Show hide payment methods based on selected shipping method in WoocommerceHide payment methods based on selected shipping method in WooCommerceWooCommerce - Virtual Products have “No Available Payment Method”WooCommerce Shipping API functionsCustom Woocommerce Payment Gateway for Squareup.comWoocommerce - Shipping methods not shown and shipping costs not calculatedHide payment method based on product meta in WoocommerceWoocommerce: Hide payment rates when specific shipping option is selectedMake Shipping Method fields Mandatory on Woocommerce checkout pageCustom shipping method for a specific country based weight in one countryRemove duplicated shipping packages using a shipping class in WoocommerceUnset Shipping Methods based on weight in woocommerce

Is there a good program to play chess online in ubuntu?

What are the arguments for California’s nonpartisan blanket (jungle) primaries?

What exactly is a Hadouken?

Will it hurt my career to work as a graphic designer in a startup for beauty and skin care?

Accidentally deleted python and yum is not working in centos7

Could a planet have a naturally occuring moon at one of its Lagrange points?

Why did Spider-Man take a detour to Dorset?

In Adventurers League, is there any way for an 5th-level wizard to gain heavy armor proficiency?

Do aircraft cabins have suspension?

Teferi's Time Twist on creature with +1/+1 counter

Capacitor with specific self-resonant frequency?

If I stood next to a piece of metal heated to a million degrees, but in a perfect vacuum, would I feel hot?

How to change checkbox react correctly?

What to look for in climbing shoes?

Is 7000 words too long for a chapter?

Should I be able to keep my company purchased standing desk when I leave my job?

Why aren't globular clusters disk shaped

What systems of robust steganography are out there?

I do not have power to all my breakers

Advice for paying off student loans and auto loans now that I have my first 'real' job

What is the technical explanation of the note "A♭" in a F7 chord in the key of C?

Is this more than a packing puzzle?

Why don't commercial aircraft adopt a slightly more seaplane-like design to allow safer ditching in case of emergency?

Why run a service as a system user?



Show hide payment methods based on selected shipping method in Woocommerce


Hide payment methods based on selected shipping method in WooCommerceWooCommerce - Virtual Products have “No Available Payment Method”WooCommerce Shipping API functionsCustom Woocommerce Payment Gateway for Squareup.comWoocommerce - Shipping methods not shown and shipping costs not calculatedHide payment method based on product meta in WoocommerceWoocommerce: Hide payment rates when specific shipping option is selectedMake Shipping Method fields Mandatory on Woocommerce checkout pageCustom shipping method for a specific country based weight in one countryRemove duplicated shipping packages using a shipping class in WoocommerceUnset Shipping Methods based on weight in woocommerce






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








1















I would like to hide some payment method and enable another one when I select a specified “Shipping Method" in flexible Shipping plugin form wpdesk.



I have already tried that code:



add_filter( 'woocommerce_available_payment_gateways', 'gateway_disable_shipping_326' );
function gateway_disable_shipping_326( $available_gateways )
global $woocommerce;

if ( !is_admin() )
$chosen_methods = WC()->session->get( 'chosen_shipping_methods' );
$chosen_shipping = $chosen_methods[0];

if ( isset( $available_gateways['payment_method_cod'] ) && 0 === strpos( $chosen_shipping, 'flat_rate:6' ) )
unset( $available_gateways['payment_method_cod'] );


return $available_gateways;



and this one



function my_custom_available_payment_gateways( $gateways ) 
$chosen_shipping_rates = WC()->session->get( 'chosen_shipping_methods' );
if ( in_array( 'flat_rate:6', $chosen_shipping_rates ) ) :
unset( $gateways['payment_method_cod'] );
endif;
if ( in_array( 'flat_rate:8', $chosen_shipping_rates ) ) :
unset( $gateways['payment_method_przelewy24'] );
endif;
return $gateways;


add_filter( 'woocommerce_available_payment_gateways', 'my_custom_available_payment_gateways' );


The link to my website: [www.dajati.pl][1]










share|improve this question
























  • Hey Artur, can you share what didn't work about the approaches you tried?

    – Zach Bloomquist
    Mar 25 at 19:34











  • Hey Zach so payments methods didn't hide when I chose certain delivery methods.

    – Artur Schulz
    Mar 25 at 19:56

















1















I would like to hide some payment method and enable another one when I select a specified “Shipping Method" in flexible Shipping plugin form wpdesk.



I have already tried that code:



add_filter( 'woocommerce_available_payment_gateways', 'gateway_disable_shipping_326' );
function gateway_disable_shipping_326( $available_gateways )
global $woocommerce;

