• Resolved dhrf

    (@dhrf)


    Hi,

    I have show suggested products enabled with type Cross-Sells. Some products don’t have Cross-Sells set and are just pulling in random products to fill in the suggested products. Can I only show suggested products when the Cross-Sells are not empty?

    Thanks.

Viewing 6 replies - 1 through 6 (of 6 total)
  • Thread Starter dhrf

    (@dhrf)

    function xoo_cu_wsc_sp_filter($args){
        $suggested_products = WC()->cart->get_cross_sells();
    
        if(empty($suggested_products)){
            $args['suggested_products'] = array(0);
        }
        return $args;
    }   
    add_filter('xoo_wsc_suggested_product_args','xoo_cu_wsc_sp_filter');

    This seems to work, not sure if it is the best way to handle it though?

    Plugin Author xootix

    (@xootix)

    Hello @dhrf

    That would also work.
    Here is the better version.

    function xoo_cu_wsc_sp_filter($args){
     
        if( empty( $args['suggested_products'] ) ){
            $args['items_count'] = 0;
        }
        return $args;
    }   
    add_filter('xoo_wsc_suggested_product_args','xoo_cu_wsc_sp_filter');
    
    Thread Starter dhrf

    (@dhrf)

    Hi @xootix

    Thanks for your quick reply.

    Unfortunately that code doesn’t seem to work as $args[‘suggested_products’] doesn’t seem to be empty. When cross-sells are empty other products are being added to suggested products instead.

    Plugin Author xootix

    (@xootix)

    Hello @dhrf

    It seems like you cannot ask WP query to return 0 items.
    This should work

    function xoo_cu_wsc_sp_filter($args){
     
        if( empty( $args['suggested_products'] ) ){
           $args['suggested_products'] = array(-1);
        }
        return $args;
    }   
    add_filter('xoo_wsc_suggested_product_args','xoo_cu_wsc_sp_filter');
    Thread Starter dhrf

    (@dhrf)

    Hi @xootix

    That seems to work perfect.

    Thank you!

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Hide suggested products when cross-sells empty’ is closed to new replies.