我需要在創建后使用我的子主題中的功能更改 woocommerce 產品類型,我已經嘗試過以下操作: wp_set_object_terms($product_id, 'variable', 'product_type', true);我的方法在創建后觸發但類型仍然不變?
1 回答

元芳怎么了
TA貢獻1798條經驗 獲得超7個贊
從 WooCommerce 3 開始,要更改現有產品的產品類型,您可以使用以下命令:
/**
?* Change product type.
?*
?* @param int? ? ?$product_id? ? ? ?- The product id.
?* @param string? $new_product_type - The new product type
?*/
?
// Get the correct product classname from the new product type
$product_classname = WC_Product_Factory::get_product_classname( $product_id, $new_product_type );
// Get the new product object from the correct classname
$new_product? ? ? ?= new $product_classname( $product_id );
// Save product to database and sync caches
$new_product->save();
- 1 回答
- 0 關注
- 152 瀏覽
添加回答
舉報
0/150
提交
取消