if ( !is_admin() )
$chosen_methods = WC()->session->get( 'chosen_shipping_methods' );
$chosen_shipping = $chosen_methods[0];

if ( isset( $available_gateways['payment_method_cod'] ) && 0 === strpos( $chosen_shipping, 'flat_rate:6' ) )
unset( $available_gateways['payment_method_cod'] );


return $available_gateways;



and this one



function my_custom_available_payment_gateways( $gateways ) 
$chosen_shipping_rates = WC()->session->get( 'chosen_shipping_methods' );
if ( in_array( 'flat_rate:6', $chosen_shipping_rates ) ) :
unset( $gateways['payment_method_cod'] );
endif;
if ( in_array( 'flat_rate:8', $chosen_shipping_rates ) ) :
unset( $gateways['payment_method_przelewy24'] );
endif;
return $gateways;


add_filter( 'woocommerce_available_payment_gateways', 'my_custom_available_payment_gateways' );


The link to my website: [www.dajati.pl][1]










share|improve this question
























  • Hey Artur, can you share what didn't work about the approaches you tried?

    – Zach Bloomquist
    Mar 25 at 19:34











  • Hey Zach so payments methods didn't hide when I chose certain delivery methods.

    – Artur Schulz
    Mar 25 at 19:56













1












1








1








I would like to hide some payment method and enable another one when I select a specified “Shipping Method" in flexible Shipping plugin form wpdesk.



I have already tried that code:



add_filter( 'woocommerce_available_payment_gateways', 'gateway_disable_shipping_326' );
function gateway_disable_shipping_326( $available_gateways )
global $woocommerce;

if ( !is_admin() )
$chosen_methods = WC()->session->get( 'chosen_shipping_methods' );
$chosen_shipping = $chosen_methods[0];

if ( isset( $available_gateways['payment_method_cod'] ) && 0 === strpos( $chosen_shipping, 'flat_rate:6' ) )
unset( $available_gateways['payment_method_cod'] );


return $available_gateways;



and this one



function my_custom_available_payment_gateways( $gateways ) 
$chosen_shipping_rates = WC()->session->get( 'chosen_shipping_methods' );
if ( in_array( 'flat_rate:6', $chosen_shipping_rates ) ) :
unset( $gateways['payment_method_cod'] );
endif;
if ( in_array( 'flat_rate:8', $chosen_shipping_rates ) ) :
unset( $gateways['payment_method_przelewy24'] );
endif;
return $gateways;


add_filter( 'woocommerce_available_payment_gateways', 'my_custom_available_payment_gateways' );


The link to my website: [www.dajati.pl][1]










share|improve this question
















I would like to hide some payment method and enable another one when I select a specified “Shipping Method" in flexible Shipping plugin form wpdesk.



I have already tried that code:



add_filter( 'woocommerce_available_payment_gateways', 'gateway_disable_shipping_326' );
function gateway_disable_shipping_326( $available_gateways )
global $woocommerce;

if ( !is_admin() )
$chosen_methods = WC()->session->get( 'chosen_shipping_methods' );
$chosen_shipping = $chosen_methods[0];

if ( isset( $available_gateways['payment_method_cod'] ) && 0 === strpos( $chosen_shipping, 'flat_rate:6' ) )
unset( $available_gateways['payment_method_cod'] );


return $available_gateways;



and this one



function my_custom_available_payment_gateways( $gateways ) 
$chosen_shipping_rates = WC()->session->get( 'chosen_shipping_methods' );
if ( in_array( 'flat_rate:6', $chosen_shipping_rates ) ) :
unset( $gateways['payment_method_cod'] );
endif;
if ( in_array( 'flat_rate:8', $chosen_shipping_rates ) ) :
unset( $gateways['payment_method_przelewy24'] );
endif;
return $gateways;


add_filter( 'woocommerce_available_payment_gateways', 'my_custom_available_payment_gateways' );


The link to my website: [www.dajati.pl][1]







php wordpress woocommerce shipping-method payment-method






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Mar 26 at 7:29







Artur Schulz

















asked Mar 25 at 19:28









Artur SchulzArtur Schulz

84 bronze badges




84 bronze badges












  • Hey Artur, can you share what didn't work about the approaches you tried?

    – Zach Bloomquist
    Mar 25 at 19:34











  • Hey Zach so payments methods didn't hide when I chose certain delivery methods.

    – Artur Schulz
    Mar 25 at 19:56

















  • Hey Artur, can you share what didn't work about the approaches you tried?

    – Zach Bloomquist
    Mar 25 at 19:34











  • Hey Zach so payments methods didn't hide when I chose certain delivery methods.

    – Artur Schulz
    Mar 25 at 19:56
















