将产品类别类别更改为Hello(WooCommerce问题)

发布于 2025-02-10 19:43:56 字数 190 浏览 0 评论 0原文

  1. 我们在WooCommerce中创建了一种产品。
  2. 然后,我们将类别分配给产品:CAT1,CAT2,CAT3。

几天后,我想启动一个脚本以将类别Cat2更改为所有产品中的Cat4。如何通过这样的php脚本对此进行操作: Run domain.de/start.php将把所有带有类别Cat2的产品更改为CAT4。

  1. We create an product in woocommerce.
  2. Then we assign categories: cat1, cat2, cat3 to product.

After some days i wanna start a script to change category cat2 to cat4 in all products. How do to that via php script like this:
run domain.de/start.php will change all products with category cat2 to cat4.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

笑忘罢 2025-02-17 19:43:56

“ CAT-1”是旧类别,而“ CAT-2”是新的。
测试和工作

if( isset( $_GET['update_cats'] ) && $_GET['update_cats'] =='yes' ){
   add_action("init","change_products_cats");
}
function change_products_cats(){
    $args = array(
    'category' => array( 'cat-1' ),
    );
    $products = wc_get_products( $args );
    foreach ($products as $key => $value) {
        wp_set_object_terms(  $value->id, 'cat-2', 'product_cat' );
    }
}

'cat-1' is old category and 'cat-2' is new.
Tested and working

if( isset( $_GET['update_cats'] ) && $_GET['update_cats'] =='yes' ){
   add_action("init","change_products_cats");
}
function change_products_cats(){
    $args = array(
    'category' => array( 'cat-1' ),
    );
    $products = wc_get_products( $args );
    foreach ($products as $key => $value) {
        wp_set_object_terms(  $value->id, 'cat-2', 'product_cat' );
    }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文