To display something above the product page, hook into woocommerce_before_single_product
, and to get the shipping class use the get_shipping_class()
method on the product, which can be retrieved with wc_get_product()
:
function wpse_295878_shipping_banner() {
$product = wc_get_product();
$shipping_class = $product->get_shipping_class();
switch ( $shipping_class ) {
case 'free-shipping':
echo '<div class="woocommerce-info">Free shipping on this item</div>';
break;
case 'flat-rate':
echo '<div class="woocommerce-info">Flat rate shpping $10</div>';
break;
}
}
add_action( 'woocommerce_before_single_product', 'wpse_295878_shipping_banner', 20 );