彰化一整天的論壇

 找回密碼
 立即註冊
查看: 697|回復: 0

woocommerce移除付款方式

[複製鏈接]
發表於 2015-11-5 21:23:54 | 顯示全部樓層 |閱讀模式
How to Disable a Payment Method in Checkout for Certain Products
  1. /*
  2. * Disable PayPal payment method in the checkout if certain
  3. * products are present in the cart.
  4. *
  5. * Add this to your theme's functions.php file
  6. */

  7. add_filter( 'woocommerce_available_payment_gateways', 'filter_gateways', 1);
  8. function filter_gateways( $gateways ){
  9.   global $woocommerce;
  10.   foreach ($woocommerce->cart->cart_contents as $key => $values ) {
  11.   
  12.     // store product IDs in array PayPal method is disabled at checkout
  13.     $nonPPproducts = array(1111,2222,3333);                // LIST YOUR PRODUCTS HERE

  14.     if ( in_array( $values['product_id'], $nonPPproducts ) ) {       
  15.       unset($gateways['paypal']);
  16.       // You can unset other gateways using the gateway ID e.g. "cod", "bacs", "stripe"
  17.       break;
  18.     }
  19.   }
  20.   
  21.   return $gateways;
  22.   
  23. }
複製代碼
參考資料: https://support.woothemes.com/hc ... or-Certain-Products
回復

使用道具 舉報

您需要登錄後才可以回帖 登錄 | 立即註冊

本版積分規則

 ㄚ母滴雞湯
 員林香純滴雞精

Archiver|手機版|小黑屋|彰化一整天的論壇(Excel,Office)  

GMT+8, 2020-2-25 15:12 , Processed in 0.121142 second(s), 19 queries .

Powered by Discuz! X3.2

© 2001-2013 Comsenz Inc.

快速回復 返回頂部 返回列表