在woocommerce中隐藏超过一定金额的订单的货到付款 [英] Hide cash on delievery for orders over certain amount of money in woocommerce
问题描述
我只想在价格低于 100 美元时使用货到付款选项,并在购物车高于 100 美元时自动隐藏它.问题是,我现在有 3 种不同的付款方式.贝宝,支票和货到付款.当一个人买东西并选择货到付款方式时,我在那里写了一个描述说如果您的订单低于100美元,您可以选择货到付款".但是有些人忽略了它,即使他们的购买超过100美元仍然选择COD.所以,当购买超过 100 美元时,我想自动隐藏 COD.因此,当购买金额超过 100 美元时,只有两个选项,Paypal 和 Cheque.希望我能澄清一点.
I want to have the cash on delivery option only for price below 100$ and hide it automatically when cart is above 100$. The problem is that, I have 3 different payment methods right now. Paypal, cheque and COD. When a person buy something, and choose cash on delievry method, I've written a description there saying "you can choose COD if your order is below 100$". But some people neglect it and still choose COD even their purchase is above 100$. So, I want to hide COD automatically, when a purchase is above 100$. Hence, when a purchase is above 100$, there would be just two options, Paypal and Cheque. Hope I could clarify it a bit more.
谢谢
推荐答案
您可以使用 woocommerce_available_payment_gateways
钩子来编辑 woocommerce 网关.
You can use the woocommerce_available_payment_gateways
hook to edit woocommerce gateways.
add_filter( 'woocommerce_available_payment_gateways' , 'change_payment_gateway', 20, 1);
/**
* remove cod gateway if cart total > 100
* @param $gateways
* @return mixed
*/
function change_payment_gateway( $gateways ){
// Compare cart subtotal (without shipment fees)
if( WC()->cart->subtotal > 100 ){
// then unset the 'cod' key (cod is the unique id of COD Gateway)
unset( $gateways['cod'] );
}
return $gateways;
}
这篇关于在woocommerce中隐藏超过一定金额的订单的货到付款的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!