• Resolved petschko

    (@petschko)


    Hey,

    I need to disable all Payment-Gateways on a certain condition in the checkout, except one.
    I used this method to hook into

    
    add_filter('woocommerce_available_payment_gateways', [$this, 'replaceWithRequestPaymentGateway']);
    
    /**
     * @param array $paymentGateways
     * @return WC_Payment_Gateway[]
     */
    public function replaceWithRequestPaymentGateway(array $paymentGateways): array {
    	$myFreeGateway = new PaymentGatewayFree();
    
    	// Replace all other Gateways with the custom one
    	$paymentGateways = [$myFreeGateway->id => $myFreeGateway];
    
    	return $paymentGateways;
    }
    

    That actually works pretty well. I just have the Problem, whenever the AJAX-Reload on the checkout page loads the Payment methods, it shows all default payment methods again.
    I think I need to hook into the ajax request as well, but I didnt seem able to find it, do you have any hints were to look? (I may need to send a parameter via that ajax request, so i can use it to get the correct payment systems there as well)

    Thank you so much!

    • This topic was modified 3 years, 11 months ago by petschko.
    • This topic was modified 3 years, 11 months ago by petschko. Reason: Added a small sentence
Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Support Gabriel – a11n

    (@gabrielfuentes)

    Hi there ??

    This is a fairly complex development topic. I’m going to leave it open for a bit to see if anyone is able to chime in to help you out.

    I can also recommend the WooCommerce Developer Resources Portal for resources on developing for WooCommerce.

    You can also visit the WooCommerce Facebook group or the #developers channel of the WooCommerce Community Slack. We’re lucky to have a great community of open-source developers for WooCommerce, and many of our developers hang out there, as well.

    Cheers!

    Thread Starter petschko

    (@petschko)

    Hey,

    I figured it out myself how to solve this, it was rather complex. If someone else want to know how to do it, I can help you out then. I just don’t want to write my solution here, because its to long and im unsure if even someone needs it

    Thank you =)

    Plugin Support Gabriel – a11n

    (@gabrielfuentes)

    That’s wonderful ??

    I’m glad to know that you could figure it out! If you have any further questions, you can start a new thread.

    Cheers ??

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Payment-Gateways AJAX-Reload’ is closed to new replies.