Using WooCommerce shortcodes

Yesterday I had some issues running WooCommerce shortcodes and didn’t found solution on YouTube or via Google. After an hour I figured it out. I created a post with the following shortcode:

[product_category category="letne-pneumatiky" order="asc"]

After viewing the post in the frontend a saw nothing with the following in single.php

<?php
// Start the Loop.
while ( have_posts() ) : the_post();

get_template_part( ‘content’, get_post_format() );

endwhile;
?>

As I made my own theme and copied this loop code from the default twentyfourteen it didn’t show anything. I think the problem could be that I have no content.php and also
get_post_format() didn’t output anything. During googling I found get_the_content() which outputed the raw content, not interpreted shortcode. So I came to do_shortcode()
Joining the knowledge success arise
echo do_shortcode( get_the_content() );
But I thought that’s not nice, there must be a different, nicer WordPress solution.
After some digging in the themes directory I found the solution.

<?php
if ( have_posts() ) :
// Start the Loop.
while ( have_posts() ) : the_post();

the_content();

endwhile;
endif;
?>

For a list of usable WooCommerce shortcodes visit http://docs.woothemes.com/document/woocommerce-shortcodes/

Advertisements

About Michal Zuber

Full stack developer, biker and rollerblader. Owner and developer at https://nevilleweb.sk/ Co-founded http://neville.sk/ Blog at https://michalzuber.wordpress.com/
This entry was posted in php, wordpress and tagged , , . Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s