2013-05-02 66 views
-1

我有我的購物車代碼(Magento的1.6.2)腓如果選擇按產地訪問者(IP地址)

<?php if ($this->getQuote()->getSubtotal() < 41.28): ?> 
<?php $subtotalamt = $this->getQuote()->getSubtotal(); ?> 
<?php $freeshipamt = 41.28; ?> 
<?php $sumtotal = ($freeshipamt - $subtotalamt)* 1.21; ?> 
<?php Mage::helper('checkout')->formatPrice($sumtotal); ?> 
<p>Gratis verzending vanaf € 49,95 <br/>(binnen Nederland)</p><p> 
<strong>Nog <span>€ <?php print number_format($sumtotal, 2, ',', ' '); ?></span> 
tot gratis verzending!</strong></p> 
<?php else: ?><p><strong>Uw bestelling wordt GRATIS verzonden!</strong> <br/>(binnen Nederland)</p> 
<?php endif ?> 
<?php /* You are just <span>$<?php print ($sumtotal); ?></span> away from earning free shipping!</p> */ ?> 

此代碼計算客戶在荷蘭境內免運費所需金額。

有沒有辦法添加一些代碼,所以當一個來自其他國家的訪客訪問我們的網上商店的金額改變了免費送貨。像德國或比利時一樣。他們從149,95收到免費送貨。

我想應該有一個php if whick可以確定訪問者ip-adress的來源。 任何人都可以幫我設置這個嗎?

+0

可能的重複[如何從IP地址中獲取國家/地區名稱](http://stackoverflow.com/questions/4191489/how-to-get-country-name-from-ip-address-in-php ) – Quentin 2013-05-02 11:16:08

回答

0

這是一些IP到國家的數據庫和API。的API可能工作得很好,但你會爲此付出一些錢,他們...

把你的時間來檢查這個PHP類+ DB:

https://github.com/magorski/php-ip-2-country

PS:也許區議會並非如此不好,現在我在一個真正的系統上使用了一個PHP類,它有一個簡單的數據庫來完成這個工作,並且比我指出的那個小得多。 (也許不那麼精確或什麼)。