I have a CMS page that I am going to display products on with the following updated XML code:
<reference name="content">
<block type="catalog/product_list" name="product_list" template="catalog/product/wholesale-list.phtml">
<action method="setCategoryId"><category_id>191</category_id></action>
<action method="setToolbarBlockName"><name>product_list_toolbar</name></action>
</block>
</reference>
I have tried getting the ID I set in the layout, but no such luck. I have tried:
$_category = Mage::registry(‘current_category’);
$currentCategoryId= $_category->getId();
and
$layer = Mage::getSingleton(‘catalog/layer’);
$_category = $layer->getCurrentCategory();
$currentCategoryId= $_category->getId();
But neither of these methods work. Does anyone know how I can get the ID?
The first thing you need to do is log into your WordPress Dashboard and go to WooCommerce->Products->Categories. Now that you know how to find the current category id in WooCommerce, you can use this information to create custom WooCommerce shortcodes or show different products on different pages of your store.
php using the following code so the category-slug is displayed inside the string based on the current category: $cat = get_query_var('cat'); $yourcat = get_category ($cat);
i think this is the best way ;)
Mage::registry('current_category')->getId();
Haven't tried this, but maybe something like:
$this->getLayout()->getBlock('product_list')->getCategoryId()
This way you are directly getting the variable that you have set on the Block object in the XML.
Cheers,
JD
Try below code
Mage::getModel('catalog/layer')->getCurrentCategory()->getId();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With