• dassels43

    (@dassels43)


    Hi, any plans to add the EU as it’s own ‘country’, so it appears in the dropdown selector and when selected it includes all 27 member states? This would a great feature. The previous plugin we were using, Product Visibility by Country for WooCommerce by WP Wham, had this feature and it was a real time saver.

Viewing 1 replies (of 1 total)
  • Thread Starter dassels43

    (@dassels43)

    For anyone that wants a work around, you can do the following:

    Update functions.php in your child theme:

    /**
    * Add a new country to countries list
    */
    add_filter( 'woocommerce_countries', 'add_eu_to_dropdown' );
    function add_eu_to_dropdown( $countries ) {
    $new_countries = array('EU' => __( 'European Union', 'woocommerce' ),
    );

    return array_merge( $countries, $new_countries );
    }

    Then edit this plugin with the following:

    	/*
    * Save the product meta settings for simple product
    *
    * @since 1.0.0
    * @para $post_id
    */
    public function save_custom_product_fields( $post_id ) {
    $restriction = isset($_POST['_fz_country_restriction_type']) ? sanitize_text_field($_POST['_fz_country_restriction_type']) : '';
    if (! is_array($restriction)) {

    if ( !isset( $_POST['_restricted_countries'] ) || empty( $_POST['_restricted_countries'] ) ) {
    update_post_meta( $post_id, '_fz_country_restriction_type', 'all' );
    } else {
    if ( !empty( $restriction ) ) {
    update_post_meta( $post_id, '_fz_country_restriction_type', $restriction );
    }
    }

    $countries = array();

    if (isset($_POST['_restricted_countries'])) {
    $countries = isset($_POST['_restricted_countries']) ? wc_clean( $_POST['_restricted_countries'] ) : '';
    }

    $eu_countries = array( 'AT', 'BE', 'BG', 'CY', 'CZ', 'DE', 'DK', 'EE', 'ES', 'FI', 'FR', 'GR', 'HU', 'HR', 'IE', 'IT', 'LT', 'LU', 'LV', 'MT', 'NL', 'PL', 'PT', 'RO', 'SE', 'SI', 'SK' );

    if ( ! empty( $countries ) && is_array( $countries ) && in_array( 'EU', $countries )) {
    $countries = array_merge($countries, $eu_countries);
    } else {
    $countries;
    }

    update_post_meta( $post_id, '_restricted_countries', $countries );
    }
    }

    /*
    * Save the product meta settings for variation product
    *
    * @since 1.0.0
    * @para $post_id
    */
    public function save_custom_variation_fields( $post_id ) {
    $restriction = isset($_POST['_fz_country_restriction_type'][ $post_id ]) ? sanitize_text_field($_POST['_fz_country_restriction_type'][ $post_id ]) : '';

    if ( !isset( $_POST['_restricted_countries'] ) || empty( $_POST['_restricted_countries'] ) ) {
    update_post_meta( $post_id, '_fz_country_restriction_type', 'all' );
    } else {
    if ( !empty( $restriction ) ) {
    update_post_meta( $post_id, '_fz_country_restriction_type', $restriction );
    }
    }

    $countries = array();
    if (isset($_POST['_restricted_countries'])) {
    $countries = isset( $_POST['_restricted_countries'][ $post_id ] ) ? wc_clean( $_POST['_restricted_countries'][ $post_id ] ) : '';
    }

    $eu_countries = array( 'AT', 'BE', 'BG', 'CY', 'CZ', 'DE', 'DK', 'EE', 'ES', 'FI', 'FR', 'GR', 'HU', 'HR', 'IE', 'IT', 'LT', 'LU', 'LV', 'MT', 'NL', 'PL', 'PT', 'RO', 'SE', 'SI', 'SK' );

    if ( ! empty( $countries ) && is_array( $countries ) && in_array( 'EU', $countries )) {
    $countries = array_merge($countries, $eu_countries);
    } else {
    $countries;
    }

    update_post_meta( $post_id, '_restricted_countries', $countries );
    }

    Basically, we want to change how the 2 functions “save_custom_product_fields” and “save_custom_variation_fields” save the data. Note that on next update this will need to be updated again until this or similar feature is implemented by Zorem.

Viewing 1 replies (of 1 total)
  • You must be logged in to reply to this topic.