Woocommerce结帐页面中的自定义统一费率说明文本 [英] Custom Flat Rate Description Text in Woocommerce checkout page
问题描述
我在运输区域内设置了两种统一费率运输方法。结帐时可以使用这两种送货方式。
I have two flat rate shipping methods set up within Shipping Zones. At the checkout both of these shipping methods are available.
我想在每个固定费用送货选项下显示文字说明。在WooCommerce中似乎没有任何选择可以做到这一点。
I'd like to display a text description under each flat rate shipping option. There doesn't seem to be any options to do this in WooCommerce.
我尝试了以下代码,但不用说它不起作用:
I have tried the following code but needless to say it doesn't work:
add_filter( 'woocommerce_page_title', 'woo_shop_page_title');
function wc_get_shipping_zone( $package ) {
if( $package == 'flat_rate:1') {
return "<p>Arriving on your chosen date between 9am - 1pm Perfect for business addresses & special occasions</p>";
}
if( $package == 'flat_rate:2') {
return "<p>Arriving on your chosen date between 9am - 7pm Perfect for residential addresses</p>";
}
}
有人可以帮助完成这项工作吗?
Could anyone help to make this work?
这是我希望在结帐时显示的说明:
This is what I would like the description to look like in the checkout:
推荐答案
向运输固定费率方法添加其他信息的正确的钩子函数是:
The correct hooked function to add additional information to your shipping "flat rate" methods is:
add_action( 'woocommerce_after_shipping_rate', 'action_after_shipping_rate', 20, 2 );
function action_after_shipping_rate ( $method, $index ) {
// Targeting checkout page only:
if( is_cart() ) return; // Exit on cart page
if( 'flat_rate:1' === $method->id ) {
echo __("<p>Arriving on your chosen date between 9am - 1pm Perfect for business addresses & special occasions</p>");
}
if( 'flat_rate:2' === $method->id ) {
echo __("<p>Arriving on your chosen date between 9am - 7pm Perfect for residential addresses</p>");
}
}
此代码在您活动的function.php文件中进行子主题(或活动主题)。经过测试并可以正常工作。
This code goes on function.php file of your active child theme (or active theme). tested and works.
这篇关于Woocommerce结帐页面中的自定义统一费率说明文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!