WooCommerce Shortcodes Breaks Sage Site

When I add WooCommerce shortcodes as follows in WordPress WYSIWYG editor pages or in blade templates:
[products columns=“4”]
{!! do_shortcode(’[products columns=“4”]’) !!}
<?php echo do_shortcode('[products columns="4"]'); ?>
@php echo do_shortcode(’[products columns=“4”]’); @endphp

My WordPress site breaks, removes the admin bar, and doesn’t display any products. I have Sage WooCommerce (https://github.com/roots/sage-woocommerce) installed and I can override the template pages just fine. The issue comes in when I try to use WooCommerce shortcodes and even template functions like “wc_get_template_part(‘content’, ‘product’);”. It even breaks product pages when I insert the WooCommerce shortcodes.

I think you have missed something. I have tried to implement it and it worked without any issue.

Please check it once and confirm.

I did. It just loads in a blank container.

I have lots of products loaded as well.

The code

Does this happen on development or on staging/production?
When the page breaks and output is aborted there is probably a fatal PHP error.
Is error display enabled? What is logged in the PHP error logs?

I figured it out. I had a file in the /woocommerce/content-product.blade.php that was blanking out all the [product*] stuff. Removing it made all the shortcodes work again. Thank you all for responding.

Just a note, best practice (and best outcome) is to use the following:

{!! do_shortcode('[products columns="4"]') !!}

Rather than using @php in templates wherever possible.

1 Like

This topic was automatically closed after 42 days. New replies are no longer allowed.