2018-05-29 20:47
浏览 93

在Woocommerce 3+上通过PHP更改产品可见性

I have a feature on my store that allows me to auto-generate a product quote, after the quote's attributes, prices, and shipping rules, I create a new product on the fly.

I don't want these products to show on my catalogue or searches, so I've been trying to figure out how to update the "Catalog Visibility" to Hidden.

At first I was trying:

update_post_meta( $prod_ID, '_visibility', 'hidden' );

The meta is added, however, looking into it I found out that WooCommerce changed the way it specifies if a product is visible or hidden:: below is from WooCommerce

Product visibility is taxonomy based instead of meta based 3.0.0 introduces a new product visibility taxonomy; catalogue, search, hidden, featured, out of stock are terms. These are set to upgrade and help filter products in the catalogue during frontend queries.

My issue is; how can I modify a taxonomy via PHP.

图片转代码服务由CSDN问答提供 功能建议

我的商店有一项功能,允许我在报价属性,价格后自动生成产品报价 和运输规则,我即时创建一个新产品。

我不希望这些产品显示在我的目录或搜索上,所以我一直试图弄清楚如何 将“目录可见性”更新为隐藏。


  update_post_meta($ prod_ID,'_ visible“,  'hidden'); 

添加了元数据,然而,在调查中我发现WooCommerce改变了它指定产品是否可见或隐藏的方式: :以下是来自WooCommerce

产品可见性是基于分类而非基于元的 3.0.0引入了新的产品可见性分类; 目录,搜索,隐藏,特色,缺货是条款。 这些设置为在前端查询期间升级并帮助过滤目录中的产品。

我的问题是; 如何通过PHP修改分类法。

  • 写回答
  • 好问题 提建议
  • 追加酬金
  • 关注问题
  • 邀请回答

1条回答 默认 最新

  • duanbimo7212 2018-05-30 04:09

    it should be something like this:

    $terms = array( 'exclude-from-search', 'exclude-from-catalog' ); // for hidden..
    wp_set_post_terms( $prod_ID, $terms, 'product_visibility', false );

    you can get the idea here... woocommerce/includes/data-stores/class-wc-product-data-store-cpt.php#L671

    解决 无用
    打赏 举报

相关推荐 更多相似问题