Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

287
Views
Remove Klarna Payments with cash on delivery method

I have a problem with a code. So I have five different payment methods in my site. When a customer select "Cash on delivery" as shipment method all the payment methods, exept cash on delivery, are hide. For make that I use the follow code:

/**
* Remove payment methods when select "pagamento in contrassegno"
*/
function my_custom_available_payment_gateways( $gateways ) {

$chosen_shipping_rates = WC()->session->get( 'chosen_shipping_methods' );

// When 'Pagamento in contrassegno' has been chosen as shipping rate
if ( in_array( 'flat_rate:5', $chosen_shipping_rates ) ) :

    // Remove the follow payments
    unset( $gateways['woocommerce_payments'] );
    unset( $gateways['paypal'] );
    unset( $gateways['bacs'] );
    unset( $gateways['klarna_payments_pay_later'] );

    endif;

    return $gateways;

    }
    add_filter( 'woocommerce_available_payment_gateways', 
    'my_custom_available_payment_gateways' );

The code work with all payments exept for Klarna payments that remain if I select "Pagamento in contrassegno" (cash on delivery), how can I solve that?

The site is: https://www.modacapellishop.it/

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Try with

unset( $gateways['klarna_payments'] );

it works for me

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!