WordPress.org

Ready to get started?Download WordPress

Forums

Woocommerce force shipping country by WPML (1 post)

  1. EightN9ne
    Member
    Posted 11 months ago #

    I have a woocommerce store and it runs WPML so I can have different prices for Canadian or American customers because of different warehouses and costs.

    It works great it changes the price and depending on if they select the US or CAN store but my problem is people in the US store can still select to ship to Canada and vice versa.

    I need to change the code so that if they are in the "Canadian Store" (in other words they have Canada selected as their language) they can only select to ship to Canada and the same for the US store.

    Can this be done by adding a php if statement to woocommerce-template.php where the below code normally is that basically says if WPML is set to US then the only country option is United States else the only option is Canada? If so what would the code be?

    <select name="' . esc_attr( $key ) . '" id="' . esc_attr( $key ) . '" class="country_to_state country_select" ' . implode( ' ', $custom_attributes ) . '>
    <option value="">'.__( 'Select a country&hellip;', 'woocommerce' ) .'</option>';
    
       foreach ( $woocommerce->countries->get_allowed_countries() as $ckey => $cvalue )
       $field .= '<option value="' . $ckey . '" '.selected( $value, $ckey, false ) .'>'.__( $cvalue, 'woocommerce' ) .'</option>';
    
    $field .= '</select<>';

Reply

You must log in to post.

About this Topic