How to adjust Shipping prices based on desired countries using ELEX WooCommerce USPS Plugin? (Code Snippet)

Do you wish to adjust USPS shipping prices based on the desired countries? Do you want to add markup or apply discounts on shipping rates for selected countries?

If yes, you can achieve this by using the code snippet provided in this article. This code snippet can only be used if you have ELEX Shipping Plugin with USPS Postage for WooCommerce.

Code snippet to adjust Shipping prices based on desired countries

The price adjustments are made in percentage value. Add the following code snippet to the functions.php file of your activated website theme.

add_filter('elex_usps_stamps_set_custom_price_adjustment_percentage', 'set_custom_price_adjustment_percentage', 10, 2);

function set_custom_price_adjustment_percentage($price_adjustment_in_settings, $destination_country){
    $custom_price_adjustment_array = array(
        //Add desired country code and price adjustment
        'US' => '20',
        'GB' => '15',
        'IN' => '-5'
    foreach($custom_price_adjustment_array as $stored_country_code => $price_adjustment_percentage){
        if($stored_country_code == $destination_country){
            return $price_adjustment_percentage;
    return $price_adjustment_in_settings;

As given in the above code snippet, a 20% markup is applied to the United States (US), 15% markup to the Great Britain (GB), and 5% discount to India (IN). You can give country codes of desired countries in the array and give markup or discount (with a negative sign in prefix).


To explore more details about the plugins, go check out ELEX Shipping Plugin with USPS Postage for WooCommerce.

Read the product setting up article to understand the plugin, in detail. Or check out the product documentation section for more related articles.

You can also check out other WooCommerce and WordPress plugins in ELEX.

Previous Code Snippet to Rearrange Shipping Methods in cart page
Next Modifying product title and price in label (Code Snippet)

    Leave a Reply

    WordPress Image Lightbox Plugin