从wooCommerce站点检索目录数据

时间:2014-12-26 10:03:21

标签: woocommerce

我有一个要求,我想要检索wooCommerce网站中的所有产品,并获取与之相关的所有属性,例如产品ID,产品图片网址,产品名称,价格,颜色,不是等等。< / p>

1 个答案:

答案 0 :(得分:0)

使用此代码,您可以检索目录中的所有产品:

$args = array(
    'numberposts'     => -1,
    'orderby'         => 'title',
    'order'           => 'ASC',
    'post_type'       => 'product',
    'post_status'     => 'publish'
);

$products = new WP_Query( $args );

if( $products->have_posts() ) {
    while ( $products->have_posts() ) {
        $products->the_post();
        $_product = new WC_Product( get_the_ID() );
    }
}

根据您想要的信息,您可能需要调用Woocommerce功能才能获得它。

相关问题