Magento 2 Estimated Delivery Date v2.x Developer Guide and API Reference

Magento 2 Estimated Delivery Date Manual Configuration

The Estimated Delivery Date module will automatically add “Delivery Dates” on the Product Page if enabled in the backend. However, you can change the standard “Delivery Date” display or position in the front-end. To do this follow the instructions below.

Product Page

In order to have the Delivery Date displayed on the product page – please make the following steps on your server :1. Create file:

/app/design/frontend/<Vendor>/<theme>/Plumrocket_Estimateddelivery/layout/catalog_product_view.xml

2. Paste the code below into the created file:

<?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">
    <body>
        <move element="estimateddelivery_product" destination="CONTAINER_OR_BLOCK_NAME"
            after="-"/>
    </body>
</page>

CONTAINER_OR_BLOCK_NAME – name of one of the containers or blocks on the product page. You can check them in the theme layout.

Go to:

/app/design/frontend/<Vendor>/<theme>/Magento_Catalog/layout/catalog_product_view.xml

or:

/vendor/magento/module-catalog/view/frontend/layout/catalog_product_view.xml

after=”-” means that block with estimated delivery dates has been placed into container.CONTAINER_OR_BLOCK_NAME after all the blocks. before=”-” can be used, if you need to place it before other blocks. Instead of “-” you can use name of specific block, if you need to place estimated delivery dates before or after it.

Example:

<?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">
        <body>
            <move element="estimateddelivery_product" destination="product.info.extrahint"
                after="-"/>
        </body>
    </page>

Category Page

In order to add the Estimated Delivery dates to the products on the category page, make the following steps on your server:

1. Create file:

/app/design/frontend/<Vendor>/<theme>/Plumrocket_Estimateddelivery/layout/catalog_category_view.xml

2. Paste the code below into the created file:

/app/design/frontend/<Vendor>/<theme>/Magento_Catalog/layout/catalog_product_view.xml

or here:

/vendor/magento/module-catalog/view/frontend/layout/catalog_product_view.xml

Display Estimated Delivery Dates and Shipping Dates in Magento for Specific Categories & Products

The following methods in “Plumrocket_Estimateddelivery_Block_Product” block allow to show shipping and delivery dates for specific products:

setProduct($product)

Allows to set the product the dates will be shown for.

Example:

Let’s show the date for “related” products on Product Page:

$relatedProducts = get_related_products(); // where get_related_products() is some custom
        method to retrieve related products
    $estimatedBlock = $this->getLayout()->createBlock(
        "PlumrocketEstimateddeliveryBlockProduct")
        ->setTemplate("Plumrocket_Estimateddelivery::product.phtml");
    foreach ($relatedProducts as $_product) {
        echo $estimatedBlock->setProduct($_product)->toHtml();
    }

Example:

On Product Page with custom design we can display dates for “related” products and immediately after that display dates for the current product:

<div class="related_dates">
        <?php
            $relatedProducts = get_related_products(); // where get_related_products() is
                some custom method to retrieve related products
            foreach ($relatedProducts as $_product) {
                echo $this->getChild('estimateddelivery')->setProduct($_product)->toHtml();
            }
        ?>
    </div>
    
    <div class="main_date">
        <?php $this->getChild('estimateddelivery')->reset()->toHtml(); ?>
    </div>
setCategory($category)

Allows to set the category for which the dates will be shown.

Example:

Let’s display html block that contains delivery date for the set category:

$customCategory = MagentoFrameworkAppObjectManager::getInstance()->create(
        'MagentoCatalogModelCategory')->load(<any id>);
    echo $this->getLayout()
        ->createBlock('PlumrocketEstimateddeliveryBlockProduct')
        ->setTemplate('Plumrocket_Estimateddelivery::product.phtml')
        ->setCategory($customCategory)
        ->toHtml();
getProduct()

Allows to get the product for which the dates will be shown. Note: If no product was indicated manually – current product will be returned on Product Page.

getCategory()

Allows to get the category the dates will be shown for. Note: If no category was indicated manually – current category will be returned on Product Page or Category Page.

reset()

Allows to clear all current settings. After calling this method, the other methods (getProduct and getCategory) will return current product (on Product Page) and current category (on Product Page or Category Page) accordingly.This method comes handy for displaying dates of custom products (categories) on the product (category) page, and for returning to default settings.

Example code of layout.xml file:

Let’s display block with date for the product by inserting it into the layout:

<catalog_product_default>
        <body>
            <referenceContainer name="category.view.container">
                <block class="PlumrocketEstimateddeliveryBlockProduct"
                    name="estimateddelivery_product" as="estimateddelivery"
                    template="Plumrocket_Estimateddelivery::product.phtml" cacheable="false" />
            </referenceContainer>
        </body>
Was this article helpful?