This plugin work in half.
You can set restrictions into product edit window, but this not work on checkout page, after click order submit button.
Solution:
function fnc_woocommerce_after_checkout_validation( $data, $errors ) {
global $woocommerce;
$cart_contents = $woocommerce->cart->get_cart_contents();
$fz_shipping_is_disabled = false;
if ( is_countable( $cart_contents ) === true && is_array( $cart_contents ) === true ) {
foreach ( $cart_contents as $cart_item ) {
$fz_country_restriction_type = get_post_meta( $cart_item[ 'product_id' ], '_fz_country_restriction_type', true );
$fz_restricted_countries = get_post_meta( $cart_item[ 'product_id' ], '_fz_restricted_countries', true );
if ( empty( $fz_restricted_countries ) === false && is_array( $fz_restricted_countries ) === true ) {
if ( $fz_country_restriction_type === 'excluded' ) {
if ( in_array( $data[ 'shipping_country' ], $fz_restricted_countries ) === true ) {
$fz_shipping_is_disabled = true;
}
}
if ( $fz_country_restriction_type === 'specific' ) {
if ( in_array( $data[ 'shipping_country' ], $fz_restricted_countries ) === false ) {
$fz_shipping_is_disabled = true;
}
}
}
}
}
if ( $fz_shipping_is_disabled === true ) {
wc_add_notice( 'We do not send certain products to selected country. Please, remove restricted products from cart, or change shipping country.', 'error' );
}
}
add_action( 'woocommerce_after_checkout_validation', 'fnc_woocommerce_after_checkout_validation', 10, 2 );