簡體   English   中英

有條件地從 WooCommerce 我的帳戶訂單中刪除取消按鈕

[英]Remove cancel button from WooCommerce My account Orders conditionally

當“付款方式標題”為“Npay”時,我想確保取消按鈕在 my-account> my-order 中不可見。

“Npay”是一個外部支付網關,不適用於商業。 因此,付款取消只能在外部完成。

add_filter('woocommerce_my_account_my_orders_actions', 'remove_my_cancel_button', 10, 2);
function remove_my_cancel_button($actions, $order){
    if ( $payment_method->has_title( 'Npay' ) ) {
        unset($actions['cancel']);
        return $actions;
    }
}

要從我的帳戶訂單中刪除取消按鈕,我們使用以下內容:

add_filter('woocommerce_my_account_my_orders_actions', 'remove_myaccount_orders_cancel_button', 10, 2);
function remove_myaccount_orders_cancel_button( $actions, $order ){
    unset($actions['cancel']);

    return $actions;
}

但是要根據付款標題從我的帳戶訂單中刪除取消按鈕,您將使用WC_Order方法get_payment_method_title()如:

add_filter('woocommerce_my_account_my_orders_actions', 'remove_myaccount_orders_cancel_button', 10, 2);
function remove_myaccount_orders_cancel_button( $actions, $order ){
    if ( $order->get_payment_method_title() === 'Npay' ) {
        unset($actions['cancel']);
    }
    return $actions;
}

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

主變量參數$actions需要在IF語句外的最后返回

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM