• Resolved MCI Desarrollo

    (@mcidesarrollo)


    Hi there. I created a plugin so that the user can request product samples in WooCommerce that is based on adding the product to the cart with $ woocommerce-> cart-> add_to_cart and then modifying its name and price.
    In variable products it shows the “Product added to cart” notice correctly but in simple products it only shows the notice when reloading the page for the second time.
    The way to add the simple product and the variable is the same but the result is different.
    Do you know why WooCommerce can have this behavior?
    Thank you very much for your help!

Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Support kellymetal a11n

    (@kellymetal)

    Hi there,

    It’s hard to say without seeing the code, but based on your description, it sounds like your custom plugin code would need to handle things differently between Variable and Simple products. There’s some info about adding products/variations to the Cart programmatically here:
    https://rudrastyh.com/woocommerce/add-product-to-cart-programmatically.html

    If you need assistance with coding or custom development, we recommend reaching out to a developer from one of the services at https://woocommerce.com/customizations/

    I’ll leave this open for now in case any other community members have other advice.

    Thread Starter MCI Desarrollo

    (@mcidesarrollo)

    Hello, thank you very much for your answer.
    Finally the best solution I have found is to add a script like this after adding 1 unit to the cart:
    echo ‘<script type = “text / javascript”> window.location.href = “‘. get_permalink (). ‘” </script>’;
    Now the page reloads a second time and that way it shows the notice correctly.
    I haven’t been able to figure out why using the exact same add to cart method WooCommerce needs to reload only for simple products and it works fine without reloading for variable products.

    Greetings!

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Notice only the second page reload’ is closed to new replies.