问题是这段代码在页面加载时被执行,基本上运输方法块只是隐藏,直到你到达那个步骤。这意味着
$this->getQuote()->getShippingAddress()->getCountry()
l
Ajax 加载的唯一内容是可用的运输方式,所以我通过挂钩来解决它
app/design/base/default/template/checkout/onepage/shipping_method/available.phtml
并添加以下 javascript 代码
<?php //Show extra shipping options only if the shipping address is outside of FRANCE ?>
<script type="text/javascript">
var countryID = '<?= Mage::getSingleton('checkout/session')->getQuote()->getShippingAddress()->getData('country_id') ?>';
jQuery('#ownTransport')[countryID == 'FR' ? 'hide' : 'show']();
</script>
供参考:中的代码
app/design/XXX/XXX/template/checkout/onepage/shipping_method.phtml
曾是
<form id="co-shipping-method-form" class="stack-form" action="">
<div id="checkout-shipping-method-load">
<?php echo $this->getChildHtml('available') ?>
</div>
<script type="text/javascript">
//<![CDATA[
var shippingMethod = new ShippingMethod('co-shipping-method-form', "<?php echo $this->getUrl('checkout/onepage/saveShippingMethod') ?>");
//]]>
</script>
<div id="onepage-checkout-shipping-method-additional-load">
<?php echo $this->getChildHtml('additional') ?>
</div>
<?php //ADD AMASTY FIELDS ?>
<?php //Show extra shipping options only if the shipping address is outside of FRANCE ?>
<div id="ownTransport">
<?php
echo Mage::helper('amorderattr')->fields('shipping_method');
?>
</div>
<div id="shipping-method-buttons-container" class="buttons-set">
<button class="button" onclick="shippingMethod.save()"><?php echo $this->__('Continue') ?></button>
<span class="please-wait" id="shipping-method-please-wait" style="display:none;"><?php echo $this->__('Loading') ?></span>
</div>
希望这可以帮助某人!