Displaying a WooCommerce product via PHP

Having a hard time composing a searchable query, so I apologize in advance if this has been covered.

I know you can add WooCommerce products to a page or post via short code, but I have one section of my site where it’s displaying from theme settings and PHP template only.

So my question is, how can I display a product on this section via PHP?

1 Answer
1

Use do_shortcode().

For example, in a template, if you were wanting to display products specifically by ID:

<?php

echo do_shortcode('[products ids="1, 2, 3, 4, 5"]');

?>

WooCommerce comes with several shortcodes which can be used to insert
content inside posts and pages: http://docs.woothemes.com/document/woocommerce-shortcodes/

You can add shortcodes to a post or page easily via the shortcode
shortcut button in the post editor: Woo Commerce Shortcode Editor

Leave a Comment