Php 启用";“重新订购”;我的帐户查看订单页面中的自定义状态按钮
我在我的Woocommerce网站上需要一个报价请求系统,但找不到任何与Composite Products插件兼容的系统。因此,我将让客户使用“无配送/报价”配送选项和“报价请求支付网关”正常结账。这样,我可以在后端查看报价,批准报价,然后客户可以从我的帐户部分订购(技术上重新订购)他们的报价 我获得了已完成订单和报价的按钮,并通过以下方式显示:Php 启用";“重新订购”;我的帐户查看订单页面中的自定义状态按钮,php,wordpress,woocommerce,hook-woocommerce,orders,Php,Wordpress,Woocommerce,Hook Woocommerce,Orders,我在我的Woocommerce网站上需要一个报价请求系统,但找不到任何与Composite Products插件兼容的系统。因此,我将让客户使用“无配送/报价”配送选项和“报价请求支付网关”正常结账。这样,我可以在后端查看报价,批准报价,然后客户可以从我的帐户部分订购(技术上重新订购)他们的报价 我获得了已完成订单和报价的按钮,并通过以下方式显示: /** * Add order again button in my orders completed actions. * * @param
/**
* Add order again button in my orders completed actions.
*
* @param array $actions
* @param WC_Order $order
* @return array
*/
function cs_add_order_again_to_my_orders_actions( $actions, $order ) {
if ( $order->has_status( 'completed' ) ) {
$actions['order-again'] = array(
'url' => wp_nonce_url( add_query_arg( 'order_again', $order->id ) , 'woocommerce-order_again' ),
'name' => __( 'Order Again', 'woocommerce' )
);
}
return $actions;
}
add_filter( 'woocommerce_my_account_my_orders_actions', 'cs_add_order_again_to_my_orders_actions', 50, 2 );
/**
* Add Place order button in my orders quote-approved actions.
*
* @param array $actions
* @param WC_Order $order
* @return array
*/
function cs_add_place_order_to_my_orders_actions( $actions, $order ) {
if ( $order->has_status( 'quote-approved' ) ) {
$actions['place-order'] = array(
'url' => wp_nonce_url( add_query_arg( 'order_again', $order->id ) , 'woocommerce-place_order' ),
'name' => __( 'place order', 'woocommerce' )
);
}
return $actions;
}
add_filter( 'woocommerce_my_account_my_orders_actions', 'cs_add_place_order_to_my_orders_actions', 50, 2 );
//Make order again work for Place order , see below
add_filter('woocommerce_valid_order_statuses_for_order_again', function( $statuses ){
$statuses = wc_get_order_statuses('completed', 'quote-approved');
return $statuses;
}, 10, 2);
但我的第二个按钮不起作用,我相信是因为:
if ( ! function_exists( 'woocommerce_order_again_button' ) ) {
/**
* Display an 'order again' button on the view order page.
*
* @param object $order Order.
*/
function woocommerce_order_again_button( $order ) {
if ( ! $order || ! $order->has_status( apply_filters( 'woocommerce_valid_order_statuses_for_order_again', array( 'completed' ) ) ) || ! is_user_logged_in() ) {
return;
}
wc_get_template( 'order/order-again.php', array(
'order' => $order,
) );
}
}
在woocommerce/includes/wc-template-functions.php中
所以我想我只需要在
woocommerce_valid_order_statuses_for_order_again
排列
我试着用这个:
/**
* Add order again button in my orders completed actions.
*
* @param array $actions
* @param WC_Order $order
* @return array
*/
function cs_add_order_again_to_my_orders_actions( $actions, $order ) {
if ( $order->has_status( 'completed' ) ) {
$actions['order-again'] = array(
'url' => wp_nonce_url( add_query_arg( 'order_again', $order->id ) , 'woocommerce-order_again' ),
'name' => __( 'Order Again', 'woocommerce' )
);
}
return $actions;
}
add_filter( 'woocommerce_my_account_my_orders_actions', 'cs_add_order_again_to_my_orders_actions', 50, 2 );
/**
* Add Place order button in my orders quote-approved actions.
*
* @param array $actions
* @param WC_Order $order
* @return array
*/
function cs_add_place_order_to_my_orders_actions( $actions, $order ) {
if ( $order->has_status( 'quote-approved' ) ) {
$actions['place-order'] = array(
'url' => wp_nonce_url( add_query_arg( 'order_again', $order->id ) , 'woocommerce-place_order' ),
'name' => __( 'place order', 'woocommerce' )
);
}
return $actions;
}
add_filter( 'woocommerce_my_account_my_orders_actions', 'cs_add_place_order_to_my_orders_actions', 50, 2 );
//Make order again work for Place order , see below
add_filter('woocommerce_valid_order_statuses_for_order_again', function( $statuses ){
$statuses = wc_get_order_statuses('completed', 'quote-approved');
return $statuses;
}, 10, 2);
我在这里发现:
但是我无法让它工作。有人知道我做错了什么吗?任何帮助都将不胜感激。谢谢!问题来自,它只是给出了所有可用订单状态的索引数组
相反,您只需通过以下方式添加自定义订单状态slug:
add_filter( 'woocommerce_valid_order_statuses_for_order_again', 'add_custom_status_for_order_again', 20, 1 );
function add_custom_status_for_order_again( $statuses ){
$statuses[] = 'quote-approved';
return $statuses;
}
代码放在活动子主题(或活动主题)的function.php文件中。经过测试,效果良好