add_action('woocommerce_before_single_product', function() { $restricted_class = 'restricted-netherlands'; $user_country = WC_Geolocation::geolocate_ip()['country'] ?? ''; global $product; $shipping_class_id = $product->get_shipping_class_id(); $shipping_class = get_term_by('id', $shipping_class_id, 'product_shipping_class'); if ($shipping_class && $shipping_class->slug === $restricted_class && $user_country === 'NL') { add_filter('woocommerce_get_price_html', '__return_false'); add_filter('woocommerce_is_purchasable', '__return_false'); add_action('woocommerce_single_product_summary', function() { echo '
' . esc_html__('We are sorry, this product is unavailable for order from your country.', 'geoip-filter-product') . '
'; }, 25); } }, 10); add_filter('woocommerce_loop_add_to_cart_link', function($button, $product) { $restricted_class = 'restricted-netherlands'; $user_country = WC_Geolocation::geolocate_ip()['country'] ?? ''; $shipping_class_id = $product->get_shipping_class_id(); $shipping_class = get_term_by('id', $shipping_class_id, 'product_shipping_class'); if ($shipping_class && $shipping_class->slug === $restricted_class && $user_country === 'NL') { return '' . esc_html__('We are sorry, this product is unavailable for order from your country.', 'geoip-filter-product') . '
'; } return $button; }, 10, 2);