Woocommerce根据指定国家隐藏指定产品

本文作者: Fengjiajun 评论数量: 0

在下面的示例中,如果当前访问者来自美国,则将隐藏ID为344的产品:

function fjj_hide_product_if_country( $visible, $product_id ){
   $location = WC_Geolocation::geolocate_ip();
   $country = $location['country'];
   if ( $country === "US" && $product_id === 344 ) {
      $visible = false;
   }
   return $visible;
}
add_filter( 'woocommerce_product_is_visible', 'fjj_hide_product_if_country', 9999, 2 );

 


专注 Wordpress Woocommerce 独立站开发&谷歌广告推广 8 年

免费提供WordPress建站以及谷歌广告推广相关咨询服务

This will close in 0 seconds