0

I need to display global $product in my custom shortcode. I am trying to create a manual layout of $product with only products with "category C".

so in my shortcode i declared

//Create display Apple function    
function wpb_displayApples_shortcode() { 
        global $product;
        echo '<pre>';
        print_r($product);
        echo '</pre>';
    } 
    // register shortcode
    add_shortcode('displaydisplayApples', 'wpb_displayApples_shortcode');

but my functions return blank $product

When i use $woocommerce, I get data but I can not locate my products.

How do i get all my products on my custom shortcode, to manually display control my products layout?

Thando Hlophe
  • 57
  • 2
  • 12

1 Answers1

0

So after researching more I found this code from Woocommerce get products

$args = array(
        'post_type'      => 'product',
        'posts_per_page' => 10,
        'product_cat'    => 'hoodies'
    );

    $loop = new WP_Query( $args );

    while ( $loop->have_posts() ) : $loop->the_post();
        global $product;
        echo '<br /><a href="'.get_permalink().'">' . woocommerce_get_product_thumbnail().' '.get_the_title().'</a>';
    endwhile;

    wp_reset_query();
Thando Hlophe
  • 57
  • 2
  • 12