In Woocommerce, I am trying to display a shipping badge which updates based on defined shipping classes.
The problem I have is when I have a variable product with the variants having different classes. I need the badge to update depending on the selection.
For example, when a variable product has a single and carton option and the single has a 10 class and the carton has a bulk1 class I need the badge to update when the carton is selected from the options.
I am not sure how to get the variant shipping class rather than the single product shipping class.
Here is how far I have got:
function rod_shipping_banner() {
if( $product->is_type( 'simple' ) ){
$product = wc_get_product();
$shipping_class = $product->get_shipping_class();
switch ( $shipping_class ) {
case '10':
echo '<div class="woocommerce-info"><a href="/shipping-policy/"target="_blank"><img src="/wp-content/uploads/2019/03/10-shipping-small.gif" alt="$10 Flat Rate"></a></div>';
break;
case 'bulk1':
echo '<div class="woocommerce-info"><a href="/shipping-policy/"target="_blank"><img src="/wp-content/uploads/2019/03/Bulky1.gif"alt="Bulky class 1"></a></div>';
break;
case 'bulk2':
echo '<div class="woocommerce-info"><a href="/shipping-policy/"target="_blank"><img src="wp-content/uploads/2019/03/Bulky_2.gif"alt="Bulky class 2"></a></div>';
break;
}
} elseif( $product->is_type( 'variable' ) ){
$product = wc_get_product();
$shipping_class = $product->get_shipping_class();
switch ( $shipping_class ) {
case '10':
echo '<div class="woocommerce-info"><a href="/shipping-policy/"target="_blank"><img src="/wp-content/uploads/2019/03/10-shipping-small.gif" alt="$10 Flat Rate"></a></div>';
break;
case 'bulk1':
echo '<div class="woocommerce-info"><a href="/shipping-policy/"target="_blank"><img src="/wp-content/uploads/2019/03/Bulky1.gif"alt="Bulky class 1"></a></div>';
break;
case 'bulk2':
echo '<div class="woocommerce-info"><a href="/shipping-policy/"target="_blank"><img src="wp-content/uploads/2019/03/Bulky_2.gif"alt="Bulky class 2"></a></div>';
break;
}
}
}
add_action( 'woocommerce_single_product_summary_price',