久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

在 Woocommerce 中排除相關產品 ID

Exclude related products ids in Woocommerce(在 Woocommerce 中排除相關產品 ID)
本文介紹了在 Woocommerce 中排除相關產品 ID的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

限時送ChatGPT賬號..
function woocommerce_output_related_products() {

    $args = array(
        'posts_per_page' => 4,
        'columns'        => 4,
        'orderby'        => 'rand', // @codingStandardsIgnoreLine.
        'post__not_in' => array(502,281)
    );

    woocommerce_related_products( apply_filters( 'woocommerce_output_related_products_args', $args ) );
}

我將此函數從 includes/wc-template-functions.php 復制到我的主題的functions.php

I copied this function from includes/wc-template-functions.phpinto my theme's functions.php

為了驗證我的更改是否有效,我將 posts_per_page 更改為 3,它只查詢 3 而不是 4.

To verify that my changes would work I changed the posts_per_page to 3 and it queried only 3 instead of 4.

我需要排除一些產品,但 post__not_in 不起作用.

I need to exclude a few products, but post__not_in is not working.

我做錯了嗎?我還能如何排除使用此功能的產品?

Am I doing something wrong? How else can I exclude products using this function?

我用這個函數輸出產品:woocommerce_output_related_products();

I'm outputting the products with this function: woocommerce_output_related_products();

好討厭的問題.我根本無法從這里排除產品.有人可以幫忙嗎?

such an obnoxious problem. I simply cannot exclude products from here. can anyone help?

我也試過這個:

add_filter( 'woocommerce_output_related_products_args', function( $args ) { 
    $args = wp_parse_args( array(  "post__not_in" => array('502','281') ), $args );
    return $args;
});

我做了 print_r($args) 并且它顯示我的post__not_in"被添加了,但產品仍然存在.我有正確的身份證.

i did print_r($args) and it showed that my "post__not_in" was being added, but the products are still there. I have the right ID.

推薦答案

改用 woocommerce_related_products 過濾器鉤子,這樣:

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 );
}

代碼位于活動子主題(或活動主題)的 function.php 文件中.經測試有效.

這篇關于在 Woocommerce 中排除相關產品 ID的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

相關文檔推薦

Add programmatically a downloadable file to Woocommerce products(以編程方式將可下載文件添加到 Woocommerce 產品)
Get today#39;s total orders count for each product in Woocommerce(獲取今天 Woocommerce 中每種產品的總訂單數)
Add Custom registration fields in WooCommerce and phone field validation issue(在 WooCommerce 和電話字段驗證問題中添加自定義注冊字段)
Add a select field that will change price in Woocommerce simple products(在 Woocommerce 簡單產品中添加一個將更改價格的選擇字段)
Add custom columns to admin products list in WooCommerce 3(在 WooCommerce 3 中將自定義列添加到管理產品列表)
Customizing checkout quot;Place Orderquot; button output html(自定義結帳“下訂單按鈕輸出html)
主站蜘蛛池模板: 久久综合一区 | 狠狠涩| 国产成人久久精品一区二区三区 | 久久午夜电影 | 日韩精品一区二区三区在线观看 | 亚洲另类春色偷拍在线观看 | 亚洲精品免费在线观看 | 极品在线 | 欧美精品在线一区二区三区 | 欧美日韩在线不卡 | 精品久久久久久久久久久 | 久久国产精品久久久久久 | 日韩精品视频在线 | 亚洲欧美久久 | 91久久精品 | 国产一级黄色网 | 欧美在线视频一区 | 久久91精品国产 | 男女羞羞视频在线免费观看 | 日日夜夜天天 | 蜜臀久久99精品久久久久野外 | 玖玖国产精品视频 | 日韩精品 电影一区 亚洲 | 久久伊人亚洲 | 日韩精品一二三 | 在线观看亚洲欧美 | 天堂一区| 中文字幕亚洲一区二区三区 | 国产激情三区 | 蜜臀久久99精品久久久久久宅男 | 国产精品久久久久久福利一牛影视 | 欧美精品网站 | 麻豆久久久9性大片 | 中文日韩在线 | 日韩在线视频一区二区三区 | 婷婷亚洲综合 | 午夜视频一区 | 国产99久久精品 | 日韩精品一区二区三区中文在线 | 精品乱人伦一区二区三区 | 91精品一区二区三区久久久久 |