Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/wordpress/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 增加COD费用,除非在WooCommerce结帐时选择本地取货_Php_Wordpress_Woocommerce_Checkout_Fee - Fatal编程技术网

Php 增加COD费用,除非在WooCommerce结帐时选择本地取货

Php 增加COD费用,除非在WooCommerce结帐时选择本地取货,php,wordpress,woocommerce,checkout,fee,Php,Wordpress,Woocommerce,Checkout,Fee,我目前在WooCommerce中有活动代码,它运行良好。该代码允许我在客户选择“COD”pyament方法+1.7欧元时应用额外成本 我想了解的是: 当客户选择从我们的仓库提货时,是否可以禁用额外成本 代码如下: //添加基于购物车小计的自定义费用 添加操作('woocommerce\u cart\u calculate\u fees'、'custom\u handling\u fee',10,1); 功能自定义处理费($cart){ if(定义了('DOING'uajax')) 返回; 如果(

我目前在WooCommerce中有活动代码,它运行良好。该代码允许我在客户选择“COD”pyament方法+1.7欧元时应用额外成本

我想了解的是:

当客户选择从我们的仓库提货时,是否可以禁用额外成本

代码如下:

//添加基于购物车小计的自定义费用
添加操作('woocommerce\u cart\u calculate\u fees'、'custom\u handling\u fee',10,1);
功能自定义处理费($cart){
if(定义了('DOING'uajax'))
返回;
如果('cod'==WC()->session->get('selected\u payment\u method')){
$fee=1.7;
$cart->add_fee('Extra per pagamento alla consegna',$fee,true);
}
}
//jQuery-更新methode付款更改的签出
添加操作('wp_footer','custom_checkout_jqscript');
函数自定义检查jqscript(){
如果(is_checkout()&&!is_wc_endpoint_url()):
?>
jQuery(函数($){
$('form.checkout')。在('change','input[name=“payment\u method”]”上,函数(){
$(document.body).trigger('update_checkout');
});
});

虽然
cod
是一种付款方式,
local\u-pick
是一种运输方式

  • WC()->session->get('selected_payment_method');

  • WC()->session->get('selected_shipping_methods');

所以要回答你们的问题,你们必须使用2的组合

所以你得到:

功能操作\u商业\u购物车\u计算\u费用($cart){
if(定义了('DOING'uajax'))
返回;
//选择的付款方式
$selected_payment_method=WC()->session->get('selected_payment_method');
//选择的运输方式
$selected_shipping_methods=WC()->session->get('selected_shipping_methods');
$selected_shipping_method=substr($selected_shipping_methods[0],0,strpos($selected_shipping_methods[0],':');
//比较付款方式和运输方式
如果($selected\u payment\u method='cod'&&$selected\u shipping\u method!='local\u pickup'){
//费用
$fee=1.7;
//加费
$cart->add_fee(uuu('Extra per pagamento alla consegna','woocommerce'),$fee,true);
}
}
添加行动('woocommerce\u cart\u calculate\u fees','action\uWooCommerce\u cart\u calculate\u fees',10,1);
//jQuery-更新付款方式更改的签出
函数自定义检查jqscript(){
如果(is_checkout()&&!is_wc_endpoint_url()):
?>
jQuery(函数($){
$('form.checkout')。在('change','input[name=“payment_method”]”,函数()上{
$(document.body).trigger('update_checkout');
});
});

太棒了!谢谢!我希望这篇文章也能帮助其他人。