php - Woocommerce中基于地理位置的可变产品目录模式
问题描述
我正在尝试为除澳大利亚以外的任何地方的用户启用 WooCommerce 商店的目录模式。
本店有2种产品
- 简单的
- 多变的
我试过“将 Woocommerce 商店变成地理定位国家的目录? ”答案代码,它适用于“简单”产品
问题是可变产品仍然显示数量字段并添加到购物车按钮,尽管它们不可购买。
我的理解是目录模式本质上是使产品无法购买。
如果我可以通知代码使用类似的东西来查找产品类型“变量”,那么$product->is_type( 'variable' )
它可以适用于两种类型的产品。
我试过这个显然没有用。该函数很可能不能接受多个变量:
//Disable purchasing of products if the country is not Australia
add_filter('woocommerce_is_purchasable', 'purchasable_country_based', 10, 2);
function purchasable_country_based( $is_purchasable, $product, $product->is_type( 'variable' ) ) {
// Enable for "AU" only geolocated users country
if( get_geolocated_user_country() ==='AU' )
return true;
else
return false;
}
所以我想我可以添加另一个代码实例,但这次是针对可变产品。我尝试了以下方法,但也没有用:
//Disable variable products if the country is not Australia
add_filter('woocommerce_is_purchasable', 'purchasable_country_based', 10, 2);
function purchasable_country_based( $is_purchasable, $product->is_type( 'variable' ) ) {
// Enable for "AU" only geolocated users country
if( get_geolocated_user_country() ==='AU' )
return true;
else
return false;
}
解决方案
推荐阅读
- javascript - 存储最后一个值并比较异步函数的变化?
- css - Bootstrap 4卡,扩展最后一个卡页脚以填充空间
- css - 如何让 css 文件反映 xampp 上 localhost 中的任何更新?
- javascript - RoR 和 json:按钮单击和更新计数不刷新
- php - 带有 XDebug 和 PHP Debug 扩展以及 IISExpress 的 VSCode 和 PHP
- javascript - 如何在Javascript中声明具有不同名称的对象?
- .net - 负载均衡场景下AppDomain便捷信息丢失
- javascript - 如何在模板标签(或组件)中包含 javascript
- react-native - 在 react-native 中集成 Paytm All in One SDK
- php - 修改 Laravel 模型响应以使用不同的 ID