php - woocommerce 条件字段
问题描述
当用户在 woocommerce 结帐中选择一个字段时,我无法弄清楚如何激活该功能,这是我的代码,我希望它仅在用户在结帐选择字段中选择 1 时才处于活动状态
add_action( 'woocommerce_cart_calculate_fees','conditional_add_fee' );
function conditional_add_fee() {
global $woocommerce;
if ( is_admin() && ! defined( 'DOING_AJAX' ) )
return;
$subtotal = $woocommerce->cart->subtotal;
$fee_percentage = 0.22; // 22 percent
$fee = number_format( round( $subtotal * $fee_percentage, 2 ), 2 ); // rounded to two decimal places to match currency formatting
$woocommerce->cart->add_fee( 'IVA', $fee, true, 'standard' );
}
谢谢
解决方案
推荐阅读
- vue.js - Vue + Vuex:存储在组件中的变量即使在离开和回来后也会保存更改
- css - 如何设置以下元素的样式?
- c - 如何决定 printf("%d %d %d %d", a++, ++a, a--, --a); 的输出 当 a = 10 时?
- asp.net - CORS 策略阻止了从源对“url”处的 XMLHttpRequest 的访问:请求的资源上不存在“Access-Control-Allow-Origin”标头
- python - 绘制 add_trace 与 append_trace
- python - W.write,在熊猫中引用问题
- xml - 根据多个兄弟条件选择兄弟节点值
- c# - ECONNRESET for response.write 不时返回邮递员
- javascript - 如何限制网站仅在 iframe 内加载?
- javascript - 多选框中选择的值应显示在同一页面中,无需单击提交按钮