Php如果选择由源访问者(ip地址)



我有这个代码在我的购物车(magento 1.6.2)

<?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年起免费送货。

我猜应该有一个可以确定访问者ip地址来源的php if。有人能帮我把这个设置好吗?

是一些到国家数据库和api的IP。api可能工作得很好,但你最终会为它们支付一些钱…

用你的时间检查这个PHP类+ DB:

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

PS:也许数据库不是那么糟糕,现在我在一个真正的系统上使用一些PHP类和一个简单的数据库来完成这项工作,并且比我指出的那个小得多。

最新更新