【发布时间】:2021-02-04 15:34:43
【问题描述】:
我试图通过重命名下面的默认消息来解决一个问题,当没有可用的运输方法时,无论是由基于规则的插件设置还是在 WooCommerce 中根本没有设置任何方法。
No shipping method has been selected. Please double check your address, or contact us if you need any help.
我通过 sn-ps 插件使用了以下功能,我可以确认它会更改购物车中的消息并在运输标签下方结帐。
但是,如果有人随后尝试结帐,他们会在屏幕顶部收到一条红色的 WooCommerce 错误消息,这仍然是上面的默认消息。
如何更改此错误消息?我想将其更改为与下面代码显示的内容不同的内容,以便我可以灵活地在购物车总计框中放置一条短消息,并提供一条更长的信息性消息,说明为什么没有可用的方法。
我的功能:
add_filter( 'woocommerce_cart_no_shipping_available_html', 'no_shipping_available_html' );
add_filter( 'woocommerce_no_shipping_available_html', 'no_shipping_available_html' );
function no_shipping_available_html( $message ) {
$country = WC()->customer->get_shipping_country();
if ( !empty( $country ) ) {
$all_countries = WC()->countries->get_countries();
return sprintf( 'Orders delivered into the EU are limited to €150 (inc shipping) or a max weight of 2kg. The items in you cart exceed this limit. Please remove an item or reduce the quantity required to bring the order value/weight within the permitted values.', $all_countries[ $country ] );
}
return 'Orders delivered into the EU are limited to €150 (inc shipping) or a max weight of 2kg. The items in you cart exceed this limit. Please remove an item or reduce the quantity required to bring the order value/weight within the permitted values.';
}
【问题讨论】:
标签: php wordpress woocommerce checkout gettext