Exclude related products ids in Woocommerce

前端 未结 1 1688
轮回少年
轮回少年 2020-12-20 04:23
function woocommerce_output_related_products() {

    $args = array(
        \'posts_per_page\' => 4,
        \'columns\'        => 4,
        \'orderby\'              


        
相关标签:
1条回答
  • 2020-12-20 05:12

    Use the woocommerce_related_products filter hook instead, this way:

    add_filter( 'woocommerce_related_products', 'exclude_related_products', 10, 3 );
    function exclude_related_products( $related_posts, $product_id, $args ){
        // HERE set your product IDs to exclude
        $exclude_ids = array('502','281');
    
        return array_diff( $related_posts, $exclude_ids );
    }
    

    Code goes in function.php file of your active child theme (or active theme). Tested and works.

    0 讨论(0)
提交回复
热议问题