Woocommerce – Retrieve shipping cost

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

    $args = array(
        'post_type'   => array('product', 'product_variation'),
        'numberposts' => -1,
        'post_status' => 'publish',
    $shop_products = get_posts( $args );
    foreach ($shop_products as $item) {
        echo $item->ID.": shipping class is -> ".$item->get_shipping_class()."<br>";

I need to create a list of product with their own shipping class, but it doesn’t works.
It shows me the error “Call to undefined method WP_Post::get_shipping_class()“.

What is wrong? How can I fix it?

Read more here: Woocommerce – Retrieve shipping cost

Leave a Reply

Your email address will not be published. Required fields are marked *