• tom

    (@klickchoice)


    Hi, Really thank you fro this great plugin . And it is working very good . Let me know how to hide the new payment gateway based on location of customer .

    Currently i add a custom payment gateway . But i need to hide new one when customer select specified billing_state. For this i write the following jQuery

    jQuery("[name='billing_state']").change(function(){
    
    		var state=jQuery('[name="billing_state"]').val();
    
    		if(state=="123" ){
    		$("#payment_method_my_new_gateway").hide();
    		}
    
    		});

    It’s working . But after this an ajax call from the woocommerece for updating the order is happen . checkout?wc-ajax=update_order_review And it will show my new paymentgateway . Please tell to how to modify the result .

    https://www.ads-software.com/plugins/woocommerce-jetpack/

Viewing 3 replies - 1 through 3 (of 3 total)
  • Thread Starter tom

    (@klickchoice)

    Please reply .

    Hi,

    If I got it right, what you need is to use woocommerce_available_payment_gateways filter. So it’s PHP only, no jQuery.

    Basically your code should look something like this:

    add_filter( 'woocommerce_available_payment_gateways', 'hide_custom_payment_gateway_by_state', PHP_INT_MAX, 1 );
    function hide_custom_payment_gateway_by_state( $_available_gateways ) {
    	$custom_gateway_key = 'jetpack_custom_gateway';
    	if ( isset( $_available_gateways[ $custom_gateway_key ] ) ) {
    		$customer_state = WC()->customer->get_state();
    		$exclude_state = 'CA';
    		if ( $exclude_state == $customer_state ) {
    			unset( $_available_gateways[ $custom_gateway_key ] );
    		}
    	}
    	return $_available_gateways;
    }

    We have similar module in our plugin called “Gateways by Country”, please check “includes\class-wcj-payment-gateways-by-country.php” file…

    Hope it helps. I didn’t test the code above, so please let me know if it doesn’t work.

    P.S. We are probably going to add this functionality as a module in our plugin shortly. Will let you know when we do…

    Best regards,
    Tom

    Hi Tom,

    does new version of Booster for WooCommerce solved your problem?
    Could we mark this problems as solved?

    BR,
    Val

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Change or hide the new custom paymentgateway’ is closed to new replies.