第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問題,去搜搜看,總會(huì)有你想問的

允許客戶在 WooCommerce 我的帳戶中更改訂單狀態(tài)

允許客戶在 WooCommerce 我的帳戶中更改訂單狀態(tài)

PHP
溫溫醬 2021-06-11 13:12:50
希望創(chuàng)建一個(gè)如下所示的自定義訂單流程:客戶將商品添加到購物車在結(jié)賬過程中客戶上傳設(shè)計(jì)訂單結(jié)賬時(shí)付款已驗(yàn)證,但未捕獲公司完成設(shè)計(jì)后,上傳證明供客戶審核客戶在他們的儀表板上查看證明,然后單擊一個(gè)按鈕來處理訂單并獲取付款除了如何允許客戶在儀表板中更改訂單狀態(tài)外,我已經(jīng)想出了實(shí)現(xiàn)這一目標(biāo)所需的一切。我不需要他們來編輯訂單,只需批準(zhǔn)它用于付款捕獲。我認(rèn)為應(yīng)該有一種簡單的方法來使用自定義 PHP 代碼以及 Woocommerce Status Control 等插件來執(zhí)行此操作,但我似乎無法在任何地方找到解決方案。
查看完整描述

2 回答

?
慕俠2389804

TA貢獻(xiàn)1719條經(jīng)驗(yàn) 獲得超6個(gè)贊

新改進(jìn)的答案:允許客戶在 WooCommerce 中更改訂單狀態(tài)

您可以使用以下代碼:

  • 將“我的帳戶”>“訂單”中的“查看”按鈕替換為“批準(zhǔn)”

  • 在我的帳戶 > 訂單視圖(單個(gè)訂單)上顯示一個(gè)自定義按鈕以批準(zhǔn)訂單

  • 客戶批準(zhǔn)訂單后顯示自定義成功消息

這只會(huì)發(fā)生在具有特定狀態(tài)的客戶訂單上。所以你必須定義:

  • 需要客戶批準(zhǔn)的訂單狀態(tài)。

  • 反映客戶批準(zhǔn)訂單的訂單狀態(tài)(在 3 個(gè)功能上)

  • 訂單審批按鈕文本

  • 客戶批準(zhǔn)訂單后將顯示的文本

編碼:

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

    }

}

代碼位于活動(dòng)子主題(或活動(dòng)主題)的 functions.php 文件中。測試和工作。


在我的賬戶 > 訂單(列表):

http://img1.sycdn.imooc.com//60c5b26f00014dea07990246.jpg

在我的賬戶 > 訂單視圖(當(dāng)需要批準(zhǔn)訂單時(shí))

http://img1.sycdn.imooc.com//60c5b27d0001a24e07710230.jpg

在我的賬戶 > 訂單視圖(當(dāng)客戶批準(zhǔn)訂單時(shí))

http://img1.sycdn.imooc.com//60c5b2890001e39608150273.jpg

對(duì)于訂單狀態(tài),您可以使用代碼或插件創(chuàng)建自定義訂單狀態(tài)。



查看完整回答
反對(duì) 回復(fù) 2021-06-13
?
子衿沉夜

TA貢獻(xiàn)1828條經(jīng)驗(yàn) 獲得超3個(gè)贊

我知道我可能會(huì)遲到。但在這里我回答這個(gè)問題,以防有人仍然需要它。


下面的代碼將在我的帳戶訂單頁面操作列表中添加一個(gè)標(biāo)記為已完成按鈕。請(qǐng)注意,它會(huì)檢查訂單狀態(tài)是否由管理員設(shè)置為已交付,然后向客戶顯示該按鈕。


我也為此開發(fā)了一個(gè)插件,它可以在 WordPress 存儲(chǔ)庫中使用。有需要的可以去看看??蛻魧?duì) WooCommerce 的訂單批準(zhǔn)。


/*================================

    Add Delivered Order Status

==================================*/


add_action( 'init', 'msoa_register_delivered_order_status' );

