【发布时间】:2020-01-30 18:00:45
【问题描述】:
我正在使用 WooCommerce 3.6.5。
我需要我的functions.php文件中的所有变量产品,因此我想在我的functions.php文件中使用WC_Product_Query,但它总是返回空数据。但是在 WooCommerce 模板文件 (archive-product.php) 中工作的相同代码并返回正确的数据。
这是我的代码
$query = new WC_Product_Query(array(
'limit'=>-1,
'type' => 'variable',
'return' => 'ids'
));
$variableproducts = $query->get_products();
echo '<pre>';
echo 'print from functions.php';
print_r($variableproducts);
echo '</pre>';
谁能帮助我为什么WC_Product_Query 类在functions.php 中没有返回正确的数据,或者有没有其他方法可以在functions.php 文件中获取所有可变产品ID?
【问题讨论】:
标签: php wordpress woocommerce e-commerce product