in the home page show, the number of orders that are placed and when the user placed the order that number should increase in home page for eg the current order placed are 500 and when user place the order it should 501 shown in home page in magento2

  • You want to display the order count of the logged in user or overall order count you want to display in home page? Apr 4, 2019 at 10:01
  • overall order count Apr 4, 2019 at 10:08

1 Answer 1


Try this,

Create a helper and add the below code to it,

Helper path be like


namespace Vendor\Module\Helper;
class Data extends \Magento\Framework\App\Helper\AbstractHelper
public function __construct(
    \Magento\Sales\Model\OrderFactory $orderFactory
) {
    $this->orderFactory = $orderFactory;
public function getCollection()
    $total = $this->orderFactory->create()->getCollection();
    return $total->getSize();


then in your phtml you can call like below

echo $this->helper('Vendor\Module\Helper\Data')->getCollection();

you can call any of the phtml in the home page to get this information.

To call a phtml only on home page follow the below steps

create a cms_index_index.xml in the below path


then add the below code to it

<?xml version="1.0"?>
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
   <referenceContainer name="content">
        <block class="Magento\Framework\View\Element\Template"  name="sales_total" template="Vendor_Module::total.phtml">

Vendor_Module - this should you namespace_modulename

And also place total.phtml in the below path


Hope this helps.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.