function msoa_register_delivered_order_status() {

    register_post_status( 'wc-delivered', array(

        'label'                     => 'Session Completed',

        'public'                    => true,

        'show_in_admin_status_list' => true,

        'show_in_admin_all_list'    => true,

        'exclude_from_search'       => false,

        'label_count'               => _n_noop( 'Delivered <span class="count">(%s)</span>', 'Delivered <span class="count">(%s)</span>' )

    ) );

}


add_filter( 'wc_order_statuses', 'msoa_add_delivered_status_to_order_statuses' );

function msoa_add_delivered_status_to_order_statuses( $order_statuses ) {


    $new_order_statuses = array();


    foreach ( $order_statuses as $key => $status ) {


        $new_order_statuses[ $key ] = $status;


        if ( 'wc-processing' === $key ) {

            $new_order_statuses['wc-delivered'] = __( 'Delivered', 'order-approval' );

        }

    }


    return $new_order_statuses;

}


add_filter( 'woocommerce_my_account_my_orders_actions', 'msoa_mark_as_received', 10, 2 );

function msoa_mark_as_received( $actions, $order ) {

    $order_id = $order->id;


    if ( ! is_object( $order ) ) {

        $order_id = absint( $order );

        $order    = wc_get_order( $order_id );

    }

    

    // check if order status delivered and form not submitted


    if ( ( $order->has_status( 'delivered' ) ) && ( !isset( $_POST['mark_as_received'] ) ) ) {

        $check_received = ( $order->has_status( 'delivered' ) ) ? "true" : "false";

        ?>

        <div class="ms-mark-as-received">

            <form method="post">

                <input type="hidden" name="mark_as_received" value="<?php echo esc_attr( $check_received ); ?>">

                <input type="hidden" name="order_id" value="<?php echo esc_attr($order_id);?>">

                <?php wp_nonce_field( 'so_38792085_nonce_action', '_so_38792085_nonce_field' ); ?> 

                <input class="int-button-small" type="submit" value="<?php echo esc_attr_e( 'Mark as Received', 'order-approval' ); ?>" data-toggle="tooltip" title="<?php echo esc_attr_e( 'Click to mark the order as complete if you have received the product', 'order-approval' ); ?>">

            </form>

        </div>

        <?php

    }


    /*

    //refresh page if form submitted


    * fix status not updating

    */

    if( isset( $_POST['mark_as_received'] ) ) { 

        echo "<meta http-equiv='refresh' content='0'>";

    }


    // not a "mark as received" form submission

    if ( ! isset( $_POST['mark_as_received'] ) ){

        return $actions;

    }


    // basic security check

    if ( ! isset( $_POST['_so_38792085_nonce_field'] ) || ! wp_verify_nonce( $_POST['_so_38792085_nonce_field'], 'so_38792085_nonce_action' ) ) {   

        return $actions;

    } 


    // make sure order id is submitted

    if ( ! isset( $_POST['order_id'] ) ){

        $order_id = intval( $_POST['order_id'] );

        $order = wc_get_order( $order_id );

        $order->update_status( "completed" );

        return $actions;

    }  

    if ( isset( $_POST['mark_as_received'] ) == true ) {

        $order_id = intval( $_POST['order_id'] );

        $order = wc_get_order( $order_id );

        $order->update_status( "completed" );

    }


    $actions = array(

        'pay'    => array(

            'url'  => $order->get_checkout_payment_url(),

            'name' => __( 'Pay', 'woocommerce' ),

        ),

        'view'   => array(

            'url'  => $order->get_view_order_url(),

            'name' => __( 'View', 'woocommerce' ),

        ),

        'cancel' => array(

            'url'  => $order->get_cancel_order_url( wc_get_page_permalink( 'myaccount' ) ),

            'name' => __( 'Cancel', 'woocommerce' ),

        ),

    );


    if ( ! $order->needs_payment() ) {

        unset( $actions['pay'] );

    }


    if ( ! in_array( $order->get_status(), apply_filters( 'woocommerce_valid_order_statuses_for_cancel', array( 'pending', 'failed' ), $order ), true ) ) {

        unset( $actions['cancel'] );

    }


    return $actions;


}


查看完整回答
反對(duì) 回復(fù) 2021-06-13
  • 2 回答
  • 0 關(guān)注
  • 294 瀏覽

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)