php - 有条件地从 WooCommerce 我的帐户订单中删除取消按钮
问题描述
当“付款方式标题”为“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;
}
但是要根据付款标题从 My account Orders 中删除取消按钮,您将使用如下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
语句的末尾返回
推荐阅读
- linked-list - 我可以创建一个 Github 网站并在其中存储我的存储库的所有链接吗?
- excel - 在文件夹中循环excel工作簿并删除除一张以外的所有工作表
- python-3.x - python boto3上传的文件不可见
- javascript - 在 CSS 中附加 div 时如何获得不同的边距?
- reactjs - 组件正在将受控输入更改为不受控。这可能是由于值从已定义更改为未定义引起的
- install4j - 从 install4j 安装程序安装和触发 macOS 应用程序
- unity3d - 如何将 USDZ 模型导入 Unity?
- java - javafx tableView 不显示数据,getter setter 有什么问题?
- python - 当我在 python2.7 中将 pandas 转换为 pyspark 数据框时出现乱码
- flutter - Flutter:如何在启动时显示 ModalBottomSheet 而无需单击任何按钮,我想将其显示为我的 App 的第一个屏幕