亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

更改 WooCommerce 3+ 中現有產品的產品類型

更改 WooCommerce 3+ 中現有產品的產品類型

PHP
烙印99 2023-07-15 10:24:44
我需要在創建后使用我的子主題中的功能更改 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();

查看完整回答
反對 回復 2023-07-15
  • 1 回答
  • 0 關注
  • 152 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號