• Resolved igyhere

    (@igyhere)


    Hi,

    I noticed that checkout-wc is calling the WC_Payment_Gateways->get_available_payment_gateways() twice during the Ajax call ‘update_order_review’. This is slowing down the server as sometimes the gateways do some Ajax calls themselves on this filter and it takes time to complete. So when we call this twice it is twice slower. Please refactor this somehow such that this is only called once. I think this also called during checkout page generation.

    Here is the logs I checked this:

    [23-Aug-2024 10:49:30 UTC] Checking payment gateways
    [23-Aug-2024 10:49:30 UTC] #0 /var/www/html/wp-includes/class-wp-hook.php(324): debug_payment_gateways()
    #1 /var/www/html/wp-includes/plugin.php(205): WP_Hook->apply_filters()
    #2 /var/www/html/wp-content/addons/woocommerce/includes/class-wc-payment-gateways.php(333): apply_filters()
    #3 /var/www/html/wp-content/addons/checkout-for-woocommerce/sources/php/functions.php(397): WC_Payment_Gateways->get_available_payment_gateways()
    #4 /var/www/html/wp-content/addons/checkout-for-woocommerce/sources/php/functions.php(945): cfw_get_payment_methods_html()
    #5 /var/www/html/wp-content/addons/checkout-for-woocommerce/includes/Action/UpdateCheckoutAction.php(213): cfw_get_payment_methods()
    #6 /var/www/html/wp-content/addons/checkout-for-woocommerce/includes/Action/CFWAction.php(76): Objectiv\Plugins\Checkout\Action\UpdateCheckoutAction->action()
    #7 /var/www/html/wp-includes/class-wp-hook.php(324): Objectiv\Plugins\Checkout\Action\CFWAction->execute()
    #8 /var/www/html/wp-includes/class-wp-hook.php(348): WP_Hook->apply_filters()
    #9 /var/www/html/wp-includes/plugin.php(517): WP_Hook->do_action()
    #10 /var/www/html/wp-content/addons/woocommerce/includes/class-wc-ajax.php(96): do_action()
    #11 /var/www/html/wp-includes/class-wp-hook.php(324): WC_AJAX::do_wc_ajax()
    #12 /var/www/html/wp-includes/class-wp-hook.php(348): WP_Hook->apply_filters()
    #13 /var/www/html/wp-includes/plugin.php(517): WP_Hook->do_action()
    #14 /var/www/html/wp-includes/template-loader.php(13): do_action()
    #15 /var/www/html/wp-blog-header.php(19): require_once('/var/www/html/w...')
    #16 /var/www/html/index.php(17): require('/var/www/html/w...')

    [23-Aug-2024 10:49:31 UTC] Checking shipping address
    [23-Aug-2024 10:49:31 UTC] Checking payment gateways
    [23-Aug-2024 10:49:31 UTC] #0 /var/www/html/wp-includes/class-wp-hook.php(324): debug_payment_gateways()
    #1 /var/www/html/wp-includes/plugin.php(205): WP_Hook->apply_filters()
    #2 /var/www/html/wp-content/addons/woocommerce/includes/class-wc-payment-gateways.php(333): apply_filters()
    #3 /var/www/html/wp-content/addons/checkout-for-woocommerce/sources/php/template-functions.php(910): WC_Payment_Gateways->get_available_payment_gateways()
    #4 /var/www/html/wp-content/addons/checkout-for-woocommerce/sources/php/functions.php(3383): cfw_get_review_pane_payment_method()
    #5 /var/www/html/wp-content/addons/checkout-for-woocommerce/includes/Managers/AssetManager.php(917): cfw_get_review_data()
    #6 /var/www/html/wp-content/addons/checkout-for-woocommerce/includes/Action/UpdateCheckoutAction.php(233): Objectiv\Plugins\Checkout\Managers\AssetManager::get_data()
    #7 /var/www/html/wp-content/addons/checkout-for-woocommerce/includes/Action/CFWAction.php(76): Objectiv\Plugins\Checkout\Action\UpdateCheckoutAction->action()
    #8 /var/www/html/wp-includes/class-wp-hook.php(324): Objectiv\Plugins\Checkout\Action\CFWAction->execute()
    #9 /var/www/html/wp-includes/class-wp-hook.php(348): WP_Hook->apply_filters()
    #10 /var/www/html/wp-includes/plugin.php(517): WP_Hook->do_action()
    #11 /var/www/html/wp-content/addons/woocommerce/includes/class-wc-ajax.php(96): do_action()
    #12 /var/www/html/wp-includes/class-wp-hook.php(324): WC_AJAX::do_wc_ajax()
    #13 /var/www/html/wp-includes/class-wp-hook.php(348): WP_Hook->apply_filters()
    #14 /var/www/html/wp-includes/plugin.php(517): WP_Hook->do_action()
    #15 /var/www/html/wp-includes/template-loader.php(13): do_action()
    #16 /var/www/html/wp-blog-header.php(19): require_once('/var/www/html/w...')
    #17 /var/www/html/index.php(17): require('/var/www/html/w...')
Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Author Clifton Griffin

    (@clifgriffin)

    Hi there,

    By AJAX call, I assume you mean a remote call to the gateway server?

    Do you have an example gateway? This strikes me as poor gateway design.

    We might be able to reduce this to 1 call – I’ll look into it.

    Clif

    Thread Starter igyhere

    (@igyhere)

    thanks for looking into that. The gateway specifically is https://wordpress.com/plugins/ing-lease-now. They call their server to check payment availability and I already asked them to cache the call but that is another issue. Let’s say the call takes 500ms and is called in

    get_available_payment_gateways()

    Then checkout wc calls it twice and it slows down the whole checkout as this is the Ajax call that checkout wc uses for every update on the front end. This can be even worse when more gateways are used like that as this adds up.

    Plugin Author Clifton Griffin

    (@clifgriffin)

    I’ve confirmed the behavior you’re seeing.

    Making calls to get_available_payment_gateways() should be safe – there are various reasons to do. We have to call it to make sure that all of the payment gateways are loaded and available for interacting with in a couple of contexts.

    WooCommerce core calls it in many places for example. This isn’t a CheckoutWC specific behavior.

    What’s happening here is that this gateway is poorly coded. Making an API call on this filter is a really bad idea. At the very minimum they should cache the results of this API call, but really they should handle this differently altogether.

    You might consider forking the plugin and running a modified version until they fix this.

    Thread Starter igyhere

    (@igyhere)

    Thanks for taking a closer look. I will also share your findings with the plugin. However, I would like to note that the get_available_payment_gateways() is Called only once on the original WooCommerce checkout page. Is it possible you can refactor CheckoutWC to also call it once?

    Thanks ??

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Slow down – 2 calls to WC_Payment_Gateways->get_available_payment_gateway’ is closed to new replies.