Hey Artur, can you share what didn't work about the approaches you tried?

– Zach Bloomquist
Mar 25 at 19:34





Hey Artur, can you share what didn't work about the approaches you tried?

– Zach Bloomquist
Mar 25 at 19:34













Hey Zach so payments methods didn't hide when I chose certain delivery methods.

– Artur Schulz
Mar 25 at 19:56





Hey Zach so payments methods didn't hide when I chose certain delivery methods.

– Artur Schulz
Mar 25 at 19:56












1 Answer
1






active

oldest

votes


















0














The following code example will enable / disable payment gateways based on chosen shipping method.



In this example, we have 3 shipping methods and 3 payment gateways. Each selected shipping method will enable only one different payment gateway.



add_filter( 'woocommerce_available_payment_gateways', 'payment_gateways_based_on_chosen_shipping_method' );
function payment_gateways_based_on_chosen_shipping_method( $gateways )
// Get chosen shipping methods
$chosen_shipping_methods = (array) WC()->session->get( 'chosen_shipping_methods' );

if ( in_array( 'flat_rate:12', $chosen_shipping_methods ) )

unset( $gateways['bacs'] );
unset( $gateways['cod'] );

elseif ( in_array( 'flat_rate:14', $chosen_shipping_methods ) )

unset( $gateways['bacs'] );
unset( $gateways['paypal'] );

elseif ( in_array( 'free_shipping:10', $chosen_shipping_methods ) )

unset( $gateways['cod'] );
unset( $gateways['paypal'] );


return $gateways;



Code goes in function.php file of your active child theme (or active theme). Tested and works.




To be able to get the correct shipping method ID you can use your browser inspector, this way:



enter image description here







share|improve this answer

























  • It Works. THANK YOU VERY MUCH !!!

    – Artur Schulz
    Mar 26 at 7:26










Your Answer






StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













draft saved

draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55345129%2fshow-hide-payment-methods-based-on-selected-shipping-method-in-woocommerce%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









0














The following code example will enable / disable payment gateways based on chosen shipping method.



In this example, we have 3 shipping methods and 3 payment gateways. Each selected shipping method will enable only one different payment gateway.



add_filter( 'woocommerce_available_payment_gateways', 'payment_gateways_based_on_chosen_shipping_method' );
function payment_gateways_based_on_chosen_shipping_method( $gateways )
// Get chosen shipping methods
$chosen_shipping_methods = (array) WC()->session->get( 'chosen_shipping_methods' );

if ( in_array( 'flat_rate:12', $chosen_shipping_methods ) )

unset( $gateways['bacs'] );
unset( $gateways['cod'] );

elseif ( in_array( 'flat_rate:14', $chosen_shipping_methods ) )

unset( $gateways['bacs'] );
unset( $gateways['paypal'] );

elseif ( in_array( 'free_shipping:10', $chosen_shipping_methods ) )

unset( $gateways['cod'] );
unset( $gateways['paypal'] );


return $gateways;



Code goes in function.php file of your active child theme (or active theme). Tested and works.




To be able to get the correct shipping method ID you can use your browser inspector, this way:



enter image description here







share|improve this answer

























  • It Works. THANK YOU VERY MUCH !!!

    – Artur Schulz
    Mar 26 at 7:26















0














The following code example will enable / disable payment gateways based on chosen shipping method.



In this example, we have 3 shipping methods and 3 payment gateways. Each selected shipping method will enable only one different payment gateway.



add_filter( 'woocommerce_available_payment_gateways', 'payment_gateways_based_on_chosen_shipping_method' );
function payment_gateways_based_on_chosen_shipping_method( $gateways )
// Get chosen shipping methods
$chosen_shipping_methods = (array) WC()->session->get( 'chosen_shipping_methods' );

if ( in_array( 'flat_rate:12', $chosen_shipping_methods ) )

unset( $gateways['bacs'] );
unset( $gateways['cod'] );

elseif ( in_array( 'flat_rate:14', $chosen_shipping_methods ) )

unset( $gateways['bacs'] );
unset( $gateways['paypal'] );

elseif ( in_array( 'free_shipping:10', $chosen_shipping_methods ) )

unset( $gateways['cod'] );
unset( $gateways['paypal'] );


return $gateways;



