本文介绍了设置目录可见性隐藏woo-commerce的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何以编程方式设置隐藏在 woo-commerce WordPress 中的目录可见性?

How to set Catalog visibility hidden in woo-commerce WordPress programmatically?

就像这里提到的:

https://docs.woothemes.com/document/catalog-visibility-options/

但我找不到任何钩子或黑客,如何在 PHP 中做到这一点.

But i can't find any hook or hack, that how to do it in PHP.

推荐答案

我已经尝试这样做了几天,但网上没有任何相关信息,所以我阅读了 woocommerce 文档并发现在 woocommerce 3.xx 中的可见性是称为product_visibility"的分类法.

I have tried doing this for some days, and there is nothing about it online so I read the woocommerce documentation and discovered that in woocommerce 3.x.x the visibility is a taxonomy called "product_visibility".

要实现这一点,您应该设置分类术语,例如:

To achieve that you should set taxonomy terms, for example:

//Set product hidden: 
$terms = array( 'exclude-from-catalog', 'exclude-from-search' );
wp_set_object_terms( $post_id, $terms, 'product_visibility' );

//Set product visible in catalog:
$terms = 'exclude-from-search';
wp_set_object_terms( $post_id, $terms, 'product_visibility' );

//Set product visible in search:
$terms = 'exclude-from-catalog';
wp_set_object_terms( $post_id, $terms, 'product_visibility' );

所有可能的分类术语:

"exclude-from-catalog"
"exclude-from-search"
"featured"
"outofstock"

这篇关于设置目录可见性隐藏woo-commerce的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-21 21:12