1. Documentation
  2. Plugins
  3. WooCommerce
  4. Extensions
  5. Smart Coupons

How to change the coupon expiry date format displayed on the website

Smart Coupons provide a powerful, “all-in-one” solution for gift certificates, store credits, discount coupons, and vouchers extending the core functionality of WooCommerce coupons.

This doc article explains how to change the coupon expiry date format on your WooCommerce store.

Currently, the default display format used by Smart Coupons is 31-Dec-2020.

In this guide, we’ll change the display format of the expiry date to the date format of the website that is set under the menu Settings > General > Date Format.

Steps to change display format of expiry date ↑ Back to top

  1. Open the directory of the child theme of your website
  2. Find a file named functions.php
  3. Open the file in an editor
  4. Copy & paste the following code at the end of functions.php file
    /**
     * Change the display format of the expiry date of the coupon which is displayed on the website & set it as per the website's setting
     *
     * @author StoreApps.org <support@storeapps.org>
     */
    function storeapps_wc_sc_formatted_coupon_expiry_date( $expires_string = '', $args = array() ) {
        $expiry_date = ( ! empty( $args['expiry_date'] ) ) ? $args['expiry_date'] : 0;
        if ( $expiry_date instanceof WC_DateTime ) {
            $expiry_date = $expiry_date->getTimestamp();
        } elseif ( ! is_int( $expiry_date ) ) {
            $expiry_date = strtotime( $expiry_date );
        }
        if ( ! empty( $expiry_date ) ) {
            $expires_string = date_i18n( get_option( 'date_format', 'F j, Y' ), $expiry_date );
        }
        return $expires_string;
    }
    add_filter( 'wc_sc_formatted_coupon_expiry_date', 'storeapps_wc_sc_formatted_coupon_expiry_date', 99, 2 );
    
  5. Save the file. That’s it.

Date format – before applying the code ↑ Back to top

Smart Coupons change display format of expiry date (before)

Date format – after applying the code ↑ Back to top

Smart Coupons change display format of expiry date (after)

WooCommerce - the most customizable eCommerce platform for building your online business.

  • 30 day money back guarantee
  • Support teams across the world
  • Safe & Secure online payment