I am trying to display the shipping class name and the shipping flat rate for the product on WooCommerce single product page. I have used the code below:
$shipping_class_id = $product->get_shipping_class_id();
$shipping_class= $product->get_shipping_class();
$fee = 0;
if ($shipping_class_id) {
$flat_rates = get_option("woocommerce_flat_rates");
$fee = $flat_rates[$shipping_class]['cost'];
}
$flat_rate_settings = get_option("woocommerce_flat_rate_settings");
echo 'Shipping cost: ' . ($flat_rate_settings['cost_per_order'] + $fee);
I can get the shipping class id and also the shipping class slug with this code but not the label. I can not also get the cost of that particular shipping class which is a flat rate of 5 Euro as defined in shipping zones section.
Looking forward to your replies.