• Resolved poniel

    (@poniel)


    Hello There

    So I used code snippets to remove a particular category from my shop page. It worked a treat but now im trying to use the same code to remove another different category from the shop page and no matter how i put it I get fatal errors and syntax errors. The code I used is this. the first time i literally just changed clothing in the brackets to the category i wanted to remove. it worked but the second time i tried with a different category it just never works. would really appreciatte some help please.

    /**
    * Exclude products from a particular category on the shop page
    */
    function custom_pre_get_posts_query( $q ) {

    $tax_query = (array) $q->get( ‘tax_query’ );

    $tax_query[] = array(
    ‘taxonomy’ => ‘product_cat’,
    ‘field’ => ‘slug’,
    ‘terms’ => array( ‘clothing’ ), // Don’t display products in the clothing category on the shop page.
    ‘operator’ => ‘NOT IN’
    );

    $q->set( ‘tax_query’, $tax_query );

    }
    add_action( ‘woocommerce_product_query’, ‘custom_pre_get_posts_query’ );

    The page I need help with: [log in to see the link]

Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)

The topic ‘Need help with in abilty to do simple code using snippets’ is closed to new replies.