php - 在 Woocommerce 中的特定国家/地区的购物车和结帐总额后显示文本
问题描述
我需要在价格后的 Woocommerce 订单总数单元格中显示一条消息,但前提是客户的国家/地区是美国或加拿大。我有这个
add_filter( 'woocommerce_cart_totals_order_total_html', 'custom_total_message_html', 10, 1 );
function custom_total_message_html( $value ) {
$value .= __('<small>My text.</small>');
return $value;
}
如果客户的国家/地区是美国或加拿大,我如何才能添加文本?
解决方案
如果您正在使用 Geolocation 函数并有一个 API 密钥,则可以使用WC_Geolocation
该类。
add_filter( 'woocommerce_cart_totals_order_total_html', 'custom_total_message_html', 10, 1 );
function custom_total_message_html( $value ) {
$geolocation = WC_Geolocation::geolocate_ip();
if (in_array($geolocation['country'], array('US', 'CA'))){
$value .= __('<small>My text.</small>');
}
return $value;
}
推荐阅读
- powershell - 人类可读的字节大小的显示如何工作?
- javascript - JS:递归调用promise函数
- python - 如何使用任何分类器对我的数据进行分类,每个数据点由一组浮点值组成?
- ionic-framework - 在socket.on函数ionic 3中调用相机预览插件时应用程序崩溃
- eloquent - 多个嵌套不起作用:我只得到第一个
- php - 取出字符串中的前导零(客户编号输入字段)
- sql - 当我在 SQL 查询中执行联合或某些命令时,我想对列值求和
- python - SQLite Trigger: Update a table after insert is done on another
- angular - 如何在 Angular 6 中以人类可读的方式表示文件大小?
- javascript - 为什么我的变量没有初始化值?