• Resolved Two Row Studio

    (@tworowstudio)


    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?

Viewing 4 replies - 1 through 4 (of 4 total)
  • Zee

    (@doublezed2)

    Hello Two Row Studio,

    Thank you for contacting WooCommerce support.

    I understand that variable products are not displaying with the product shortcode, while simple products work fine. The content-product template seems to be filtering out WC_Product_Variable products.

    Could you share a screenshot of your product edit page where you placed the shortcode? I’d like to replicate this on my test site and see how it behaves. You may use https://snipboard.io to upload images and share links here.

    Looking forward to your response. 🙂

    Thread Starter Two Row Studio

    (@tworowstudio)

    Here are two screenshots as both may be needed to confirm any issue. I am using WP Bakery’s page builder so the first one is showing the Widget used to set the shortcode within the content of the page and the second one is what the raw content is that gets stored with the post when saved.

    Plugin Support shahzeen(woo-hc)

    (@shahzeenfarooq)

    Hi there,

    Thank you for sharing the screenshot. I tested the shortcode [product id="12"] on my site to display a variable product, and it appears to be working correctly.

    For testing purposes, could you please try the following steps:

    • Deactivate the Classic Editor and any third-party page builder plugins.
    • Use the WordPress Shortcode block to insert the shortcode and see if it displays the product correctly.

    Since the shortcode is working fine on my test site, this suggests the issue might be related to a setting or custom code on your site. To narrow it down, I recommend:

    • Switching to the Storefront theme.
    • Deactivating all plugins except for WooCommerce.
    • Then, test the shortcode again.

    Let me know how it goes! I’m happy to help further based on what you find.

    Plugin Support Feten L. a11n

    (@fetenlakhal)

    Hi there,

    As we haven’t had any updates, I’ll assume this is resolved and close the thread. Feel free to reconnect anytime.

    Your review would mean a lot: https://wordpress.org/support/plugin/woocommerce/reviews/#new-post

Viewing 4 replies - 1 through 4 (of 4 total)

The topic ‘product shortcode does not work for variable products’ is closed to new replies.