【问题标题】:Php if selection by origin visitor (ip adress)如果原始访问者选择了 PHP(IP 地址)
【发布时间】:2013-05-02 11:00:54
【问题描述】:

我的购物车中有这个代码(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 获得免费送货。

我想应该有一个php if 可以确定访问者IP 地址的来源。 谁能帮我设置一下?

【问题讨论】:

标签: php country


【解决方案1】:

这些是国家/地区数据库和 API 的一些 IP。 API 可能工作得很好,但你最终会为它们支付一些钱......

花点时间检查这个 PHP 类 + DB:

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

PS:也许数据库并没有那么糟糕,现在我在一个真实的系统上使用一些 PHP 类和一个简单的数据库,它可以完成这项工作并且比我指出的那个要小得多。 (可能不太精确或其他什么)。

【讨论】:

    猜你喜欢
    • 2023-03-31
    • 2020-12-12
    • 2013-02-05
    • 1970-01-01
    • 2015-03-01
    • 1970-01-01
    • 2023-04-11
    • 2011-12-17
    • 2015-01-16
    相关资源
    最近更新 更多