如何解决检查变体项目中产品名称和WooCommerce中允许的国家/地区中的特定字符串
如何添加允许的国家/地区列表和标题中仅包含特定单词的目标产品,而不是版本ID。例如,“裱框A3海报”产品标题中的“裱框”一词。
这意味着我将避免定位每个单独的版本ID,因为我实际上有+280个产品。
下面的代码是我正在使用的代码:
add_action( 'woocommerce_check_cart_items','check_cart_items_for_shipping' );
function check_cart_items_for_shipping() {
$allowed_variation_id = '13021'; // Here defined the allowed Variation ID
$allowed_country = 'IE'; // Here define the allowed shipping country for all variations
$shipping_country = WC()->customer->get_shipping_country();
$countries = WC()->countries->get_countries();
// Loop through cart items
foreach(WC()->cart->get_cart() as $cart_item ) {
// Check cart item for defined product Ids and applied coupon
if( $shipping_country !== $allowed_country && $cart_item['variation_id'] !== $allowed_variation_id ) {
wc_clear_notices(); // Clear all other notices
// Avoid checkout displaying an error notice
wc_add_notice( sprintf( __('The product "%s" can not be shipped to %s.'),$cart_item['data']->get_name(),$countries[$shipping_country]
),'error' );
break; // stop the loop
}
}
}
解决方法
使用protected override void WndProc(ref Message msg)
{
const int WM_SYSCOMMAND = 0x0112;
const int SC_CLOSE = 0xF060;
if (msg.Msg == WM_SYSCOMMAND && ((int)msg.WParam == SC_CLOSE))
{
// click the 'X' button to close the application
Application.Exit();
return;
}
base.WndProc(ref msg);
}
PHP函数将允许在购物车商品名称中找到一个字符串,如下所示(代码句柄也允许多个国家/地区代码):
strpos()
代码进入活动子主题(或活动主题)的functions.php文件中。经过测试,可以正常工作。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。