Currently, when a product is out of stock, the 'addtocart' block disappears, but I want to change that so instead, it still displays the 'addtocart' block, but instead of the actual 'add to basket' button, it displays some text explaining that the product is out of stock.
I have managed to get this to work on simple products by taking
<?php echo $this->getChildHtml('addtocart') ?>
out of the
if ($_product->isSaleable())
section, and editing the 'addtocart' block so that if the product isn't saleable it displays the required text instead of the 'add to basket' button.
My issue is, for configurable products, whatever code dictates whether or not the 'addtocart' block is displayed isn't particularly obvious, I have looked all over view.phtml and load of other files, and grep'd through the entire directory, but the section I have already altered for simple products is the only one that shows up (in view.phtml)...
Any ideas?
it's the same code (if ($_product->isSaleable())) but in the file /app/design/frontend/base/default/template/catalog/product/view/addtocart.phtml
Turns out it was much simpler than I thought, in the 'view.phtml' file there were two sections of code:
<?php if ($_product->isSaleable() && $this->hasOptions()): ?>
<?php echo $this->getChildChildHtml('container2', '', true, true) ?>
<?php endif; ?>
Which grabs 'container2' if the product is BOTH a configurable product '$this->hasOptions()' AND is saleable. Container2 has the block for displaying configurable options, related products (but just for configurable products, the line of code above this code displays the related products for simple products), and the addtocart block. Below this code I had:
<?php if (!$this->hasOptions()): ?>
<div class="add-to-box">
<?php echo $this->getChildHtml('addtocart') ?>
<?php if ($_product->isSaleable()): ?>
<?php if ($this->helper('wishlist')->isAllow() || $_compareUrl = $this->helper('catalog/product_compare')->getAddUrl($_product)): ?>
<?php endif; ?>
<?php endif; ?>
Which displays the addtocart block if the product is a simple product 'if (!$this->hasOptions()'. I had to add the following bit of code as there was nothing which told the server what to do if the product was configurable but NOT saleable:
<?php if (!$_product->isSaleable() && $this->hasOptions()){ ?>
<?php echo $this->getChildHtml('addtocart') ?>
<?php } ?>
I'm fairly new to php so that was probably pretty obvious for a lot of people, but I managed to miss it for a good week or so (lucky this isn't my full time job!), hopefully this helps others!
Related
Woocommerce shopping cart page is acting very strange.
I just updated my theme ( X | Theme v3.2.5 ) and woocommerce ( v2.3.8 )
So I am running the most current versions.
For some reason, since the update my cart totals are now displaying twice on my cart page.
I have two subtotal columns, two proceed to checkout buttons, two empty cart buttons, etc.
When I look at the HTML, it's literally duplicated.
<div class="cart-collaterals">
<div class="cart_totals ">
<div class="cart_totals ">
</div>
Obviously cart_totals has more HTML underneath, but you get the idea.
On the actual cart.php page I can locate this php:
<?php woocommerce_cart_totals(); ?>
only one time. Here is all the markup from the cart.php page:
<div class="cart-collaterals">
<?php do_action( 'woocommerce_cart_collaterals' ); ?>
<?php woocommerce_cart_totals(); ?>
</div>
<?php do_action( 'woocommerce_after_cart' ); ?>
Is there any way to ensure that this php is only being ran one time?
I might try to just limit the height of the CSS container, but that's not the right fix...
In their latest update, they must have moved the cart total to the woocommerce_cart_collaterals, which means it is now printed once in this action, and once in your code.
I had the same problem with TM Extra Options plugin on Themeforest. In the plugin remove <?php woocommerce_cart_totals(); ?> in the templates/cart/cart.php file (it's at the bottom) and you will remove duplicate "Cart Totals". Hope this helps someone.
Using Catalog Price Rules, I'm trying to show that there was a discount applied to the particular product once viewing the cart page. Currently, Magento stops showing the "crossed-out" price when viewing the cart, so it doesn't appear that they received a discounted price unless they go back to the product / catalog page.
The area in question is located around line 103:
template > checkout > cart > item > default.phtml
What would be the proper way to show the original price next to the current price within this section? I serioulsly have no idea how it works and can't find anything on the net regarding this, as it's much different setup than anything inside View.phtml
<?php if (Mage::helper('weee')->typeOfDisplay($_item, array(0, 1, 4), 'sales') && $_item->getWeeeTaxAppliedAmount()): ?>
<?php echo $this->helper('checkout')->formatPrice($_item->getCalculationPrice()+$_item->getWeeeTaxAppliedAmount()+$_item->getWeeeTaxDisposition()); ?>
<?php else: ?>
<?php echo $this->helper('checkout')->formatPrice($_item->getCalculationPrice()) ?>
<?php endif; ?>
Due to the random / low responses I get from alternate StackExchange websites, I've also posted this question here: https://magento.stackexchange.com/questions/42494/show-original-price-in-cart
and will update my question accordingly. Thanks!
You could try using $_item->getProduct()->getPrice() to get the original price.
<?php echo $this->helper('checkout')->formatPrice($_item->getProduct()->getPrice()) ?>
What I'm looking to do is add a separate menu for each wordpress page on my site. I did some research and found that
<?php if (is_page('our-staff')): ?>
<?php wp_nav_menu('menu-side'); ?>
<?php endif; ?>
<?php if (is_page('contact-brian')): ?>
<?php wp_nav_menu('menu-home'); ?>
<?php endif; ?>
Is supposibly supposed to switch the menu from, menu-side while looking at the our-staff page, and it will change again when the page is contact-brian, it will change to the menu-home menu.
The problem is, I cannot get both menus to appear, its either one or the other
when you view our-staff page, i want the menu-side menu to appear, and nothing else.
When you view the contact-brian page, i want only the menu-home to appear –
I have added the following code, which seems to "hide" the products using the placeholder.
How can i make it so it completely skips that product.
The reason is on the grid of 50. Only 3 have images on the main page. Then only 3 will show and make the user go to the next page to see more.
<?php foreach ($_productCollection as $_product): ?>
<?php $small_image = $this->helper('catalog/image')->init($_product, 'small_image'); ?>
<?php if(!strpos($small_image,'placeholder/small_image')){ ?>
I have many sites that use the same root category of the Main Site. Each product that is added is added to the site it was added to (wow.) and also the Main Site. However, I would like categories on a per site basis to only appear if there are products on that site.
If I have:
Category1
Category2
Category3
But Site1 only has products in Category1 and Category2, whereas Site2 and Site3 have products in Category2 and Category3; I only want Category1/2 to appear on Site1 and only Category2/3 to only appear on Site2 and Site3.
However, because all products in Site1/2/3 are also added to the Main Site; the Main Site would list Category1/2/3.
No products are added directly to the Main Site. It simply serves as a repository for the other sites.
Now, if there is no really easy way to enable this (as I'm sure), would it be as simple as writing my own theme that lists categories that only have products on the site that the template is being displayed on?
I am not a novice in the technologies that Magento uses; so writing custom code is no problem. I would, however, not like to edit it that much so that upgrading my code base would be easier in the future with later versions of Magento.
Thanks,
-nelson
Well, what you can do is, create your own helper with a collection (through a model), and then filter the collection based on product count.
Only a rough draft, but I've posted some code in another magento related question: Magento products by categories. You can see how and when it adds the products count, I'd filter again when this is done.
I don't think this is extremely "great" in terms of performance, so instead of using their model classes, you could write your own, extending it and adding default filters, or shortcutting directly to the database.
As long as you stay in your skin/template, there are no larger issues with updating.
this is a simple solution to hide categories that might help you .
The original contents of the top.phtml file should look like below.
<?php $_menu = $this->renderCategoriesMenuHtml(0,'level-top') ?>
<?php if($_menu): ?>
<div>
<ul id="nav">
<?php echo $_menu ?>
</ul>
</div>
<?php endif ?>
Replace the code above with this code below.
<?php $_menu = ''?>
<?php $excludeCat = array(); ?>
<?php foreach ($this->getStoreCategories() as $_category): ?>
<?php if($_category->getProductCount() <=0) {
$excludeCat[] = $_category->getId();
}
?>
<?php $_menu .= $this->drawItem($_category) ?>
<?php endforeach ?>
<?php if ($_menu): ?>
<div>
<ul id="nav">
<?php foreach ($this->getStoreCategories() as $_category): ?>
<?php if (!in_array($_category->getId(), $excludeCat)) : ?> <?php echo $this->drawItem($_category) ?>
<?php endif; ?>
<?php endforeach ?>
</ul>
</div>
<?php endif; ?>