Already made a script with help from this forum and friends, like:
<?php
// Determine if product "free shipping" is true
if ($_product->getFreeShipping())
{
echo '<span class="freeShip">'.$_product->getAttributeText('free_shipping').'</span>';
}
// Determine if product costs more than 65
else if ($_specialPrice = $_product->getFinalPrice() > 65)
{
echo '<span class="freeShip">FREE SHIPPING ON THIS PRODUCT!</span>';
}
?>
This works perfectly, but now I want also to show the "FREE SHIPPING ON THIS PRODUCT" text when a price rule called "Free Shipping Rule" is enabled. This price rule ensures that a selection of products gets free shipping.
I already made a short code, but don't know how to go further. //Load the rule object $rule = Mage::getModel('catalogrule/rule')->load($ruleID);
if ($_product->$rule->getName() = Free Shipping Rule)
{
echo '<span class="freeShip">FREE SHIPPING ON THIS PRODUCT!</span>';
}
Done this with information from this post: Magento - get price rules from order
If you see something that I can change, or what I can do to make it work, please let me know! Thanks!
EDIT 1: I thought we can also do this when getting information about the shipping cost. I thought something like "If shipping cost = 0, display "FREE SHIPPING ON THIS PRODUCT". Just found something on the internet, and edited a bit. Do you think this code will work?
<?php
if($_product->isSaleable())
{
$quote = Mage::getModel('sales/quote');
$quote->getShippingAddress()->setCountryId('*');
$quote->addProduct($_product);
$quote->getShippingAddress()->collectTotals();
$quote->getShippingAddress()->setCollectShippingRates(true);
$quote->getShippingAddress()->collectShippingRates();
$rates = $quote->getShippingAddress()->getShippingRatesCollection();
foreach ($rates as $rate)
}
// Check the product shipping price
php if ($rate->getPrice() == 0)
{
echo '<span class="freeShip">FREE SHIPPING ON THIS PRODUCT!</span>';
}
?>
EDIT 2: Edited the code to below, but still doesn't work. Looks like the is well, isn't it?
<?php
// Determine if product "free shipping" is true
if ($_product->getGratisVerzending())
{
echo '<span class="freeShip">'.$_product->getAttributeText('gratis_verzending').'</span>';
}
// Determine if product costs more than 65
else if ($_specialPrice = $_product->getFinalPrice() > 65)
{
echo '<span class="freeShip">GRATIS VERZONDEN!</span>';
}
$quote = Mage::getModel('sales/quote');
$quote->getShippingAddress()->setCountryId('*');
$quote->addProduct($_product);
$quote->getShippingAddress()->collectTotals();
$quote->getShippingAddress()->setCollectShippingRates(true);
$quote->getShippingAddress()->collectShippingRates();
$rates = $quote->getShippingAddress()->getShippingRatesCollection();
foreach ($rates as $rate)
// Determine if shipping is 0
else if ($rate->getPrice() == 0)
{
echo '<span class="freeShip">FREE SHIPPING ON THIS PRODUCT!</span>';
}
?>