[英]Hide WooCommerce payment methods for specific shipping zones and min subtotal
在 WooCommerce 中,當特定送貨區域名稱(區域 1、區域 4 和區域 7)的購物車小計高達 250 美元時,我試圖刪除“貨到付款”付款方式。
所有其他區域不得有此限制。
這是我基於此線程的不完整代碼:
add_filter( 'woocommerce_available_payment_gateways', 'change_payment_gateway', 20, 1);
function change_payment_gateway( $gateways ){
$zone = $shipping_zone->get_zone_name();
if( WC()->cart->subtotal > 250 ) && if($zone=='Zone 1','Zone 4','Zone 7'){
unset( $gateways['cod'] );
}
return $gateways;
}
任何幫助表示贊賞。
以下將刪除特定運輸區域的“貨到付款”支付網關,並且當購物車小計達到250
:
add_filter( 'woocommerce_available_payment_gateways', 'conditionally_remove_payment_methods', 20, 1);
function conditionally_remove_payment_methods( $gateways ){
// Not in backend (admin)
if( is_admin() )
return $gateways;
// HERE below your targeted zone names
$targeted_zones_names = array('Zone 1','Zone 4','Zone 7');
$chosen_methods = WC()->session->get( 'chosen_shipping_methods' ); // The chosen shipping mehod
$chosen_method = explode(':', reset($chosen_methods) );
$shipping_zone = WC_Shipping_Zones::get_zone_by( 'instance_id', $chosen_method[1] );
$current_zone_name = $shipping_zone->get_zone_name();
if( WC()->cart->subtotal > 250 && in_array( $current_zone_name, $targeted_zones_names ) ){
unset( $gateways['cod'] );
}
return $gateways;
}
代碼位於活動子主題(或活動主題)的 functions.php 文件中。 測試和工作。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.