Call Category function
$categories = $this->getTreeCategories(2, false);
print_r($categories);
Get All categories array tree view
function getTreeCategories($parentId, $isChild) {
$allCats = Mage::getModel('catalog/category')->getCollection()
->addAttributeToSelect('*')
->addAttributeToFilter('is_active', '1')
->addAttributeToFilter('include_in_menu', '1')
->addAttributeToFilter('parent_id', array('eq' => $parentId));
$subcat = ($isChild) ? " -- " : "";
foreach ($allCats as $category) {
$options[] = array(
'label' => Mage::helper('jaydip_attrfiltercount')->__($subcat.iconv(mb_detect_encoding($category->getName(), mb_detect_order(), true), "UTF-8", $category->getName())),
'value' => $category->getId()
);
$subcats = $category->getChildren();
if ($subcats != '') {
$options[] = $this->getTreeCategories($category->getId(), true);
}
}
$optiondata = array();
foreach ($options as $option):
if(isset($option[0])){
foreach ($option as $value):
$optiondata[] = array(
'label' => $value['label'],
'value' => $value['value']
);
endforeach;
}else{
$optiondata[] = array(
'label' => $option['label'],
'value' => $option['value']
);
}
endforeach;
return $optiondata;
}
<?php
/**
* woocommerce_after_shop_loop_item_title hook
*
* @hooked woocommerce_template_loop_rating - 5
* @hooked woocommerce_template_loop_price - 10
*/
do_action( 'woocommerce_after_shop_loop_item_title' );
?>
</a>
<?php do_action( 'woocommerce_after_shop_loop_item' ); ?>
with this:
<?php
/**
* ADD PRODUCT VARIABLE WITH ADD TO CART ON CATALOG PAGE
ADDED BY GW
**/
?>
<div class="catbox">
<?php
//ADD SHORT DESCRIPTION TO PRODUCT
add_action('woocommerce_after_shop_loop_item_title','woocommerce_template_single_excerpt', 5); ?>
<?php
/**
* woocommerce_after_shop_loop_item_title hook
*
* @hooked woocommerce_template_loop_rating - 5
* @hooked woocommerce_template_loop_price - 10
*/
do_action( 'woocommerce_after_shop_loop_item_title' );
?>
<?php do_action( 'woocommerce_after_shop_loop_item' ); ?>
<?php
//ADD VARIATIONS BEFORE ADD TO CART
if($product->product_type == "variable"){
woocommerce_variable_add_to_cart();
} else {
woocommerce_template_loop_add_to_cart();
}
?>
</div>
- In your backend, go to Catalog -> Categories -> Manage Categories.
- Select the category you want to add products to.
- Click "Category Products" Tab
- Reset the Filter, select your products, Save Category