product shortcode does not work for variable products
-
I’m having trouble getting the product shortcode to display variable products on a page. The shortcode is supposed to display the product in a format that is similar to the cards displayed in the shop. After a fair bit of debugging and logging, I believe the reason variable products do not display (as Simple products do in fact display just fine using this shortcode!) is related to the following conditional on the content-product template:
if ( ! is_a( $product, WC_Product::class ) || ! $product->is_visible() ) {
return;
}When I log the global $product here, I see that the $product is of the class ‘WC_Product_Variable’ (which makes sense) and the template therefore returns no content. This does not make sense to me and is exceedingly frustrating for a storefront that is made up primarily of variable products. It seems this was brought up in a previous support topic, but was possibly insufficiently tested. (I can’t be sure since it is hard to see if the tester attempted to re-create with a variable product):
Shortcodes [products ids=”12345″] do not work for variable products | WordPress.org
Is this a bug or a feature with some reasoning and a work-around I can apply to my site?
The topic ‘product shortcode does not work for variable products’ is closed to new replies.

