You are viewing this forum as a guest. Login to an existing account, or create a new account, to reply to topics and to create new topics.
We need to add a separate charge during checkout that applies only to sales to a specific country. The amount needs to be a percentage of the cart's subtotal. I've seen something similar added to a custom shipping script, but in our case, we need the amount of the charge listed on a separate line during checkout, not included with the shipping fee.
I grabbed a copy of the "Total Of X - Y Percent Surcharge" script and included it below. How do we limit this script to charge the fee only on sales to a specific country?
<?php // +-- // | All custom surcharge scripts work in the same way. Global // | variables named 'ecom.checkout_cartids' and // | 'ecom.checkout_cosess' contain cart information and // | checkout session information respectively. // | // | This script must set global variables named // | 'ecom.total_customsurcharge' and 'ecom.customsurcharge_text' which // | contain the surcharge total and the surcharge text respectively. // | // | NOTE: Do not print anything within custom surcharge // | scripts. They are designed only to return amounts and // | text for custom surcharge methods. // | // | This script is a Total Of X - Y Percent Surcharge script that // | returns a surcharge amount based on the subtotal of items // | being purchased. // +-- $cartids = $this->globals('ecom.checkout_cartids'); $cosess = $this->globals('ecom.checkout_cosess'); // +-- // | surcharge_percent = The surcharge percentage. // | surcharge_subtotal = The subtotal needed to get the surcharge. // | surcharge_textshow = The text to be displayed for the surcharge. // +-- $surcharge_percent = 10; $surcharge_subtotal = 100; $surcharge_textshow = 'Surcharge Total'; $subtotal = 0; foreach ($cartids as $cartid => $item) { $subtotal = $subtotal + $item['subtotal']; } // End of foreach statement. if ($subtotal >= $surcharge_subtotal) { $surcharge_amount = $subtotal * ($surcharge_percent / 100); $this->globals('ecom.total_customsurcharge',$surcharge_amount); $this->globals('ecom.customsurcharge_text',$surcharge_textshow); } // End of if statement. ?>
Your help is greatly appreciated!
Offline
At the top of the script, you can add this to limit using this script to a specific billing country, in this case 'United States':
if ($this->globals('core_session.country') != 'United States') {return 1;}
Offline