douturan1807 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.

  • 写回答

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

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 如果要做一个老年人平板有哪些需求
  • ¥15 k8s生产配置推荐配置及部署方案
  • ¥15 matlab提取运动物体的坐标
  • ¥15 人大金仓下载,有人知道怎么解决吗
  • ¥15 一个小问题,本人刚入门,哪位可以help
  • ¥15 python安卓开发
  • ¥15 使用R语言GD包一直不出结果
  • ¥15 计算机微处理器与接口技术相关问题,求解答图片的这个问题,有多少个端口,端口地址和解答问题的方法和思路,不要AI作答
  • ¥15 如何根据一个截图编写对应的HTML代码
  • ¥15 stm32标准库的PID角度环