[英]Display specific shipping class below "Add to cart" on Woocommerce single products
In Woocommerce I would like to display a specific shipping class, on a single product pages在 Woocommerce 中,我想在单个产品页面上显示特定的运输类别
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?如何在 Woocommerce 单个产品页面上的“添加到购物车”下方显示特定的运输类别?
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).代码位于活动子主题(或活动主题)的 function.php 文件中。 Tested and works.测试和工作。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.