2017-09-20 18 views
1

WoCommerceでは、特定の支払い方法を無効にして、WooCommerceの定期購読商品(またはその逆)の特定の支払い方法を表示したいと思います。WooCommerceの商品タイプに基づくお支払い方法を非表示

This私が見つけた最も近いものですが、私が期待していることはしません。

はい、これを行うプラグインはありますが、他のプラグインを使用せずにスタイルシートを作成する必要はありません。

お願いします。ここで

答えて

1

は、私は、カートの項目に基づいて支払いゲートウェイを無効にすることができwoocommerce_available_payment_gatewaysフィルターフック、(製品タイプ)で、カスタムフック機能を持つ例です。

add_filter('woocommerce_available_payment_gateways', 'conditional_payment_gateways', 10, 1); 
function conditional_payment_gateways($available_gateways) { 

    foreach (WC()->cart->get_cart() as $cart_item_key => $cart_item) { 
     $prod_variable = $prod_simple = $prod_subscription = false; 
     // Get the WC_Product object 
     $product = wc_get_product($cart_item['product_id']); 
     // Get the product types in cart (example) 
     if($product->is_type('simple')) $prod_simple = true; 
     if($product->is_type('variable')) $prod_variable = true; 
     if($product->is_type('subscription')) $prod_subscription = true; 
    } 
    // Remove Cash on delivery (cod) payment gateway for simple products 
    if($prod_simple) 
     unset($available_gateways['cod']); // unset 'cod' 
    // Remove Paypal (paypal) payment gateway for variable products 
    if($prod_variable) 
     unset($available_gateways['paypal']); // unset 'paypal' 
    // Remove Bank wire (Bacs) payment gateway for subscription products 
    if($prod_subscription) 
     unset($available_gateways['bacs']); // unset 'bacs' 

    return $available_gateways; 
} 

コードはfunction.phpに行きますあなたのアクティブな子供のテーマ(またはテーマ)のファイル、またはすべてのプラグインファイル。

すべてのコードは、Woocommerce 3+でテストされ、動作します。

これは物事が働くことができるかをお見せするだけの例です。あなたは、ロイックそれ

+0

乾杯を適応する必要があります!私たちはこれを渦巻きにして、何かを壊してしまったら教えてあげます - ありがとう! –

+1

ロイック、あなたは絶対に男です。 –

関連する問題