简体   繁体   English

在 Woocommerce 单个产品的“添加到购物车”下方显示特定的运输类别

[英]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.

相关问题 在WooCommerce Shopping Cart页面的每个产品下面添加Shipping类 - Add Shipping class below each product in WooCommerce Shopping Cart page WooCommerce 中特定运输类别的购物车消息 - Cart Message for a Specific Shipping Class in WooCommerce 在WooCommerce 3中的特定送货方式下方添加一个复选框 - Add a checkbox below a specific shipping method in WooCommerce 3 向产品添加下拉菜单并在 Woocommerce 购物车上显示价值 - Add dropdown to products and display the value on Woocommerce cart Woocommerce添加到购物车产品仅限4种特定产品 - Woocommerce Add to cart product Restriction to 4 specific products 禁用特定 WooCommerce 产品的添加到购物车按钮 - Disabling Add to Cart Button for Specific WooCommerce Products 基于购物车项目数量的 WooCommerce 中特定运输类别的购物车消息 - Cart Message for a Specific Shipping Class in WooCommerce Based on Number of Cart Items 如果特定产品在 WooCommerce 购物车中,则在购物车页面中显示通知 - Display a notice in cart page if specific products are in WooCommerce cart 如果产品具有特定的运输类别,则向 WooCommerce 购物车项目添加自定义文本 - Add a custom text to WooCommerce cart items if the product has a specific shipping class Ajax 加入购物车 WooCommerce 单品上的简单和可变产品 - Ajax Add to cart for simple and variable products on WooCommerce single products
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM