• Resolved benlau

    (@benlau)


    Hi there,

    very nice plugin!

    But I have a problem with hidden products. I am using a function to hide certain products for users with a certain customer role, using the action “woocommerce_product_query”.

    When ajax is enabled in your plugin and I select a category, for example, the product that should be hidden, are still visible. Only when I reload the page, they are hidden.

    How can I fix this bug? Any ideas? Thanks!!

Viewing 4 replies - 1 through 4 (of 4 total)
  • Hello

    It looks like that in ajax mode this hook does not work.

    Try ‘woocommerce_shortcode_products_query’

    Thread Starter benlau

    (@benlau)

    Hi,

    unfortunately that action doesn’t work either. I have also tried it with

    ‘pre_get_posts’.

    But only after refreshing the page, the action is applied :/

    This is the action:

    add_action( ‘pre_get_posts’, ‘custom_pre_get_posts_query’ );

    function custom_pre_get_posts_query( $q ) {

    if ( ! $q->is_main_query() ) return;
    if ( ! $q->is_post_type_archive() ) return;

    if ( ! is_admin() && is_shop() ) {

    // Get the current user
    $current_user = wp_get_current_user();

    if ( in_array( ‘merchant’, $current_user->roles ) ) {

    $q->set(‘tax_query’, array(array(
    ‘taxonomy’ => ‘pa_benutzerrolle’,
    ‘field’ => ‘term_id’,
    ‘terms’ => array(411) // id of “haendler” attribute
    )));

    } else {

    $q->set(‘tax_query’, array(array(
    ‘taxonomy’ => ‘pa_benutzerrolle’,
    ‘field’ => ‘term_id’,
    ‘terms’ => array(411), // id of “haendler” attribute
    ‘operator’ => ‘NOT IN’
    )));

    }

    }

    remove_action( ‘pre_get_posts’, ‘custom_pre_get_posts_query’ );

    }

    Thread Starter benlau

    (@benlau)

    Is there maybe a specific ajax action or filter in your plugin that I can hook this function to?

    Hello

    Redrawing products in Ajax mode – in file “plugins\woocommerce-products-filter\index.php” function woof_products().

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Hidden products are shown with ajax enabled’ is closed to new replies.