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.