Multi Vendor Marketplace Plugin | WCFM Marketplace › Forums › WC Marketplace › PRIORITY!! Very Important to Admins
- This topic has 0 replies, 1 voice, and was last updated 4 years, 6 months ago by Moaweyah Aladwan.
- AuthorPosts
- June 3, 2020 at 7:45 pm #138089Moaweyah AladwanParticipant
Hello,
I have found this amazing snippet for an amazing feature that would increase customer loyalty and trust. For a service marketplace, it would be great if the customer can change the order status from processing to complete, by changing the “View” button in his order list to “Approve” when the order status is processing, when he clicks approve, he will be redirected to the order details page in order to confirm his action and approve the order as completed. I have tried this code, it changes the button in the order list from “View” to “Approve” but when the customer is redirected to the order details page, there is no “Approve” button to change order status. Now Please, anyone who knows coding (Unlike me) take a look at this, and find out where the problem is, because if this is fixed, the next step would be to remove “Completed” options from the vendor order details page so he can’t change the status from processing to completed, only the customer can.// 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_before_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 } }
- AuthorPosts
- You must be logged in to reply to this topic.