• Resolved fabiensen

    (@fabiensen)


    the following hook

    function custom_pre_get_posts_query( $q ) {
    
    $tempAddress = $_COOKIE["tempAddress"];
    $categories_to_exclude = array();
    
    if (strpos($tempAddress, 'New York') !== FALSE)
        {
            //categories_to_exclude;
            //$q->set(); 
        }
    
    else
        {
            $args = apply_filters('woocommerce_related_products_args', 
            array(
                'post_type'             => 'product',
                'post_status'           => 'publish',
                'meta_query'            => array(
                     array(
                        'key'           => '_visibility',
                        'value'         => array('catalog', 'visible'),
                        'compare'       => 'IN'
                    ),
                ),
                'tax_query'            => array(
                    array(
                        'taxonomy' => 'product_cat',
                        'field'    => 'term_id', // Or 'name' or 'term_id'
                        'terms'    => array(51,52,53),
                        'operator' => 'NOT IN', // Excluded
                    )
                )
            ) 
        );
        
        $q->set( 'tax_query', $args ); 
    }}
    
    add_action( 'woocommerce_product_query', 'custom_pre_get_posts_query' );

    helps us remove the products of certain categories in WooCommerce. However, when the theme has Elementor products tab on a certain page (for example the home page), the hook is not applied.

    Any idea?

    Thank you very much!

Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
  • The topic ‘woocommerce_product_query hook with Elementor products tab’ is closed to new replies.