New Landing How can we help? General Feedback & Suggestions Hidden Products showing in Shop due to Pagination

Viewing 10 posts - 1 through 10 (of 10 total)
  • #263205
    HB
    Member
    Post count: 76

    Hi Guys,

    We’ve added some PHP to hide certain shop categories ‘Mixed-Cases’ & ‘Howlers’.

    They are hidden on the Shop page but when you use the links to go to the next page they appear again.

    We think it is an issue with AJAX on the Shop.

    Thanks,
    Tim

    #263251
    Kyle – SUPPORT
    Moderator
    Post count: 35880

    Hi

    If you’re using numbered pagination instead of load more, then it will not be an AJAX issue. Please look over your code as there must be a flaw.

    – Kyle

    #263872
    HB
    Member
    Post count: 76

    Hi Kyle,

    Is load more an option we can use with the theme?

    Thanks,
    Tim

    #263887
    Rui Guerreiro – SUPPORT
    Keymaster
    Post count: 25779

    Hi,

    You can use load more only in the blog.

    The only error I found in the javascript console was a not found 404 error in this image
    http://honestbrew.co.uk/wp-content/uploads/Icon-roasted.png

    Double check what exactly that php code is doing.

    -Rui

    #263889
    HB
    Member
    Post count: 76

    Hi Rui,

    The PHP snippet below is removing 2 categories from showing on the shop but when you use pagination it’s not removing the categories.

    Cheers,
    Tim

    ——

    <?php>

    /* Remove categories from shop page
    ==================================================
    */

    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() ) {

    $q->set( ‘tax_query’, array(array(
    ‘taxonomy’ => ‘product_cat’,
    ‘field’ => ‘slug’,
    ‘terms’ => array( ‘howlers’, ‘mixed-case’ ), // Don’t display products in these categories on the shop page
    ‘operator’ => ‘NOT IN’
    )));

    }

    remove_action( ‘pre_get_posts’, ‘custom_pre_get_posts_query’ );

    }

    ——

    #263894
    Rui Guerreiro – SUPPORT
    Keymaster
    Post count: 25779

    hhhum when you move to page 2, 3, etc you are not anymore in the shop page but in an archive page.

    Try to replace this line

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

    with this one

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

    Let me know if it worked.

    -Rui

    #263910
    HB
    Member
    Post count: 76

    Hey Rui,

    Tried that code but no love 🙁

    Cheers,
    T

    #264269
    David Martin – Support
    Moderator
    Post count: 20834

    Could you add some FTP details?

    It looks like you are also removing the action you add also, will need to see your code a little more.

    Thanks.

    #264310
    HB
    Member
    Post count: 76
    This reply has been marked as private.
    #265108
    David Martin – Support
    Moderator
    Post count: 20834

    Hi,

    Why not just do it with CSS?

    Ex, to exclude the product category NZ Craft Beer Collective:

    .post-type-archive li.product-cat-nzcbc {
        display: none;
    }

    Thanks.

Viewing 10 posts - 1 through 10 (of 10 total)

You must be logged in and have valid license to reply to this topic.

License required for one of the following items
Login and Registration Log in · Register