Looking to create a custom order process that looks like this:

  • Customer adds item to cart
  • During Checkout Process customer uploads design to order
  • On Checkout payment is verified, but not captured
  • After design is finalized by the company, they upload the proof for customer review
  • the customer reviews proof on their dashboard, and clicks a button that processes the order and captures payment
  • I have figured out everything i need to make this happen except for how to allow the customer to change the status of their order in the dashboard. I do not need them to edit the order, just approve it for payment capture.

    I think there should be an easy way to do this with custom PHP code in conjunction with a plugin like Woocommerce Status Control, but I can't seem to find a solution anywhere.

    1 Answers

    0
    LoicTheAztec On

    You can use the following code that will:

    • Replace the button text "view" by "approve" on My account > Orders
    • Display a custom button to approve the order on My account > Order view (single order)
    • Display a custom success message once customer has approved an order

    This will only happen on customer orders with a specific status. So you will have to define:

    • The order status that require an approval from customer.
    • The order status that reflect an approved order by the customer (on the 3 functions)
    • The button text for order approval
    • The text that will be displayed once customer has approved the order

    The code:

    // My account > Orders (list): Rename "view" action button text when order needs to be approved
    add_filter( 'woocommerce_my_account_my_orders_actions', 'change_my_account_my_orders_view_text_button', 10, 2 );
    function change_my_account_my_orders_view_text_button( $actions, $order ) {
        $required_order_status = 'processing'; // Order status that requires to be approved
    
        if( $order->has_status($required_order_status) ) {
            $actions['view']['name'] = __("Approve", "woocommerce"); // Change button text
        }
        return $actions;
    }
    
    // My account > View Order: Add an approval button on the order
    add_action( 'woocommerce_order_details_after_order_table', 'approve_order_button_process' );
    function approve_order_button_process( $order ){
        // Avoiding displaying buttons on email notification
        if( ! ( is_wc_endpoint_url( 'view-order' ) || is_wc_endpoint_url( 'order-received' ) ) ) return;
    
        $approved_button_text  = __("Approve this order", "woocommerce");
        $required_order_status = 'processing'; // Order status that requires to be approved
        $approved_order_status = 'completed'; // Approved order status
    
        // On submit change order status
        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
        }
    
        // Display a form with a button for order approval
        if( $order->has_status($required_order_status) ) {
            echo '<form class="cart" method="post" enctype="multipart/form-data" style="margin-top:12px;">
            <input type="submit" class="button" name="approve_order" value="Approve this order" />
            </form>';
        }
    }
    
    // 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
        }
    }
    

    Code goes in functions.php file of your active child theme (or active theme). Tested and works.


    On My account > Orders (list):

    enter image description here

    On My account > Order view (when an order required to be approved):

    enter image description here

    On My account > Order view (when customer has approved the order):

    enter image description here


    For order statuses, you can create custom order statuses with code or with plugins.