Code goes in function.php file of your active child theme (or active theme). Tested and works.




To be able to get the correct shipping method ID you can use your browser inspector, this way:



enter image description here







share|improve this answer

























  • It Works. THANK YOU VERY MUCH !!!

    – Artur Schulz
    Mar 26 at 7:26













0












0








0







The following code example will enable / disable payment gateways based on chosen shipping method.



In this example, we have 3 shipping methods and 3 payment gateways. Each selected shipping method will enable only one different payment gateway.



add_filter( 'woocommerce_available_payment_gateways', 'payment_gateways_based_on_chosen_shipping_method' );
function payment_gateways_based_on_chosen_shipping_method( $gateways )
// Get chosen shipping methods
$chosen_shipping_methods = (array) WC()->session->get( 'chosen_shipping_methods' );

if ( in_array( 'flat_rate:12', $chosen_shipping_methods ) )

unset( $gateways['bacs'] );
unset( $gateways['cod'] );

elseif ( in_array( 'flat_rate:14', $chosen_shipping_methods ) )

unset( $gateways['bacs'] );
unset( $gateways['paypal'] );

elseif ( in_array( 'free_shipping:10', $chosen_shipping_methods ) )

unset( $gateways['cod'] );
unset( $gateways['paypal'] );


return $gateways;



Code goes in function.php file of your active child theme (or active theme). Tested and works.




To be able to get the correct shipping method ID you can use your browser inspector, this way:



enter image description here







share|improve this answer















The following code example will enable / disable payment gateways based on chosen shipping method.



In this example, we have 3 shipping methods and 3 payment gateways. Each selected shipping method will enable only one different payment gateway.



add_filter( 'woocommerce_available_payment_gateways', 'payment_gateways_based_on_chosen_shipping_method' );
function payment_gateways_based_on_chosen_shipping_method( $gateways )
// Get chosen shipping methods
$chosen_shipping_methods = (array) WC()->session->get( 'chosen_shipping_methods' );

if ( in_array( 'flat_rate:12', $chosen_shipping_methods ) )

unset( $gateways['bacs'] );
unset( $gateways['cod'] );

elseif ( in_array( 'flat_rate:14', $chosen_shipping_methods ) )

unset( $gateways['bacs'] );
unset( $gateways['paypal'] );

elseif ( in_array( 'free_shipping:10', $chosen_shipping_methods ) )

unset( $gateways['cod'] );
unset( $gateways['paypal'] );


return $gateways;



Code goes in function.php file of your active child theme (or active theme). Tested and works.




To be able to get the correct shipping method ID you can use your browser inspector, this way:



enter image description here








share|improve this answer














share|improve this answer



share|improve this answer








edited Apr 2 at 16:41

























answered Mar 26 at 0:01









LoicTheAztecLoicTheAztec

106k15 gold badges87 silver badges127 bronze badges




106k15 gold badges87 silver badges127 bronze badges












  • It Works. THANK YOU VERY MUCH !!!

    – Artur Schulz
    Mar 26 at 7:26

















  • It Works. THANK YOU VERY MUCH !!!

    – Artur Schulz
    Mar 26 at 7:26
















It Works. THANK YOU VERY MUCH !!!

– Artur Schulz
Mar 26 at 7:26





It Works. THANK YOU VERY MUCH !!!

– Artur Schulz
Mar 26 at 7:26








Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.







Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.



















draft saved

draft discarded
















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55345129%2fshow-hide-payment-methods-based-on-selected-shipping-method-in-woocommerce%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

Swift 4 - func physicsWorld not invoked on collision? The Next CEO of Stack OverflowHow to call Objective-C code from Swift#ifdef replacement in the Swift language@selector() in Swift?#pragma mark in Swift?Swift for loop: for index, element in array?dispatch_after - GCD in Swift?Swift Beta performance: sorting arraysSplit a String into an array in Swift?The use of Swift 3 @objc inference in Swift 4 mode is deprecated?How to optimize UITableViewCell, because my UITableView lags

Access current req object everywhere in Node.js ExpressWhy are global variables considered bad practice? (node.js)Using req & res across functionsHow do I get the path to the current script with Node.js?What is Node.js' Connect, Express and “middleware”?Node.js w/ express error handling in callbackHow to access the GET parameters after “?” in Express?Modify Node.js req object parametersAccess “app” variable inside of ExpressJS/ConnectJS middleware?Node.js Express app - request objectAngular Http Module considered middleware?Session variables in ExpressJSAdd properties to the req object in expressjs with Typescript