• Resolved Jamie Gill

    (@patchgill)


    Hi There,

    Quick question I have a few products that have discontinued so I have marked them as private so no one can order these.

    However we hold back around 20 for replacements on any damaged ones during transit. If this happens I manually create an order and ship one of these orders, only problem is as the product is private I cannot add it as a line item to the order anymore.

    Is there a hook to accomplish this so the add items in the order area also include private products?

    Cheers
    J

Viewing 2 replies - 1 through 2 (of 2 total)
  • mdshak

    (@mdshak)

    Just make a product category named private and assign all private products under this category. Now use this code at functions.php of theme.

    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( 'private' ),
    'operator' => 'NOT IN'
    )));
    
    }
    
    remove_action( 'pre_get_posts', 'custom_pre_get_posts_query' );
    
    }

    This code remove private products from the shop page and search results. You can add these products as order item line.

    Caleb Burks

    (@icaleb)

    Automattic Happiness Engineer

    Alternatively, instead of “private” you could do “hidden”. There should then be no actual link to the product, and won’t find it unless you type in the exact URL.

    So could even just set to hidden when you need to make an order, then back to private after if you want.

Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘Private Visibility’ is closed to new replies.