• Resolved matppp

    (@matppp)


    Hi, how to disable method payment for specific shipping method?

    /wp-admin/admin.php?page=wc-settings&tab=shipping&instance_id=6&action=edit&method_id=2

    
    add_filter( 'woocommerce_available_payment_gateways', 'bbloomer_gateway_disable_shipping_326' );
      
    function bbloomer_gateway_disable_shipping_326( $available_gateways ) {
         
       if ( ! is_admin() ) {
            
          $chosen_methods = WC()->session->get( 'chosen_shipping_methods' );
            
          $chosen_shipping = $chosen_methods[0];
            
          if ( isset( $available_gateways['cod'] ) && 0 === strpos( $chosen_shipping, 'local_pickup' ) ) {
             unset( $available_gateways['cod'] );
          }
            
       }
         
       return $available_gateways;
         
    }
    
Viewing 1 replies (of 1 total)
  • Thread Starter matppp

    (@matppp)

    Answer:

    
    add_filter( 'woocommerce_available_payment_gateways', 'remove_shipping_methods' );
      
    function remove_shipping_methods( $available_gateways ) {
       if ( ! is_admin() ) {
          $chosen_methods = WC()->session->get( 'chosen_shipping_methods' );
          $chosen_shipping = $chosen_methods[0];
          if ( isset( $available_gateways['cod'] ) && 0 === strpos( $chosen_shipping, 'flexible_shipping_6_1' ) ) {
             unset( $available_gateways['cod'] );
          } else if ( isset( $available_gateways['cod'] ) && 0 === strpos( $chosen_shipping, 'flexible_shipping_6_3' ) ) {
    		unset( $available_gateways['cod'] );
    	 } else if ( isset( $available_gateways['bacs'] ) && 0 === strpos( $chosen_shipping, 'flexible_shipping_6_2' ) ) {
    		unset( $available_gateways['bacs'] );
    	 } 
       }
       return $available_gateways;
    }
    
    • This reply was modified 5 years, 3 months ago by matppp.
Viewing 1 replies (of 1 total)

The topic ‘Disable Payment Gateway For Specific Shipping Method’ is closed to new replies.