2013-06-09 24 views
5

Trong thiết lập thương mại điện tử này, tôi có 2 Phương thức thanh toán, PaypalTiền mặt khi giao hàng.Cách ẩn phương thức thanh toán trong Woocommerce dựa trên Mã bưu điện

Làm cách nào để có thể Tiền mặt khi giao hàng bị ẩn/vô hiệu hóa đối với một số mã bưu điện nhất định.

Đây là mã tôi tìm thấy trên Gist

// Disable gateway based on country 
function payment_gateway_disable_country($available_gateways) { 
    global $woocommerce; 
    if (isset($available_gateways['ccavenue']) && $woocommerce->customer->get_country() <> 'IN') { 
     unset( $available_gateways['ccavenue']); 
    } else if (isset($available_gateways['paypal']) && $woocommerce->customer->get_country() == 'IN') { 
     unset($available_gateways['paypal']); 
    } 
    return $available_gateways; 
} 
add_filter('woocommerce_available_payment_gateways', 'payment_gateway_disable_country'); 

Gist Link

+0

Bạn có tìm cách để làm điều đó không? Tôi muốn làm điều này cũng như tính thêm phí cho COD. – Chirag

+0

Plugin này làm những gì bạn cần: http://gremlin.io/shop/woocommerce-plugins/restrict-check-cod-payment-method-zip-pin-codes-woocommerce –

Trả lời

7

Để vô hiệu hóa/ẩn "Tiền Delivery", Đặt mã này trong function.php của chủ đề của bạn.

Để cụ thể hơn: woocommerce-hide-payment-gatway-based-on-visitors-country

// Disable gateway based on country 
function payment_gateway_disable_country($available_gateways) { 
global $woocommerce; 
if (isset($available_gateways['cod']) && $woocommerce->customer->get_country() <> 'IN') { 
    unset( $available_gateways['cod']); 
} 
return $available_gateways; 
} 
add_filter('woocommerce_available_payment_gateways', 'payment_gateway_disable_country'); 
+0

Tôi đã thêm điều này vào câu hỏi của mình. – Nikhil

+0

Giải pháp tốt. Bạn cũng có thể thêm điều kiện để tạo mã hóa cho cổng chỉ khả dụng bằng phương thức giao hàng được xác định bằng cách sử dụng gist https://gist.github.com/salgua/30ee2bc205d71f758fd9 này – salgua

1

Trong người sử dụng "trang thanh toán" có thể có hai địa chỉ - Thanh toán và vận chuyển một.

Để chỉ hoạt động chính xác với các thay đổi của Vận chuyển nếu nó được lấp đầy, tôi đã thay đổi một chút mã. Bạn phải kiểm tra mã quốc gia giao hàng nếu được đặt, nếu không chỉ là mã quốc gia của người dùng:

function payment_gateway_disable_country($available_gateways) { 
    global $woocommerce; 
    $country = !empty($woocommerce->customer->get_shipping_country()) ? $woocommerce->customer->get_shipping_country() : $woocommerce->customer->get_country(); 
    if (isset($available_gateways['cod']) && $country <> 'CZ') { 
     unset( $available_gateways['cod']); 
    } 
    return $available_gateways; 
} 
add_filter('woocommerce_available_payment_gateways', 'payment_gateway_disable_country');