Woocommerce - Retrieve shipping class

前端 未结 1 950
无人共我
无人共我 2021-01-28 09:53

I use following code on external script to retrieve all products (simple and variable):

    $args = array(
        \'post_type\'   => array(\'product\', \'pro         


        
相关标签:
1条回答
  • 2021-01-28 10:14

    I have modified your code. Try following ---

    $args = array(
            'post_type'   => array('product', 'product_variation'),
            'numberposts' => -1,
            'post_status' => 'publish',
        );
        $shop_products = get_posts( $args );
        foreach ($shop_products as $item) {
            $product = wc_get_product($item->ID);
            echo $item->ID.": shipping class is -> ".$product->get_shipping_class()."<br>";
        }
    
    0 讨论(0)
提交回复
热议问题