Posts

Showing posts with the label Product

Create Programmatically A WooCommerce Product Variation With New Attribute Values

Image
Answer : Update January 2020: Changed to WC_Product method get_name() instead of get_title() Update September 2018: Handling taxonomy creation (Thanks to Carl F. Corneil) From a defined variable product ID You will find below, a custom function that will add (create) a Product variation. The variable parent product needs to have set for it the needed attributes. You will need to provide some information as: the array of attributes/values the Sku, prices and stock…. This data has to be stored in a formatted multi dimensional array (see an example at the end) . This function will check if the attributes values (term name) already exist and if not: it create it for the product attribute set it in the parent variable product. The custom function code: /** * Create a product variation for a defined variable product ID. * * @since 3.0.0 * @param int $product_id | Post ID of the product parent variable product. * @param array $variation_data | The data to insert in the produ...