Woocommerce: Update variable product

Good day,

I am trying to create a workflow that updates the “sale price” and “Date On Sale To” in Woocommerce.

It works great with simple products, but it’s not working for variable products.

Does anyone knows how can I change data from a variable Woocommerce product?

Thanks!

Hey @illusionandcards

According to my tests, the WooCommerce node is not ready to update variable products, as it does not perform the variation update when you tell it its ID.

As I see in the code of the WooCommerce node, it only updates simple products since only the /products/${productId} instruction appears and the /products/<product_id>/variations/<id> instruction that updates variable products through the WooCommerce API does not appear.

if (operation === 'update') {
					const productId = this.getNodeParameter('productId', i) as string;
					const updateFields = this.getNodeParameter('updateFields', i);
					const body: IProduct = {};

					setFields(updateFields, body);

					const images = (this.getNodeParameter('imagesUi', i) as IDataObject)
						.imagesValues as IImage[];
					if (images) {
						body.images = images;
					}
					const dimension = (this.getNodeParameter('dimensionsUi', i) as IDataObject)
						.dimensionsValues as IDimension;
					if (dimension) {
						body.dimensions = dimension;
					}
					const metadata = (this.getNodeParameter('metadataUi', i) as IDataObject)
						.metadataValues as IDataObject[];
					if (metadata) {
						body.meta_data = metadata;
					}
					responseData = await woocommerceApiRequest.call(
						this,
						'PUT',
						`/products/${productId}`,
						body,
					);
				}

As you know, variable products in WooCommerce create a product ID for each variation, so to update a variation you must always tell it the variation ID.

In the example that you will find in Producto variable – Rainy Daughter the variable product (ID 11) has three variations (S|M|L) with respective IDs (12|13|14). To update the sale_price and date_on_sale_to fields of the variation S (ID 12) you must create a workflow like the following that updates directly through the WooCommerce API.

:wink:

4 Likes

Wow! Thank you very much for your detailed explanation.

PD: Yo también soy de España :raised_hands:t2:

2 Likes

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.