购物车和/或结帐页面上的自定义文本

问题描述 投票:0回答:1

有谁知道如何在购物车页面和结账页面中的每个产品下添加自定义文本?我不希望该文本显示在各个产品页面上 - 仅显示在购物车/结帐页面上。每个产品都是一样的,例如“交货时间最长可达 8 周”

谢谢!

我知道代码需要添加到functions.php文件中,但我不知道是什么

php wordpress woocommerce cart
1个回答
0
投票

关于所提供问题中提到的要求,添加自定义文本“交货时间最长可达 8 周”。对于 woocommerce 购物车页面、woocommerce 结帐页面中的每个产品,可以将以下代码放入主题functions.php 文件中。如果 woocommerce 模板文件用于购物车页面、结帐页面,则可以放置以下代码。

add_action('woocommerce_after_cart_item_name', 'custom_woocommerce_after_cart_item_name');
function custom_woocommerce_after_cart_item_name($cart_item)
{
    echo '<br />Lead time can be up to 8 weeks.';
}
add_filter('woocommerce_checkout_cart_item_quantity', 'custom_woocommerce_checkout_cart_item_quantity');
function custom_woocommerce_checkout_cart_item_quantity($cart_item_quantity)
{
    $cart_item_quantity = $cart_item_quantity.'<br />Lead time can be up to 8 weeks.';
    return $cart_item_quantity;
}

如果 woocommerce 块用于购物车页面、结帐页面,则可以放置以下代码。

add_action('wp_footer', 'custom_wp_footer');
function custom_wp_footer()
{
    if(is_cart())
    {
        echo '<style type="text/css">.wc-block-cart-item__product .wc-block-components-product-price:after { content: "Lead time can be up to 8 weeks."; display: block; }</style>';
    }
    else if(is_checkout())
    {
        echo '<style type="text/css">.wc-block-components-order-summary-item__description .wc-block-components-product-price:after { content: "Lead time can be up to 8 weeks."; display: block; }</style>';
    }
}

可以检查此代码是否有效。

© www.soinside.com 2019 - 2024. All rights reserved.