Get All Shipping Classes in Woocommerce 3
To get all the shipping classes you just need the following:
$shipping_classes = get_terms( array('taxonomy' => 'product_shipping_class', 'hide_empty' => false ) );
Tested and works. This will give you an array of the WP_Term
objects of all shipping classes.
In Woocommerce the shipping classes are under
product_shipping_class
custom taxonomy.
Or you can use this custom function with a simple SQL query:
function wc_get_shipping_classes(){ global $wpdb; $return $wpdb->get_results( " SELECT * FROM {$wpdb->prefix}terms as t INNER JOIN {$wpdb->prefix}term_taxonomy as tt ON t.term_id = tt.term_id WHERE tt.taxonomy LIKE 'product_shipping_class' " );}
Code goes in function.php file of your active child theme (or active theme).
USAGE (test example):
$shipping_classes = wc_get_shipping_classes(); // Get Shipping Classesecho '<pre>'; print_r($shipping_classes); echo '</pre>'; // Test raw output