0

If I need to offer a product in a WooCommerce product tab inside another product I can. This can be done with a WooCommerce shortcode

[product id="xxx"]

Now if you also want the customer to be able to add this product to the cart you can add a cart button and connect it to the product id like so

[add_to_cart id="xxx"]

However what I need is to have the sample product in tab to be connected to the parent product. Connected in the way that the main product SKU and and title are connected to the sample product in the tab. The sample product is a separate product this way now. But it is a sample of the main product.

Background

The reason to add it this way is to be able to not add hundreds of sample products besides the main product. And all these sample products cost the same and do not need a separate thumbnail per se.

Pass SKU and Title Main Product to Sample Product

Now, how can I on adding to cart add this sample product to be added with the name and SKU of the product its page it is displayed on in a WooCommerce Tab?

Example

So let's say a loaf of wholewheat bread SKU 1238, price €1.23, sample slice €0.2 - sku 125 - is added to cart with name Wholewheat Bread Sample SKU 1238, price €0.22.

Question in detail

Can I do this with this general sample product somehow? This so the seller sees what sample to send basically? By having the title and SKU of the product the sample is based on. And to not have to great hundreds of sample products?

1 Answer 1

1

I would therefore create a new short code based on the existing one

https://docs.woocommerce.com/wc-apidocs/source-class-WC_Shortcodes.html#295

Where before adding the product (sample) to the shopping cart the values ​​of the sample product will be updated with the values ​​of the (main) product.

then you could using something like this

$product = wc_get_product( $product_id );
$product->set_sku( 1234 );
$product->save();
href=”http://yourdomain.com/?add-to-cart=product_id″

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.