The WooCommerce Cart add_to_cart function takes a parameter for cart_item_data. To make this work, you simply need to pass the addon data to add_to_cart. Something like this:
$addons = array(
array(
"name" => "Size",
"value" => "2.5x7",
"price" => 0,
"field_name" => "5186-0",
"field_type" => "multiple_choice",
"id" => "1683555538",
"price_type" => "flat_fee"
),
array(
"name" => "Medium",
"value" => "Print",
"price" => 0,
"field_name" => "5186-1", // {product_id}-{addon_index}
"field_type" => "multiple_choice",
"id" => "1683555539",
"price_type" => "flat_fee"
)
);
$product_id = 11;
$quantity = 1;
$variation_id = null;
$variation = null;
$cart_item_data = array('addons' => $addons);
WC()->cart->add_to_cart($product_id, $quantity, $variation_id, $variation, $cart_item_data);
Related Posts:
- How to override WooCommerce Order Item Meta with data from Cart?
- sessionStorage saves input value in browser but it is not loaded in the form field
- Woocommerce textarea format ignored
- How to auto-generate random numbers in username?
- i want add conditional for add category in wordpress
- Remove generated category and tag class names from woocommerce product & blog listings markup
- Adding a widget under an ‘Add to Cart’ button through a PHP snippet
- WooCommerce Quantity in Dropdown menu instead of clasic [closed]
- How to get total gross revenue for current month in the woocommerce dashboard status widget
- Add custom attribute to product’s HTML to woocommerce cart page
- Change WooCommerce template for PDF – access to custom field
- WooCommerce get products based on the taxonomy
- WP_Query To Display Product Of Brand On Taxonomy Page
- Woocommerce Add custom “Add to cart button” in single page with tags
- Reverse Cross-Sells (WooCommerce)
- Woocommerce remove menu item on myaccount dashboard
- How can i style “echo apply_filters”
- Hot to edit WooCOmmerce dashboard?
- How to echo a PHP code into WooCommerce variation product?
- How can I add another row to the total field in WooCoommerce cart, checkout and recipe mail?
- WooCommerce subcategories help
- Get Billing Email from WooCommece Checkout and Pass to Fullstory JS
- Woocommerce custom attributes list help
- WooCommerce multiple custom fields code
- Get all woocommerce product names with price and show using core php
- Search function not working
- loop to return tags in woocommerce in alphabetical order?
- Woocommerce Related Product by 2 taxonomy
- append data to mysql table via submit button coded in php – not working
- random woocommerce categories are not showing when count enabled?
- Add custom ID attribute to all woocommerce products on archive pages
- Put a span class in the shortened product title
- How to properly create multiple conditions to redirect users roles to different pages
- Add missing alt tag to featured images for “storefront” theme
- WooCommerce – Add Shipping class below each product in Shopping Cart page
- Hide price excluding tax when price is empty
- How to limit functionality of a woocommerce plugin to only certain user role?
- WooCommerce Custom Tab with ACF Repeater Field
- PHP – Woocommerce 3.2 Add variable shipping insurance with multiple “else if ” conditions
- How can i put php code on the wordpress page?
- Sort WooCommerce data with WP-CRON?
- Woocommerce variable products are being added to the card on the homepage (ajax)
- Display specific main Sub Nav on Woocommerce product pages
- How to have more than one ID included in the exclude command?
- Clone the “proceed to cart” button and place it above checkout on the cart page, but only appear display size is 320px
- I was wondering if it’s possible to implement card.js on WordPress
- wp_query beginner
- Global filter not working
- how to display woocomerce description of each category in wordpress? [closed]
- Use PHP code in Menu Admin Section
- Woocommerce variation with radio button + price
- WordPress 3.0 PHP Error – notice WordPress_product_Type was called incorrectly
- Display text of price (minus 20%) on every product page in a sentence.
- WooCommerce – Add product category below product price [closed]
- How to detect if a revision was made by woocommerce or wordpress?
- Need Quick Help With Product Category Page
- WooCommerce remove_action and add_action [closed]
- woocommerce plugin bugs
- Woocommerce custom field on emails outputs ‘Array’
- How do I prevent a folder from reappearing in my home directory?
- Display product attributes for current product
- jQuery doesn’t work in my php snippet
- Adding my own custom template page but got white page
- Getting the date_diff function return the difference in days
- WordPress using get_term to retreive slug not working as expected
- Can’t make product images clickable
- How to remove image on single product and get product to span page?
- WooCommerce – Print Processing orders [closed]
- Use WP_Query Data In Cookie
- Woocommerce Price Text
- Hide cart when empty [closed]
- Need some help with tweaking a code for woocommerce [closed]
- How to add custom checkout field in user details mail template
- WooCommerce Custom Pagination
- How to set up and use a custom upload directory for post type ‘product’
- How to get the rating value of each comment
- Add specific phrase after every product title including the discounted price? [closed]
- Ajax Load More or View More functionality for woocommerce category layout by template overriding
- How to add margin underneath woocommerce total price amount -> productpages
- Adding placeholder text field to woocommerce checkout [closed]
- Display Sale Price Before Regular Price (WooCommerce)
- wc_add_notice not working on cart page
- Order woo products, but first products must be with acf fields
- How keep woocommerce users separeted in multisite install and keep admins on network
- ACF | WooCommerce | Theme Development | How to include a /template-part/ that makes use of ACF’s on a custom WooCommerce homepage?
- Setting WooCommerce currency programmatically
- Woocommerce – Shipping tax class based on cart items not using the highest tax available
- Getting custom field data from cart page to checkout page in woocomerce [closed]
- How to find the value of the user password in wordpress and send it to another server via rest api
- Exclude specific product tags from related products in WooCommerce 3+ [closed]
- WooCommerce Orders pagination
- Change Checkout “Place Order” text if cart has a specific product
- How do I update product shipping using PHP in WooCommerce?
- Product Category Page in Full Width
- How can I edit the WooCommerce Mini DropDown Cart to read as follows
- Send a custom notification to customer on WooCommerce cancelled order status
- How to code bulk order form in wordpress
- FATAL ERROR , Sommerce Theme [closed]
- Woocommerce linking variations
- Warning: Attempt to read property “term_id” on int – Woocommerce