我嘗試獲取分組產品的類型,但如果我使用WC_Product_Factory,woocommerce將返回空或始終「簡單」。wordpress返回woocommerce總是很簡單,因爲產品類型
當我使用:
$the_product = new WC_Product(2886);
echo $the_product->product_type;
返回空。
當我使用WC_Product_Factory:
總是返回 「簡單」
我嘗試使用:
$the_product = wc_get_product(2886);
echo $the_product->product_type;
但這返回一個錯誤「調用一個成員函數get_product( )在非對象中...「
我的代碼位於:
add_action('plugins_loaded', function(){
$the_product = new WC_Product(2886);
echo $the_product->product_type;
$the_product = new WC_Product(2886);
$the_product_factory = new WC_Product_Factory();
$the_product = $the_product_factory->get_product($the_product);
echo $the_product->product_type;
$the_product = wc_get_product(2886);
echo $the_product->product_type;
die();
});
恩,謝謝你的幫忙!
這救了我的天.. – mthama 2017-02-16 00:19:09