3

I am new to WordPress and I am using WooCommerce for a online store. I have found a small issue on one of the plugins that i needed for a specific product, and now I shall need to refresh the page automatically after adding the product on cart.

How can I easily do it without compromise the whole store? Is there anyway I can achieve this?

I did try to search for the origin php or js for add to cart event, but I couldn't find anything, and afterwards I tried to add a location.reload() to the add to cart class but it didn't solve my problem as well. This is everything i've tried so far.

1

1 Answer 1

1

Maybe this will work for you. It will refresh your page when the add to cart button is clicked. Add it to your functions.php

add_action('woocommerce_add_to_cart', 'refresh_function');

function refresh_function(){
header("Refresh:0");
}
15
  • Hello John, thank you very much for your answer ! Can i use that code on a snippet or it is required to be applied on functions.php ? May 25, 2020 at 18:03
  • I am not sure if it will work in a snippet, you could always try it. But I know it works in the functons.php
    – John
    May 25, 2020 at 18:06
  • Well i did try it on a Snippet and unfortunately it didnt work so i just should paste it on functions.php, anyway, where can i find that file (functions.php) ? May 25, 2020 at 18:10
  • wp-content > themes > [YOUR THEME] and the functions.php will be there.
    – John
    May 25, 2020 at 18:13
  • Of if you're doing it from the wordpress side (I don't recommend it though in case you break something) its Appearance > theme editor and the functions.php will be on the right hand bar under "Theme Functions"
    – John
    May 25, 2020 at 18:15

Your Answer

Reminder: Answers generated by Artificial Intelligence tools are not allowed on Stack Overflow. Learn more

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.