简体   繁体   中英

show/hide magento cart in wordpress

I'm working on a site which is primarily based on wordpress but uses magento to deal with its e-commerce (not my choice, it's how the site is setup).

When a product is selected, it links through to the magento shopping cart. We have a site wide "View Cart" link in the head of the site which links to the magento cart. What I'd like to do is to hide this link if the cart is empty.

Working soley in magento I could use this to hide the link:

<?php $_cartQty = $this->getSummaryCount() ?>
<?php if ($_cartQty >0): ?>
<a href="link">link to cart</a>
<?php endif ?>

but it doesn't work for wordpress... Is there a way to get the cart count from magento into wp to then use something along the lines of...

<?php if (sizeof($cart) > 1)) : ?>
<a href="link">link to cart</a>
<?php endif ?>
<?php
require_once '../app/Mage.php'; //root to app/Mage.php of magento
Mage::app(); //run
Mage::getSingleton('core/session', array('name'=>'frontend')); //load session
$count = Mage::helper('checkout/cart')->getSummaryCount(); //read count itemes in cart
$total = Mage::helper('checkout/cart')->getQuote()->getGrandTotal(); //read total in cart
if($count==0){
    echo '<a href="'.Mage::getBaseUrl("web").'checkout/cart">Cart is empty</a>';
}
else {
    echo '<a href="'.Mage::getBaseUrl("web").'checkout/cart">'.$count.' item(s) with total '.Mage::helper('core')->formatPrice($total, false).'</a>';
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM