• Resolved cssExp

    (@cssexp)


    I’m using woocommerce_params.wc_ajax_url.toString().replace(‘%%endpoint%%’, ‘add_to_cart’) via ajax to add products via custom shopping page instead of product page. Your plugin works on regular product page add, shows error and doesn’t add dependent product. However, with the ajax add to cart button it just adds the product to cart. It only shows error message via cart validation later on when go to the page. Is there any way to make it work with ajax product call instead of traditional page reload/redirection?

Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Author Jason Kytros

    (@jasonkytros)

    Hey @cssexp,

    Thanks for reaching out!

    WooCommerce core does not support AJAX Add to Cart buttons. It only includes AJAX functionality for Add to Cart buttons located in Shop Archives. Converting single-product page buttons to behave like this requires writing a significant amount of custom code.

    In your case it seems that the custom code you added bypasses the woocommerce_add_to_cart_validation filter and therefore the dependency notices do not show up.

    If you’d like additional assistance with reviewing your custom code, we recommend hiring a WooCommerce expert. Our top recommendation is https://codeable.io/.

    Cheers,
    Jason Kytros
    Support Engineer

    SomewhereWarm SMPC
    https://somewherewarm.gr/

    Thread Starter cssExp

    (@cssexp)

    Hi thanks for response!

    That’s the strange part, it doesn’t bypass other validations and stuff fired in woocommerce_is_purchasable filter. I suppose it’s too consuming to look into it. I guess I’ll explore other options.

    Plugin Author Jason Kytros

    (@jasonkytros)

    Hey @cssexp,

    Thanks for the follow-up!

    The woocommerce_is_purchasable and woocommerce_add_to_cart_validation are two different filters. To check if the woocommerce_add_to_cart_validation filter is called, you can write a brief debug snippet that prints a message in your logs when the Add to Cart button is clicked.

    If this message is never printed, then the woocommerce_add_to_cart_validation hook is bypassed. To figure out why, it is necessary to review the custom code you created. If you’d like further assistance with this, then please consider hiring a WooCommerce Expert as we previously mentioned.

    Cheers,
    Jason Kytros
    Support Engineer

    SomewhereWarm SMPC
    https://somewherewarm.gr/

    Plugin Author Jason Kytros

    (@jasonkytros)

    Hey @cssexp,

    Since we haven’t heard back from you in a while, I am going to mark this thread as resolved. Feel free to open a new one if there is anything else we can help with!

    Cheers,
    Jason Kytros
    Support Engineer

    SomewhereWarm SMPC
    https://somewherewarm.gr/

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Does not work with ajax ADD to Cart button’ is closed to new replies.