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

SQL error code 1064 with creating Laravel foreign keysForeign key constraints: When to use ON UPDATE and ON DELETEDropping column with foreign key Laravel error: General error: 1025 Error on renameLaravel SQL Can't create tableLaravel Migration foreign key errorLaravel php artisan migrate:refresh giving a syntax errorSQLSTATE[42S01]: Base table or view already exists or Base table or view already exists: 1050 Tableerror in migrating laravel file to xampp serverSyntax error or access violation: 1064:syntax to use near 'unsigned not null, modelName varchar(191) not null, title varchar(191) not nLaravel cannot create new table field in mysqlLaravel 5.7:Last migration creates table but is not registered in the migration table

은진 송씨 목차 역사 본관 분파 인물 조선 왕실과의 인척 관계 집성촌 항렬자 인구 같이 보기 각주 둘러보기 메뉴은진 송씨세종실록 149권, 지리지 충청도 공주목 은진현