That shortcode shows the product itself, not a child variation.
You can output a cart button for a variation using one of the product add to cart shortcodes, but you cannot output a full variation. There is no view to see individual variations in WC.
Hi,
lapatente has hired me and I have created such shortcode via a plugin.
It shows the variation title linked to product page. Also shows the variation attributes and stock level.
Not sure if this should be turned into a PR at github or simply released here at WordPress.org…
Any advices?
Cheers,
Gabriel
Hi Gabriel
We can review it if you do a PR 🙂 Leave some screenshots and we’ll leave feedback.
Thanks!
I have a solution.
Use the shortcode: [add_to_cart id="971"], with 971 being the id of the variation product, or rather, the unique id of a variation of a variable product.
Then for some reason I have to edit the actual woocommerce file “class-wc-shortcodes.php” becasue I can’t seem to get my theme file to override it.
- Open class-wc-shortcodes.php
- Look for the function with comment
Display a single product price + cart button., should be line 419.
- Then look for line:
<?php if ( 'true' == $atts['show_price'] ) : ?>
- Inside there should be
<?php echo $product->get_price_html(); ?>
- Now just add new things like:
<?php echo $product->get_title(); ?>
<?php echo $product->get_categories(); ?>
<?php echo $product->get_sku(); ?>
<?php echo $product->get_image(); ?>
Of course, you can get more detailed and put divs and things to style the output to look just like you are outputting a normal product using the shortcode [product sku="ZN1U0000RS"] for example.
This would be such sensationally easy functionality for woocommerce to add, i.e. when you put in the shortcode [product sku="ZN1U0000RS"] for example, it outputs the same regardless of whether it is a simple or variation of a variable product. Sometimes I want my client to add the variation I suggest, instead of having them go to the variable product page to select a variation. An sku is an sku. An id is an id. A variation of a product should be treated just like any other product. It deserved the same respect.
Beware that myburgh.bernard@gmail.com ‘s solution would be erased each time WooCommerce gets updated.