限制 magento 1.9.0 中某些 zip/pin 代码的默认货到付款

restrict default Cash on delivery for some zip/pin codes in magento 1.9.0

我们在 magento 1.9.0 中使用货到付款方式

我们仅对某些邮政编码 codes/pin 需要此付款方式。

这里有人得到了解决方案:

How to restrict default COD in magento to certain zip codes only?

我真的无法用一些想法来实施该解决方案。

任何人都可以逐步详细地向我解释该解决方案。

您只需编辑文件 /app/code/core/Mage/Payment/Model/Method/Cashondelivery.php

打开它并将下面的代码添加到 class 的最后(就在文件中最后一个“}”之前):

public function isAvailable($quote = null)
{
    if ($quote) {

        // Here is the list of restricted Zip Codes
        $restrictedZips = array(
            '85001',
            '87965'
        );

        $address = $quote->isVirtual() ? $quote->getBillingAddress() : $quote->getShippingAddress();
        $customerZip = $address->getPostcode();

        if (in_array($customerZip, $restrictedZips)) {
            return false;
        }
    }

    return parent::isAvailable($quote);
}

P.S.: 请注意,使用此解决方案,您需要在代码中直接输入邮政编码。如果您想避免这种情况,并获得通过管理面板输入邮政编码范围的能力,请联系我们了解更多详情。

首先,您将在您的数据库中创建一个邮政编码 table,并在您的产品页面上创建一个简单的输入字段,现在为此创建一个验证,然后创建一个 AJAX 函数来检查邮政编码COD 可用与否。