久久久久久久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久久精品一区二区 | 中文字幕一区二区三区乱码图片 | 97久久久久久久久 | 国产激情在线观看视频 | 免费久久久 | 欧美成视频 | 夜夜艹| 在线播放国产一区二区三区 | 一本一道久久a久久精品蜜桃 | 国产精品欧美日韩 | 欧美日韩不卡合集视频 | 午夜电影在线播放 | a级片在线| 中文字幕在线免费观看 | 一区二区三区在线免费观看 | 国产成人一区二区 | 四虎影院在线观看av | 欧美xxxx在线 | 在线视频 中文字幕 | 精品国产一区二区三区在线观看 | 亚洲一区二区三区在线视频 | 日韩精品一区二区三区免费视频 | 狠狠做深爱婷婷综合一区 | 久久aⅴ乱码一区二区三区 91综合网 | 色噜噜狠狠色综合中国 | 在线观看成人免费视频 | 一级在线免费观看 | 免费小视频在线观看 | 青青草综合| 在线播放精品视频 | 成人黄色在线 | aaaaaa大片免费看最大的 | 国产在线观看 | 一区二区三区四区在线 | 成人高清视频在线观看 | 亚洲一区二区三区国产 | 孰女乱色一区二区三区 | 夜夜久久 | 国产在线播放一区二区三区 | 在线高清免费观看视频 |