单击按钮批准后状态顺序不会更改

时间:2020-05-28 11:42:47

标签: javascript php wordpress woocommerce

作为客户,当我单击“批准”按钮时,状态不会更改,并且完成订单的通知不会出现在“我的帐户”>“订单”>(id-order)上。 这是我用于php的代码:

//Add an approval button on the order
add_filter('woocommerce_my_account_my_orders_actions','add_approved_order_my_account_orders_actions', 50, 2 );

function add_approved_order_my_account_orders_actions( $actions, $order ) {

$required_order_status = 'processing'; // Order status that requires to be approved
$approved_order_status = 'completed'; // Approved order status

 if( $order->has_status($required_order_status) ) {
     $actions['approve_order'] = array(
        'url'  => $order->get_view_order_url(),
        'name' => __( 'Approve', 'woocommerce' )
    );                                                                       
}

 if( isset($_POST["approve_order"]) && $_POST["approve_order"] == $approved_button_text
&& $order->has_status( $required_order_status ) ) {
    $order->update_status( $approved_order_status ); // Change order status
}

return $actions ;
}

// My account > View Order: Add a custom notice when order is approved
add_action( 'woocommerce_order_details_before_order_table','approved_order_message' );
function approved_order_message( $order ){
// Avoiding displaying buttons on email notification
if( ! ( is_wc_endpoint_url( 'view-order' ) || is_wc_endpoint_url( 'order-received' ) ) ) return;

$approved_order_status = 'completed'; // Approved order status

if( $order->has_status( $approved_order_status ) ) {
    wc_print_notice(  __("This order is approved", "woocommerce"), 'success' ); // Message
}
}

示例图片:

Before Click

After Click

0 个答案:

没有答案