Support » Plugin: WooCommerce » Make all products 'related' / all products listed under a single item

  • Resolved trcyshw



    A client sells hampers, to which customers can then choose to add extras. What I’d like to do is to show the hamper as a single product, which then lists all the items in another category (e.g. ‘Extras’) underneath the main product. So essentially, the customer can shop from one page.

    If I create a Page within WordPress, I can make a custom product page using WooCommerce shortcodes:

    [product id="18"]
    [product_category category="extras" per_page="20" columns="4" orderby="date" order="desc"]

    I know about WooCommerce’s ability to override default templates by creating your own within your theme, but I’m not sure of the correct calls. How can I replicate the above shortcode functionality on my single product page when the customer is looking at a hamper?

    Any gentle shoves in the right direction are greatly appreciated.

Viewing 2 replies - 1 through 2 (of 2 total)
  • Found my solution! If anyone else is wondering, then WooCommerce’s do_shortcode() function is your friend.

    Using the function, I could call the product_category shortcode on single-product.php.

    So for my product with an ID of 18:

    <?php if (is_product(18)) { echo do_shortcode( ‘[product_category category=”extras” per_page=”20″ columns=”4″ orderby=”date” order=”desc”]’ ); } ?>

    I got a bit ahead of myself, turns out the above didn’t really work. However, this seems to be doing the trick.

    $terms = wp_get_post_terms( $post->ID, 'product_cat' );
    foreach ( $terms as $term ) $categories[] = $term->slug;
    if (in_array( 'hampers', $categories)) {
    echo 'hampers'; echo do_shortcode( '[product_category category="extras" per_page="20" columns="4" orderby="date" order="desc"]' );

    Probably comes as no surprise to anyone reading this thread that I’m no expert with PHP, so corrections are appreciated.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Make all products 'related' / all products listed under a single item’ is closed to new replies.