I am trying to create a short-code to get products from specific category in woocommerce. I am using ‘tax_query’ to target specific category and ‘shortcode_atts’ to get parameter from shortcode itself. The code is as follow:

function quick_launch_products($atts) {

    extract(shortcode_atts(array(
        'product_category_ID' => 1,
    ), $atts));

    $args = array(
        'post_type'             => 'product',
        'post_status'           => 'publish',
        'ignore_sticky_posts'   => 1,
        'posts_per_page'        => '12',
        'meta_query'            => array(
            array(
                'key'           => '_visibility',
                'value'         => array('catalog', 'visible'),
                'compare'       => 'IN'
            )
        ),
        'tax_query'             => array(
            array(
                'taxonomy'      => 'product_cat',
                'field'         => 'term_id',
                'terms'         => $product_category_ID,
                'operator'      => 'IN'
            )
        )
    );

    return $product_category_ID;

    $products = null;
    $products = new WP_Query($args);
}        
add_shortcode("quick_launch_product_slider", "quick_launch_products");

The shortcode:

[quick_launch_product_slider product_category_ID="383"]

The return value is blank. I saw a lot of demo codes and followed exactly as they were, but its not working at all.

What am i missing here?
Thanks in advance.

Read more here: Woocommerce: Create short-code with parameters


Solution:

If you know the solution of this issue, please leave us a reply in Comment section, to update the question.


Wordpress related questions and answers: