从 WooCommerce 我的帐户订单中有条件地删除取消按钮
Remove cancel button from WooCommerce My account Orders conditionally
当 'Payment Method Title' 为 'Npay' 时,我想确保取消按钮在我的帐户 > 我的订单中不可见。
'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;
}
代码进入活动 child 主题(或活动主题)的 functions.php 文件。已测试并有效。
The main variable argument $actions
need to be returned at the end outside the IF
statement
当 'Payment Method Title' 为 'Npay' 时,我想确保取消按钮在我的帐户 > 我的订单中不可见。
'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;
}
代码进入活动 child 主题(或活动主题)的 functions.php 文件。已测试并有效。
The main variable argument
$actions
need to be returned at the end outside theIF
statement