WooCommerce:如何在送货网关上禁用/启用特定货币的现金?

时间:2019-11-22 07:40:18

标签: wordpress woocommerce currency code-snippets

我找到了有关禁用基于国家/地区的付款方式的代码,是否有任何方法可以禁用基于“货币”的付款方式?

    /**
    * @snippet       WooCommerce Disable Payment Gateway for a Specific Country
    * @how-to        Watch tutorial @ https://businessbloomer.com/?p=19055
    * @sourcecode    https://businessbloomer.com/?p=164
    * @author        Rodolfo Melogli
    * @compatible    WooCommerce 3.5.7
    * @donate $9     https://businessbloomer.com/bloomer-armada/
    */

    add_filter( 'woocommerce_available_payment_gateways', 'bbloomer_payment_gateway_disable_country' );

    function bbloomer_payment_gateway_disable_country( $available_gateways ) {
      if ( is_admin() ) return $available_gateways;
       if ( isset( $available_gateways['authorize'] ) && WC()->customer->get_billing_country() <> 'US' ) { 
        unset( $available_gateways['authorize'] );
      } else {
          if ( isset( $available_gateways['paypal'] ) && WC()->customer->get_billing_country() == 'US' ) {
             unset( $available_gateways['paypal'] );
     }
    }
    return $available_gateways;
 }

我只希望“货到付款”选项显示所选货币是否为PKR。我正在使用用于WooCommerce的Currency Switcher插件来切换货币。

1 个答案:

答案 0 :(得分:0)

请将以下代码粘贴到当前活动主题 functions.php 文件中。

function disable_cod_for_pkr_filter_gateways($gateway_list)
{
  //return if admin
  if ( is_admin() ) 
    return $available_gateways;

  //check currency
  $currency = get_woocommerce_currency(); 

  if ($currency == 'PKR')
  {
     unset($gateway_list['cod']);
  }

  return $gateway_list;
}
add_filter('woocommerce_available_payment_gateways', 'disable_cod_for_pkr_filter_gateways', 1);

希望它能对您有所帮助。