Author: Narender Singh

Myself Narender Singh Thakur ( NST ) and i share my Experience/Knowledge and Tricks for folks and beginners to solve their issues while making websites through this Planet.

Shopify to show product created and published date!

Sometime we want to show the product publish date on product template.

Here is the code to show product created and publish date on product page.

1) product.published_at :-  Returns the date and time the product was published.

2) product.created_at :-  Returns the date and time the product was created

For example:- I want to show the NEW badge on product pages which one are published less than 15 days ago.

 {% assign product_pub_at = product.published_at | date: '%s' %}
    
{% assign time_ago = 'now' | date: '%s' | minus: product_pub_at | divided_by: 86400 %}
                     
{% if time_ago < 15 %}
    <div class="new_banner prd">NEW</div>
{% endif %}  

For products added in the last 15 days or you can modify the days in coding.

shopify product created and published date

I hope this helps you ..

Thanks 🙂

How to add Category name to body class wordpress!

What is the purpose of body_class function in wordpress ?

body_class function helps to show the bunch of classes name to the body element that have information about what kind of page is currently being displayed.

Here is the way to implement body_class function into theme template.

<body <?php body_class(); ?>>

So now we want to add category name to body class .. mostly for styling purposes. 😉

Add this code to your functions.php file and hit on save button.

add_filter('body_class','nst_add_category_name');
function nst_add_category_name($classes) {
if (is_single() ) {
global $post;
foreach((get_the_category($post->ID)) as $category) {
// add category slug name to the $classes array
$classes[] = $category->category_nicename;
}
}
// return the $classes array here
return $classes;
}

I hope this helps you.. Thanks 🙂

How to show Estimate Delivery Date on product Page in Shopify!

Here is one of the way to Show Estimate Delivery Date and time of products on product page template under add to cart button in Shopify.

NOTICE : Please do only if you have little bit knowledge of files.. otherwise you can contact your developer or Just drop a message for me in chat box.

1. Login to your Shopify website admin and visit to Online Store Section and then Themes option.

shopify online store theme option

2. Edit your theme by click on Edit Code option.

shopify edit code

3. From left sidebar under Sections tab find product-template.liquid file.

section from shopify online store

3. Open product-template.liquid file and scroll to the end of form tag </form> .. like here..

4. Now add these line of code there ..

  {% comment %}          
    To show under add to cart product page.          
  {% endcomment %}          
                    
        {% assign mont = 'now' | date: '%m'  %}            
          
         {% if mont == '01' %}          
            {% assign nexm = 'Feb' %} 
         
          {% elsif  mont == '02' %}          
            {% assign nexm = 'Mar' %}
          
          {% elsif  mont == '03' %}          
            {% assign nexm = 'Apr' %}
          
          {% elsif  mont == '04' %}          
            {% assign nexm = 'May' %}
          
          {% elsif  mont == '05' %}          
            {% assign nexm = 'Jun' %}
          
          {% elsif  mont == '06' %}          
            {% assign nexm = 'Jul' %}
          
          {% elsif  mont == '07' %}          
            {% assign nexm = 'Aug' %}
          
          {% elsif  mont == '08' %}          
            {% assign nexm = 'Sep' %}
          
          {% elsif  mont == '09' %} 
            {% assign nexm = 'Oct' %}
          
          {% elsif  mont == '10' %}          
            {% assign nexm = 'Nov' %}
          
          {% elsif  mont == '11' %}
            {% assign nexm = 'Dec' %}
          
          {% else %}          
            {% assign nexm = 'Jan' %}          
         {% endif %}          
         
          
  {% if mont == '04' or mont == '06' or mont == '09' or mont == '11' %}  
        {% assign f_mont = '30' %}
        {% elsif  mont == '02' %}
        {% assign f_mont = '28'%}
        {% else %}
        {% assign f_mont = '31'%}  
  {% endif %}  
          
         {% assign nexm = nexm | append: ". " %} 
         {% assign c_day = 'now' | date: '%d' %} 
         {% assign tday = f_mont | minus: c_day %}           
         
          
      {% if tday < 7 %}  
         {% assign time_inc = 7 | minus: tday | prepend: nexm %}
      {% else %}          
         {% assign mon =  'now' | date: "%b" | append: ". " %}
         {% assign time_inc = c_day | plus: 7 | prepend: mon %}          
      {% endif %}          
                            
    <div class="us-shp  ">✈️ U.S. Delivery {{time_inc}}</div>  

          
         
          

You can style it as per your theme color.

After add this click on save button and check the result on product page now.

It will be similar to this…

shopping in shopify date

This date will auto update the date of delivery by 7 days from today’s date.

You can alter the code as per your need … if you want any help then contact me please.

Thanks 🙂

Shopify apply discount code as per if cart has particular product

So here are the way to apply manual discount automatically on checkout page.. if particular products are in cart items.

You can also use automatic discount for same purpose but if 1 automatic is already active then you can choose this 2nd way to apply auto discount.

As currently shopify plus support only one automatic discount at a time.

So here is the script you have to apply on cart liquid file of your theme. Mine is ( cart-template.liquid ) in Debut theme.

NOTE : Please create a normal discount in admin first then you can apply that code there in script.

Here is the way to add discount code in shopify….

Like in the above screenshot.. click on create discount button. New window will be like this..

Choose first one and next window will be..

create discount code

Add your discount code there like helo or something you like or as per your purpose..

So we have now discount code name “helo” ..

add this script to near after form start.. on your theme cart liquid file.
<form action=”/cart” method=”post”>

if you want to match single product in cart item then..

   {% assign prod = false %}  
      
{% for item in cart.items %} 
      
  {% if item.product.title == 'Your product name or title' %}      
         {% assign prod = true %}      
  {% endif %}            
   
{% endfor %}
      
{% if prod %}      
     <input type="hidden" name="discount" value="helo"/>        
{% endif %}

Please change “Your product name or title” to with your product name.

If you want to match two products then follow this script..

   {% assign prod = false %}
   {% assign prod1 = false %}
      
{% for item in cart.items %} 
      
  {% if item.product.title == 'Your product name or title' %}      
         {% assign prod = true %}      
  {% endif %}
            
  {% if item.product.title == 'Your product name or title 2' %}      
       {% assign prod1 = true %}         
  {% endif %}    
  
{% endfor %}
      
{% if prod and prod1 %}      
     <input type="hidden" name="discount" value="helo"/>        
{% endif %}

So above scripts will only add discount on cart page if they matched to your mentioned products name and discount code will reflect on checkout page automatically.

You can also show message to cart page like this.. showing in red color on right side of screenshot.

show message on cart page shopify

add this one script to where you want to show message on cart page.

 {% if prod and prod1 %}            
    <strong class="cod-check1">*Your discount will apply in checkout.</strong> 
  {% endif %}

I hope this will help you .. If you need more help then contact with me using chat box.

Thanks 🙏

How to check and download correct database used in your wp website ?

Here is the way to find the correct database used for your website..

Login to your website hosting and Click on File Manager.

find database

Now find the file name wp-config.php and right click on that file to view it.

Now check your database name like here..

Now go to main homepage of your cpanel and click on phpMyAdmin icon.. like here..

phpmyadmin

Click on that and  new window will open…like this .. so follow the steps i mentioned there… select the correct database to export and than click on “Export” 3 point top right.

export database

After click on “Export”.. new window will be..

how to export database in phpmyadmin

After Click on Go .. database will be downloaded to your machine .

That’s it .

Thanks 🙏

Click to Chat