- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
-6ren">
我目前正在 woocommerce/cart/cart-shipping.php
中添加以下代码,以更改不在 WooCommerce 送货国家列表中的国家/地区的无送货方式消息。
<?php
add_filter( 'woocommerce_cart_no_shipping_available_html', 'custom_no_shipping_available_html' );
add_filter( 'woocommerce_no_shipping_available_html', 'custom_no_shipping_available_html' );
function custom_no_shipping_available_html( $message ) {
$country = WC()->customer->get_shipping_country();
if ( !empty( $country ) ) {
$all_countries = WC()->countries->get_countries();
return sprintf( "Unfortunately, we don't ship to %s. Please contact our Support if you need any help.", $all_countries[ $country ] );
}
return sprintf( "Unfortunately, we don't ship to this location. Please contact our Support if you need any help.", $all_countries[ $country ] );
}
?>
在这段代码之后,cart-shipping.php
中的默认代码是:
$formatted_destination = isset($formatted_destination) ? $formatted_destination : WC()->countries->get_formatted_address($package['destination'], ', ');
$has_calculated_shipping = !empty($has_calculated_shipping);
$show_shipping_calculator = !empty($show_shipping_calculator);
$calculator_text = '';
?>
<tr class="woocommerce-shipping-totals shipping">
<th><?php echo wp_kses_post($package_name); ?></th>
<td data-title="<?php echo esc_attr($package_name); ?>">
<?php if ($available_methods) : ?>
<ul id="shipping_method" class="woocommerce-shipping-methods">
<?php foreach ($available_methods as $method) : ?>
<li>
<?php
if (1 < count($available_methods)) {
printf('<input type="radio" name="shipping_method[%1$d]" data-index="%1$d" id="shipping_method_%1$d_%2$s" value="%3$s" class="shipping_method" %4$s />', $index, esc_attr(sanitize_title($method->id)), esc_attr($method->id), checked($method->id, $chosen_method, false)); // WPCS: XSS ok.
} else {
printf('<input type="hidden" name="shipping_method[%1$d]" data-index="%1$d" id="shipping_method_%1$d_%2$s" value="%3$s" class="shipping_method" />', $index, esc_attr(sanitize_title($method->id)), esc_attr($method->id)); // WPCS: XSS ok.
}
printf('<label for="shipping_method_%1$s_%2$s">%3$s</label>', $index, esc_attr(sanitize_title($method->id)), wc_cart_totals_shipping_method_label($method)); // WPCS: XSS ok.
do_action('woocommerce_after_shipping_rate', $method, $index);
?>
</li>
<?php endforeach; ?>
</ul>
<?php if (is_cart()) : ?>
<p class="woocommerce-shipping-destination">
<?php
if ($formatted_destination) {
// Translators: $s shipping destination.
printf(esc_html__('Shipping to %s.', 'woocommerce') . ' ', '<strong>' . esc_html($formatted_destination) . '</strong>');
$calculator_text = esc_html__('Change address', 'woocommerce');
} else {
echo wp_kses_post(apply_filters('woocommerce_shipping_estimate_html', __('Shipping options will be updated during checkout.', 'woocommerce')));
}
?>
</p>
<?php endif; ?>
<?php
elseif (!$has_calculated_shipping || !$formatted_destination) :
if (is_cart() && 'no' === get_option('woocommerce_enable_shipping_calc')) {
echo wp_kses_post(apply_filters('woocommerce_shipping_not_enabled_on_cart_html', __('Shipping costs are calculated during checkout.', 'woocommerce')));
} else {
echo wp_kses_post(apply_filters('woocommerce_shipping_may_be_available_html', __('Enter your address to view shipping options.', 'woocommerce')));
}
elseif (!is_cart()) :
echo wp_kses_post(apply_filters('woocommerce_no_shipping_available_html', __('There are no shipping options available. Please ensure that your address has been entered correctly, or Please contact our Support if you need any help.', 'woocommerce')));
else :
// Translators: $s shipping destination.
echo wp_kses_post(apply_filters('woocommerce_cart_no_shipping_available_html', sprintf(esc_html__('No shipping options were found for %s.', 'woocommerce') . ' ', '<strong>' . esc_html($formatted_destination) . '</strong>')));
$calculator_text = esc_html__('Enter a different address', 'woocommerce');
endif;
?>
<?php if ($show_package_details) : ?>
<?php echo '<p class="woocommerce-shipping-contents"><small>' . esc_html($package_details) . '</small></p>'; ?>
<?php endif; ?>
<?php if ($show_shipping_calculator) : ?>
<?php woocommerce_shipping_calculator($calculator_text); ?>
<?php endif; ?>
</td>
</tr>
但问题是我必须填写所有帐单地址字段,包括电话和邮政编码,才能收到不支持所选国家/地区的消息。
我认为发生这种情况是因为默认情况下 WooCommerce 正在检查同一 PHP 文件中设置的 $formatted_destination
变量。
我的问题是一旦选择了国家并且它不属于运送国家的一部分,我如何才能以直接显示的方式显示消息?
最佳答案
要回答您的问题,请先进行一些解释。我从 templates/cart/cart-shipping.php 复制了一段代码第 66 - 72 行@version 3.6.0
elseif ( ! is_cart() ) :
echo wp_kses_post( apply_filters( 'woocommerce_no_shipping_available_html', __( 'There are no shipping options available. Please ensure that your address has been entered correctly, or contact us if you need any help.', 'woocommerce' ) ) );
else :
// Translators: $s shipping destination.
echo wp_kses_post( apply_filters( 'woocommerce_cart_no_shipping_available_html', sprintf( esc_html__( 'No shipping options were found for %s.', 'woocommerce' ) . ' ', '<strong>' . esc_html( $formatted_destination ) . '</strong>' ) ) );
$calculator_text = esc_html__( 'Enter a different address', 'woocommerce' );
endif;
如您所见,它包含 2 个过滤器 Hook ,即:
woocommerce_no_shipping_available_html
woocommerce_cart_no_shipping_available_html
虽然第二个钩子(Hook)在消息中显示了 $formatted_destination
,但第一个钩子(Hook)没有。
所以要回答你的问题,你可以像这样使用钩子(Hook):
显示在购物车页面上的消息
function filter_woocommerce_cart_no_shipping_available_html( $sprintf ) {
// Get packages
$packages = WC()->shipping()->get_packages();
// Loop through
foreach ( $packages as $i => $package ) {
$formatted_destination = WC()->countries->get_formatted_address( $package['destination'], ', ' );
}
// Message
$sprintf = sprintf( esc_html__( 'Unfortunately, we don\'t ship to %s. Please contact our Support if you need any help.', 'woocommerce' ) . ' ', '<strong>' . esc_html( $formatted_destination ) . '</strong>' );
return $sprintf;
}
add_filter( 'woocommerce_cart_no_shipping_available_html', 'filter_woocommerce_cart_no_shipping_available_html', 10, 1 );
显示在结帐页面上的消息
function filter_woocommerce_no_shipping_available_html( $html ) {
// Message
$html = __( 'My new message', 'woocommerce' )
return $html;
}
add_filter( 'woocommerce_no_shipping_available_html', 'filter_woocommerce_no_shipping_available_html', 10, 1 );
对于这两个答案,无需修改/覆盖模板文件,代码进入事件子主题(或事件主题)的 functions.php
文件。
关于wordpress - 根据选定的可用送货国家/地区更改 "no shipping available"消息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/69368716/
我正在使用下面的代码但收到警告, bool versionSupports = (@available(iOS 10, *)); @available does not guard availabil
我需要检查 Xamarin.iOS 中的 API 可用性 - 在 Objective-C 或 Swift 中我可以使用这些调用: if (@available(iOS 13, *)) 或 if #av
我遇到了一个我似乎不明白的奇怪问题。我正在制作一个从文件中读取数据的程序。但是当我读取数据时,我立即收到 EOFException。 所以我用 .available() 检查文件是否为空。我得到了一个
Swift 2.0 允许使用 @available 或 #available 进行可用性检查,但是使用 @available 和 有什么区别#可用? 最佳答案 您可以使用 if #available
我刚刚开始学习 angularjs 我尝试了这段代码:在文件 angularmy.js var myname = angular.module("myModule",[]); myname.contr
我有一个 USB 麦克风和扬声器适配器连接到 raspberry pi 3。我已经在 alsamixer 上设置了所有内容。我也设置了pcm.!default sysdefault:0在文件中 .as
import requests import time import csv import ast import sys import mysql.connector config = { 'user
我想让页脚的宽度与浏览器无关。 对于 Mozilla,我想使用 -moz-available 的值,当用户使用 Opera 时,那么 CSS 应该从 -webkit-fill-available 中获
如果您的代码需要仅在 macOS 10.12 或更高版本中可用的功能,但您希望您的代码也部署到更早的系统版本,您可以使用 @available在 Objective-C 中: if (@availab
我正在使用 Element Query允许在任何元素上使用 @media queries 的元素。这是它的处理方式: #foo:media(min-available-width:350px and
我正在尝试安装 oracle 19c,但在安装过程中遇到了与内存相关的问题“[INS-35179] 当前可用内存小于创建数据库所需的可用内存 (6,537MB)”。我仔细检查了所有先决条件,例如超过
我正在编写代码以使用此页面中的文档跟踪现场请求:http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/using-spot-instances-bid-
我仔细阅读了 Kubernetes 文档 here关于扩展 imagefs.available 的默认 15%和其他参数,但没有说明如何设置,我已经安装了具有以下配置的 RKE(Rancher Kub
我想进入PAPI。我在Debian GNU/Linux上有5.3.2.0版。 papi_avail告诉我没有可用的硬件事件: $ papi_avail Available events and har
我目前正在构建一个混合云解决方案,需要将消息写入队列以供稍后处理。队列具有高可用性(99.999+% 的正常运行时间)是绝对必要的。 我的选择是将消息读/写到本地 ZeroMQ 高可用性对或 Azur
在 Mac OS X Leopard 中使用 Eclipse Helios 并调试调用 fsf gdb 7.1 的 C++ 代码,调试停止在 main 的第一行。然后在第一步之后我得到 No sour
无论如何,是否可以将 UIWebView 与针对 tvos 的应用程序一起使用?这个苹果文档,UIWebView Class Reference ,会建议否则不是吗?或者我只是解释错了? UIWebV
我想删除以下数据框中的“不可用”,但是当我使用以下代码将 Number 更改为数字时,“不可用”变为 4: c1 data 是一个 factor 列。 当您将一个因子直接转换为numeric 时,生成
PushKit 在 iOS 11 中提供了一种新方法,旨在取代 iOS 10 中的方法。 使用 iOS 11 作为基础 SDK 构建时无法使用 iOS 10 方法(我当前使用的是 Xcode 9.2B
不确定使用@rename 指令的所有方法。 我正在尝试重命名一个方法 @available(*, deprecated, renamed: "setValueInTable") public func
我是一名优秀的程序员,十分优秀!