Support » Plugin: Product Addons for Woocommerce » Add Field Value Programmatically

  • Resolved reshampanth

    (@reshampanth)


    Hi,
    I’m creating a product for which I need an additional text field. The value of this field will be defined by the customer’s actions prior to clicking on the Add TO Cart link.
    The Customer will provide two values prior and based on those values, I have to add the appropriate product to cart directly using Woocommerce hooks WC()->cart->add_to_cart( 1326 )
    My first question is, how do I set the value for the additional field manually before adding the product to cart?
    My second question is, how do I display this in the Cart and Checkout page? Will the field automatically show up along with the cart information? Will it work with Oxygen Builder?

    Thanks in Advance!

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

    (@ashwinacodez)

    Hi,

    As per your requirement, what we understand is you need to add a product to the cart programmatically once a button is pressed. For this you can’t access our plugin classes directly, instead, you have to follow one Woocommerce filter hook woocommerce_add_cart_item_data

    woocommerce_add_cart_item_data hook will provide you the details added by our plugin and you can even alter its values.

    
    add_filter('woocommerce_add_cart_item_data', function($cart_item_data, $product_id, $variation_id)
    {
       //$cart_item_data you can check all custom field values in this variable 
       return $cart_item_data;
    }, 10, 3);

    Hope this helps.

    Thank you

    • This reply was modified 3 months, 2 weeks ago by ashwinacodez.
    Thread Starter reshampanth

    (@reshampanth)

    Hi,

    Thank you for your response! This is exactly the information I need!

    I’ll try to implement this and will update the ticket if any issues come up 🙂

    Cheers,
    Resham Panth

Viewing 2 replies - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.