在WooCommerce产品及购物车价格后添加文本说明教程

有的小伙伴在使用WooCommerce建设商城及个人网店的时候,往往需要在价格后面上增加一点标注,但是按WooCommerce的设置限制,不能随便加入说明,其实要在WooCommerce产品和购物车页面的价格后面加上一个字符串,可以使用WooCommerce过滤器 woocommerce_cart_item_price 和 woocommerce_get_price_html。

在WooCommerce产品及购物车价格后添加文本说明教程插图

添加以下代码到你的活动主题 functions.php 文件。

确保用你的文本或HTML代码改变<span class="price-suffix">价格后面的文字</span>。
function banzhuti_custom_html_addon_to_price( $price, $product ) {

// 在价格后添加的自定义html标签

 $html_price_suffix = '<span class="price-suffix"> 价格后面的文字</span>';

 if ( !empty( $price ) ) {
     $price = $price . ' ' . $html_price_suffix;
      return $price;
    } else {
      return $price;
    }
}
add_filter( 'woocommerce_get_price_html', 'banzhuti_custom_html_addon_to_price', 999, 2 );
add_filter( 'woocommerce_cart_item_price', 'banzhuti_custom_html_addon_to_price', 999, 2 );
© 版权声明
THE END
喜欢就支持一下吧
点赞0分享
评论 抢沙发

请登录后发表评论

    暂无评论内容