• Resolved JapeNZ

    (@japenz)


    Hi there, is there any way to use both a product category and tags in the same shortcode?

    Basically I’m wanting to display only products in a specific category (other-publishers) that have a specified tag (back-issue).

    I’ve tried the following shortcodes without any luck:

    [product_tag tags=”back-issue” product_category category=”other-publishers” per_page=”-1″ columns=”5″ orderby=”sku” order=”asc”]

    [product_tag tags=”back-issue” category=”other-publishers” per_page=”-1″ columns=”5″ orderby=”sku” order=”asc”]

    [product_category category=”other-publishers” tags=”back-issue” per_page=”-1″ columns=”5″ orderby=”sku” order=”asc”]

    [product_category category=”other-publishers” product_tag tags=”back-issue” per_page=”-1″ columns=”5″ orderby=”sku” order=”asc”]

    Any help would be very much appreciated 🙂

    Kind regards,
    JP

Viewing 6 replies - 1 through 6 (of 6 total)
  • Plugin Contributor Sébastien Dumont

    (@sebd86)

    No. This plugin is designed to display products by tags only because WooCommerce does not provide it in the core.

    Thread Starter JapeNZ

    (@japenz)

    Hi Sebastien,
    Thanks for getting back to me 🙂

    Bummer! lol

    Do you think this is something that could be done with some coding? Might I be able to add categories to the tags array or something?

    I’m certainly not much of coder, but if you think it might be doable I’ll certainly give it a go.

    Any suggestions or links that might help would be appreciated.

    Thanks again!
    JP

    Thread Starter JapeNZ

    (@japenz)

    Hello again Sebastien,
    I think I might have got it!

    I’ve added the following to ‘// Get attributes’
    ‘category’ => ”,

    and this to ‘// Default ordering args’
    ‘product_cat’ => $atts[‘category’],

    The following shortcode seems to be working!
    [product_tag tags=”back-issue” category=”other-publishers” per_page=”-1″ columns=”5″ orderby=”sku” order=”asc”]

    If you think this might in any way break things, please let me know!

    Kind regards,
    JP

    Hi JapeNZ!
    I have same problem, so I want display products from specific category WITH specific tag.

    You wrote:

    I’ve added the following to ‘// Get attributes’
    ‘category’ => ”,
    
    and this to ‘// Default ordering args’
    ‘product_cat’ => $atts[‘category’],

    Please explain exactly where to add this code?

    Thread Starter JapeNZ

    (@japenz)

    Hi @anpeaf,
    I’m actually not using this anymore as it hasn’t been updated for ages.
    Not sure if it’ll still work with the latest Woocommerce, but here’s what I did.

    Go to your plugins folder either through cPanel file manager or via a ftp program such as filezilla and open the file named ss-wc-display-product-tags.php in the woocommerce-display-products-by-tags folder.

    Once there add “‘category’ => ”,” to the get attributes section starting on line 41, so it looks like this:

    // Get attribuets
    $atts = shortcode_atts( array(
    	'per_page' => '12',
    	'columns'  => '4',
    	'orderby'  => 'title',
    	'order'    => 'desc',
            'category' => '',
    	'tags'     => '',  // Slugs
    	'operator' => 'IN' // Possible values are 'IN', 'NOT IN', 'AND'.
    ), $atts );

    and add “‘product_cat’ => $atts[‘category’],” to the default ordering args section starting on line 55, so it looks like this:

    // Default ordering args
    	$ordering_args = $woocommerce->query->get_catalog_ordering_args( $atts['orderby'], $atts['order'] );
    	$meta_query    = $woocommerce->query->get_meta_query();
    
    $args = array(
    	'post_type'				=> 'product',
            'product_cat' => $atts['category'],
    	'post_status' 			=> 'publish',
    	'ignore_sticky_posts'	=> 1,
    	'orderby' 				=> $ordering_args['orderby'],
    	'order' 				=> $ordering_args['order'],
    	'posts_per_page' 		=> $atts['per_page'],
    	'meta_query' 			=> $meta_query,
    	'tax_query' 			=> array(
    			array(
    				'taxonomy' 		=> 'product_tag',
    				'terms' 		=> array_map( 'sanitize_title', explode( ',', $atts['tags'] ) ),
    				'field' 		=> 'slug',
    				'operator' 		=> $atts['operator']
    			)
    		)
    	);

    I’m really not sure this will work with Woocommerce anymore as version 3.3+ has had some substantial change made to it… however there’s always hope 🙂

    Best of luck!

    Kind regards,
    JP

    Hi dear @japenz and @sebd86 !

    @japenz I really thank you so much for your detailed explanation!

    So I can definitely say that this plugin, the same as addition @japenz works fine.
    I think that @sebd86 as a plugin author can safely add @japenz’s add-on to the plugin and update it.
    I am sure that a lot of people want to use this wonderful plugin.
    My configuration:
    Wordpress – 4.9.4
    WOO – 3.3.3

    All works well

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Use tags and categories in same shortcode’ is closed to new replies.