我正在使用WooCommerce Composite产品扩展名使用WooCommerce(这使您可以通过其他产品组合制作产品)。
我试图找出复合产品是否为"库存",但是通常的功能IS_IN_STOCK()在复合材料上不起作用。
如果有一个更合适的功能,我想知道它是什么。
替代,下面的函数'wc_get_product()返回以下,包括componentProductID(agissed_ids):
$product = wc_get_product($productid);
var_dump($product);
返回:
object(WC_Product_Composite)#11305 (23) {
["extended_data":"WC_Product_Composite":private]=>
array(7) {
["add_to_cart_form_location"]=>
string(7) "default"
["shop_price_calc"]=>
string(7) "default"
}
["composite_meta":"WC_Product_Composite":private]=>
array(4) {
[1477435352]=>
array(19) {
["component_id"]=>
string(10) "1477435352"
["query_type"]=>
string(11) "product_ids"
["assigned_ids"]=>
array(2) {
[0]=>
int(541)
[1]=>
int(588)
}
}
}
基本上,我想要的是通过'apanded_ids'子阵列进行提取和循环检查是否有库存,但是除了将其打印到屏幕外,我无法访问此对象的属性,因为它们是"私有"(我完全不熟悉的东西)。我相信我可以通过在WordPress/插件文件中搜索类来弄清楚这一点,但我不知道如何找到它。任何帮助将不胜感激。
Stock (复合产品的复杂得多):
关于复合产品中的库存和库存管理,显然有
WC_CP_Stock_Manager
和WC_CP_Stock_Manager_Item
专用类,因此,它似乎并不以>'的某些概念的方式以经典的方式工作。和'collections&quot" 。
includes/class-wc-cp-stock-manager.php
Core Files中可用此方法和功能。
访问数据:
您可以看到,要获取WC_Product_Composite
对象受保护的属性,您应该需要使用核心代码类中记录的WC_Product
方法或更具体的WC_Product_Composite
方法。
现在,最简单的方法访问(未保护)数据是使用以下方法从WC_Data
类class :
// Get an instance of the WC_Product_Composite object
$product = wc_get_product( $product_id );
// Get the data in an unprotected array
$product_data = $product->get_data();
// Output the raw data (for test)
echo '<pre>'; print_r( $product_data ); echo '</pre>';
// Get special meta data in an unprotected array (if it exist)
$product_meta_data = $product->get_meta_data();
// Output the raw special meta data (for test)
echo '<pre>'; print_r( $product_meta_data ); echo '</pre>';
或者您还可以使用一些WC_Product_Composite
方法为:
// Get an instance of the WC_Product_Composite object
$product = wc_get_product( $product_id );
// Get the component Id
$component_data = $product->get_component_id();
// Get the component
$component_data = $product->get_component();
// Get the raw component data
$component_data = $product->get_component_data();
您需要以任何方式进入核心文件代码,以了解事物的工作原理并获取合适的复合产品的方法。