• Resolved arconsulting

    (@arconsulting)


    Using the following in a function to add a product variation to a cart. The correct price is printing, but the parent name is printing instead of the variation name. Wonder if anyone knows why this might be happening?

    WC()->cart->add_to_cart( $_POST[‘product_id’], 1, $_POST[‘variation_id’]);

    thank you in advance,

    Andrea

    The page I need help with: [log in to see the link]

Viewing 6 replies - 1 through 6 (of 6 total)
  • Remi Corson

    (@corsonr)

    Automattic Happiness Engineer

    Hi @arconsulting,

    If I am capturing this correctly, you’re trying to add a variable product to the cart programmatically.

    The code you’re using seems to be correct since the right syntax is:

    WC()->cart->add_to_cart( $product_id, $quantity, $variation_id );

    As a first step, I’d suggest you double-check your $POST[] vars.

    Thread Starter arconsulting

    (@arconsulting)

    Thanks for your reply. I had already checked, however, to make sure it isn’t the coding I added one variable product directly to the cart and the same thing happens (parent id, quantity of 1, and variable ids):

    WC()->cart->add_to_cart(96012, 1, 96130);

    The results are the same. The price changes with each variation correctly, but not the title. Also, the url on the “a” tag changes as well. Something must be blocking it, but adding it directly should have worked. Very strange. Any thoughts?

    Remi Corson

    (@corsonr)

    Automattic Happiness Engineer

    Hi @arconsulting,

    By default you should have in the cart the parent product name, then a dash, then the variation, like so:


    Link to image: https://d.pr/i/g9Mli3

    If not, maybe you’re using a custom template that modifies this default behavior?

    Thread Starter arconsulting

    (@arconsulting)

    Hi there,

    Thanks again. I have done a lot of customization so no doubt something I have done, but have removed event listeners (as there is a lot of jQuery ajax coding) and revisions to templates.

    Here is the page. If you scroll down to “Please select one of the following:” and select a membership option from the pulldown menu, you can view the problem in the cart by hovering over the green button on the top navigation bar.

    I am grateful for any assistance or ideas. I don’t expect you do debug. Just thought it might be easier if you saw the problem.

    https://wooc.nanps.org/online-plant-sale/

    thanks again,
    andrea

    Remi Corson

    (@corsonr)

    Automattic Happiness Engineer

    Hi @arconsulting,

    I can’t tell this is related but that is something I would check:


    Link to image: https://d.pr/i/3IV556

    Plugin Support fevered – a11n

    (@fevered)

    Hey there, since we haven’t heard back from you in awhile I’ll mark this thread as resolved now. If you have any further questions, I recommend creating a new thread.

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Adding Variable Product to cart’ is closed to new replies.