In Woocommerce I would like to display a specific shipping class, on a single product pages
For Example: If a product has a "Pickup Only" shipping class, I'd like that to be visible just below the "Add to Cart" button (all other classes do not need to be displayed).
How can I display specific shipping class below "Add to cart" on Woocommerce single product pages?
Updated - The following code will display the shipping class name, in single product pages, below add to cart button, only when it is "Pickup Only":
// On single product pages
add_action('woocommerce_single_product_summary','display_specific_shipping_class', 35 );
function display_specific_shipping_class(){
global $product;
// HERE define your targeted shipping class name
$defined_shipping_class = "Pickup Only";
$product_shipping_class = $product->get_shipping_class();
// Get the product shipping class term name
$term_name = get_term_by( 'slug', $product_shipping_class, 'product_shipping_class' )->name;
if( $term_name == $defined_shipping_class ){
echo '<p class="product-shipping-class">' . $term_name . '</p>';
}
}
Code goes in function.php file of your active child theme (or active theme). Tested and works.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.