Your question should be specific to WordPress. Generic PHP/JS/SQL/HTML/CSS questions might be better asked at Stack Overflow or another appropriate Stack Exchange network site. Third-party plugins and themes are off-topic for this site; they are better asked about at their developers' support routes.
Closed 7 years ago.
Improve this questionWe have multiple shipping classes, and based on each of the shipping classes we would like to display banner/text on the product page.
For example, in a case of free shipping, we would like to display something like "Free shipping on this item". And in a case of "flat Rate" - "Flat rate shipping $10", etc.
I was wondering if there is a plugin or a code that i could include in the functions.php to achieve this.
Thanks!
Closed. This question is off-topic. It is not currently accepting answers.Your question should be specific to WordPress. Generic PHP/JS/SQL/HTML/CSS questions might be better asked at Stack Overflow or another appropriate Stack Exchange network site. Third-party plugins and themes are off-topic for this site; they are better asked about at their developers' support routes.
Closed 7 years ago.
Improve this questionWe have multiple shipping classes, and based on each of the shipping classes we would like to display banner/text on the product page.
For example, in a case of free shipping, we would like to display something like "Free shipping on this item". And in a case of "flat Rate" - "Flat rate shipping $10", etc.
I was wondering if there is a plugin or a code that i could include in the functions.php to achieve this.
Thanks!
Share Improve this question edited Mar 5, 2020 at 11:27 harvey 2151 gold badge4 silver badges13 bronze badges asked Mar 5, 2018 at 23:39 DSinghDSingh 311 silver badge2 bronze badges 1- Just tried to search for a code on internet. So far no luck. – DSingh Commented Mar 7, 2018 at 0:55
1 Answer
Reset to default 2To 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 );