3

I have been trying to figure out how to get the shipping class from the order after payment is complete. I have found this...

$shipping_class = $cart_item['data']->get_shipping_class();

but that retrieves the shipping class from an active cart, I need to get this after the order is processed, possibly from...

$order = new wc_get_order(id);
$items = $order->get_items();

I can then get the product and variation ids but for some reason I am not seeing how to get the shipping class from this.

any help on this would be greatly appreciated!

1 Answer 1

10

Palm to FACE!!!

using the product id...

$_product = get_product(id);

$_product = wc_get_product()

$shipclass = $_product->get_shipping_class();

this returns the products shipping class.

EDIT: as mentioned by Aniruddha get_product is depreciated answer has been updated.

3
  • get_product() function is deprecated. use wc_get_product() instead. Jul 22, 2017 at 13:48
  • Doh yes correct, double palm Saturday. Thank you for that!!!
    – phlipinmi
    Jul 22, 2017 at 14:44
  • what about for product variations -- if you need to get the shipping_class foreach individual product variation
    – RobBenz
    Feb 27, 2018 at 19:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.