skip to Main Content

We have a POS system running on woocommerce which we use for instore purchases. This means we have a category for items that we do not sell online. I have a plugin which succesfully hides these categories and associated products from the front end but this does not affect the items display when we use the [recent_products] shortcode for some reason.

I’ve attempted to butcher the shortcode to hide this specific category but the items still show:

[recent_products per_page="4" order="desc" cat_operator="NOT IN" category="instore"]

Is this even possible using the recent product’s shortcode? Am I maybe missing something or is there another way I can display new products and exclude the category ‘instore’ – instore is the category slug, by the way, the full category name is Instore only

Category Slug

This has been troubling me for a while now.

Any suggestions will be most welcome.

Best Regards
Donna

2

Answers


  1. It’s not possible with the recent_products shortcode alone… would need hook into the woocommerce_shortcode_products_query filter with some PHP code. Though I think you can achieve what you want with the products shortcode like this:

    [products limit="4" orderby="id" order="DESC" visibility="visible" cat_operator="NOT IN" category="instore"]
    

    More examples here: https://woocommerce.com/document/woocommerce-shortcodes/#scenario-4-newest-products

    Login or Signup to reply.
  2. Now that you want to hide it from shortcodes, why dont we give this quy a try:

    function dont_show_instore_products( $args, $atts ) {
            $args['tax_query'][] = [
                    'taxonomy' => 'product_cat',
                    'field'    => 'slug',
                    'terms'    => ['instore'],
                    'operator' => 'NOT IN'
                ];
        return $args;
    }
    add_filter( 'woocommerce_shortcode_products_query', 'dont_show_instore_products', 10, 2 );
    

    just add this to your theme’s functions.php right before the ending ?> or if the functions.php doesnt have ?> just add it after the last line and lets see if it does what it should do.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search