允许客户更改WooCommerce我的帐户中的订单状态 [英] Allow customer to change the order status in WooCommerce My account

查看:95
本文介绍了允许客户更改WooCommerce我的帐户中的订单状态的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

试图创建一个如下所示的自定义订单流程:

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

  • 客户将商品添加到购物车
  • 在结帐流程中,客户将设计上传到订单中
  • 在结帐时付款已通过验证,但未捕获
  • 公司完成设计后,将其上传证明供客户审核
  • 客户在其仪表板上查看证据,然后单击用于处理订单并捕获付款的按钮
  • 我已经弄清楚了实现此目标所需的一切,除了如何让客户更改仪表盘中订单的状态外.我不需要他们编辑订单,只需批准付款捕获即可.

    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.

    我认为应该有一种简单的方法来使用自定义PHP代码以及Woocommerce Status Control之类的插件,但是我似乎找不到任何解决方案.

    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.

    推荐答案

    改进的新答案:允许客户更改订单WooCommerce中的状态

    您可以使用以下代码来实现

    You can use the following code that will:

    • 将按钮文本视图"替换为通过批准"在我的帐户上>订单
    • 显示一个自定义按钮以批准我的帐户"上的订单>订单视图(单个订单)
    • 客户批准订单后显示自定义成功消息

    这只会在具有特定状态的客户订单上发生.因此,您必须定义:

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

    • 需要客户批准的订单状态.
    • 反映客户批准的订单的订单状态(在3个功能上)
    • 用于批准订单的按钮文字
    • 客户批准订单后将显示的文字
    • 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

    代码:

    // 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
        }
    }
    

    代码进入您的活动子主题(或活动主题)的functions.php文件中.经过测试,可以正常工作.

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

    在我的帐户"上>订单(列表):

    On My account > Orders (list):

    在我的帐户"上>订单视图(需要批准订单时):

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

    在我的帐户"上>订单视图(客户批准订单后):

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

    对于订单状态,您可以使用代码或通过插件创建自定义订单状态

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

    这篇关于允许客户更改WooCommerce我的帐户中的订单状态的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

    查看全文
    相关文章
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