Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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 '<p class="woocommerce-notice">' . esc_html__('We are sorry, this product is unavailable for order from your country.', 'geoip-filter-product') . '</p>';
- }, 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 '<p class="woocommerce-notice">' . esc_html__('We are sorry, this product is unavailable for order from your country.', 'geoip-filter-product') . '</p>';
- }
- return $button;
- }, 10, 2);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement