2017-11-09 2 views
0

私は3種類の支払いオプションと9種類の配送料率の3つのゾーンがあり、それぞれ3種類の料金があるWoocommerceインスタンスがあります。Woocommerce:特定の配送オプションが選択されたときに支払速度を隠す

各ゾーンのレートのうち1つは、決済ゲートウェイが1つしか表示できないようにする必要がありますが、これまでのところ、すべての配送方法で非表示にすることができます。

2つの送料率は異なる表料金であるため、私は出荷レートを隠す関数で 'table_rate:##'を使用することができると期待していました。

これまでに試したコードは次のとおりです。これは、選択された出荷レートがID 54のテーブルレートである場合にのみ、winbnk配送オプションを削除することを意味しますが、選択した配送方法に関係なくゲートウェイを削除します。

私は教習所のエラーを起こしたり、配送方法の機能について何か誤解しました。

add_filter('woocommerce_available_payment_gateways','remove_payment_gateway_by_shipping_option'); 

function remove_payment_gateway_by_shipping_option($available_gateways){ 
global $woocommerce; 
    $chosen_methods = WC()->session->get('chosen_shipping_methods'); 
    $chosen_shipping = $chosen_methods[0]; 

if($chosen_shipping = 'table_rate:54'){ 
    unset($available_gateways['winbnk']); 

}  
    return $available_gateways; 
} 

下記の解決策は私のために働いてくれました。うまくいけば、それは他の人には役に立つでしょう。

add_filter('woocommerce_available_payment_gateways', 'shipping_disables_payment_gateway'); 

function shipping_disables_payment_gateway($available_gateways) { 
global $woocommerce; 
$chosen_methods = WC()->session->get('chosen_shipping_methods'); 
$chosen_shipping = $chosen_methods[0]; 
    if (isset($available_gateways['winbnk']) && 0 === strpos($chosen_shipping, 'table_rate:54')) { 
unset($available_gateways['winbnk']); 
}  
return $available_gateways; 
} 

答えて

0

これが答えです:あなたは、同じトピックについての詳細を取得リンクを介して行くことができ

function alter_shipping_methods($list){ 
 
    $chosen_titles = array(); 
 
    $available_methods = WC()->shipping->get_packages(); 
 
    $chosen_rates = (isset(WC()->session)) ? WC()->session->get('chosen_shipping_methods') : array(); 
 
    
 
    foreach ($available_methods as $method) 
 
      foreach ($chosen_rates as $chosen) { 
 
       if(isset($method['rates'][$chosen])) $chosen_titles[] = $method['rates'][ $chosen ]->label; 
 
      } 
 
    
 
    if(in_array('Home Delivery', $chosen_titles)) { 
 
     $array_diff = array('WC_Gateway_Paypal'); 
 
     $list = array_diff($list, $array_diff); 
 
    } 
 
    return $list; 
 
} 
 
add_action('woocommerce_payment_gateways', 'alter_shipping_methods');

、このコードを使用することができます。うまくいけば、それは他の人を助けることでしょう

add_filter('woocommerce_available_payment_gateways', 'shipping_disables_payment_gateway'); 

function shipping_disables_payment_gateway($available_gateways) { 
global $woocommerce; 
$chosen_methods = WC()->session->get('chosen_shipping_methods'); 
$chosen_shipping = $chosen_methods[0]; 
    if (isset($available_gateways['winbnk']) && 0 === strpos($chosen_shipping, 'table_rate:54')) { 
unset($available_gateways['winbnk']); 
} 
return $available_gateways; 
} 
関連する問題