Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/226.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 在Woocommerce中添加除特定国家/地区之外的内联CSS_Php_Css_Wordpress_Woocommerce_Geolocation - Fatal编程技术网

Php 在Woocommerce中添加除特定国家/地区之外的内联CSS

Php 在Woocommerce中添加除特定国家/地区之外的内联CSS,php,css,wordpress,woocommerce,geolocation,Php,Css,Wordpress,Woocommerce,Geolocation,如果国家不是法国,我想在我的woocommerce网站中添加css样式,因为我需要在除法国以外的所有国家隐藏一个按钮。我试过下面的代码 add_filter( 'woocommerce_state_FR' , 'custom_css_countries', 10, 1 ); function custom_css_countries($mycss) { $country = array('FR'); if( ! in_array( $country ) ){ echo '<

如果国家不是法国,我想在我的woocommerce网站中添加css样式,因为我需要在除法国以外的所有国家隐藏一个按钮。我试过下面的代码

add_filter( 'woocommerce_state_FR' , 'custom_css_countries', 10, 1 );
function custom_css_countries($mycss) {
  $country = array('FR');
  if( ! in_array( $country ) ){
    echo '<style>#payez-sur-12-mois{display:none;}</style>';
  }
  return $mycss;
}
add_filter('woocommerce_state_FR','custom_css_countries',10,1);
功能自定义国家/地区($mycss){
$country=数组('FR');
如果(!in_数组($country)){
echo“#payez-sur-12-mois{display:none;}”;
}
返回$mycss;
}

您实际上不需要为此使用WC\U地理定位类。相反,您可以使用
WC\u Customer
类,该类已经在以下挂钩函数中使用了
WC\u Countries
WC\u Geolocation
类:

add_action( 'wp_head' , 'custom_inline_css', 200 );
function custom_inline_css() {
    // For all countries except 'FR'
    if( WC()->customer->get_billing_country() !== 'FR'  )
        ?><style>#payez-sur-12-mois{display:none !important;}</style><?php
}
add_action('wp_head','custom_inline_css',200);
函数自定义_内联_css(){
//适用于除“FR”以外的所有国家/地区
如果(WC()->customer->get_billing_country()!='FR')

?>#payez-sur-12-mois{display:none!重要;}#payez-sur-12-mois{display:none!重要;}对我不起作用!如果(!country\u geo\u ip\u check(数组('FR'))我应该在country\u geo\u ip\u check之前添加$吗?@Elichy Ok再做一些更改就行了。这一次它的效果和预期一样好。
add_action( 'wp_head' , 'custom_inline_css', 200 );
function custom_inline_css() {
    // Get an instance of the WC_Geolocation object class
    $geolocation_instance = new WC_Geolocation();
    // Get user IP
    $user_ip_address = $geolocation_instance->get_ip_address();
    // Get geolocated user IP country code.
    $user_geolocation = $geolocation_instance->geolocate_ip( $user_ip_address );

    // For all countries except 'FR'
    if( $user_geolocation['country'] !== 'FR' ){
        ?><style>#payez-sur-12-mois{display:none !important;}</style><?php
    }
    // For testing (to be removed):
    echo '<!-- GEO Located country: '.$user_geolocation['country'].' -->';
}