How to Dynamically Add a Coupon Code Bar to Specific Product Pages with Divi

Last Updated on September 16, 2022 by 5 Comments

How to Dynamically Add a Coupon Code Bar to Specific Product Pages with Divi
Blog / Divi Resources / How to Dynamically Add a Coupon Code Bar to Specific Product Pages with Divi

When you’re running an online shop you’ve made with Divi and WooCommerce, you’ll occasionally want to show coupon codes on your website to increase the sense of urgency. Across the web, you’ll notice that many online shops share the coupon codes in a bar that’s stuck to the top of the page. Now, with Divi’s Theme Builder, you’re able to automatically add such coupon code bar to products that are eligible for the coupon code.

In this tutorial, we’ll show you exactly how to do that. There are several parts to this tutorial, from setting up the coupon code to creating a separate product template for products in the discount category. You’ll be able to download the template’s JSON file for free as well! The overall style we’re using is based on the bold product page layout we’ve shared in the past.

Let’s get to it!

Preview

Before we dive into the tutorial, let’s take a quick look at the outcome across different screen sizes.

Desktop

coupon code bar

Mobile

coupon code bar

Download The Product Page Template for FREE

To lay your hands on the product page template, you will first need to download it using the button below. To gain access to the download you will need to subscribe to our newsletter by using the form below. As a new subscriber, you will receive even more Divi goodness and a free Divi Layout pack every Monday! If you’re already on the list, simply enter your email address below and click download. You will not be “resubscribed” or receive extra emails.

Tutorial Overview

  • Make sure you have Divi and the WooCommerce plugin installed on your website
  • In the first part of the tutorial, we’ll create a new discount product category
  • We’ll assign the eligible products to this new product category
  • Then, we’ll create a new coupon code and make sure the coupon code applies to the product category we created only
  • Inside the theme builder, we’ll create a new template for that particular product category
  • We’ll reuse the normal product page body for this template and add a top coupon code bar using Divi’s built-in options

1. Create New Discount Product Category

Go to Product Categories & Add New Discount Product Category

Start by installing the WooCommerce plugin on your WordPress website and add a new product category dedicated to all products eligible for the new discount. If you’re planning on using the coupon code on existing product categories, you can use those instead.

coupon code bar

2. Assign Products to New Discount Category

Edit Product

Then, open the products you want to include in the sale.

coupon code bar

Assign Products to New Discount Category

And include them in the new discount product category.

coupon code bar

3. Create WooCommerce Coupon Code

Go to Coupons & Add New Coupon

The next part of this tutorial handles creating a new coupon code. Go to your WordPress dashboard > Coupons > And click on ‘Create your first coupon’.

coupon code bar

Add Coupon Code & Coupon Data

Add the coupon code at the top and select the general settings you want to apply to your coupon code.

  • Discount code: Add discount code
  • Discount type: Percentage discount
  • Coupon amount: Add percentage
  • Coupon expiry date: Select date

coupon code bar

Add Usage Restriction

Then, move on to the usage restriction and make sure the coupon code works on products inside your discount product category only.

  • Product categories: Discount

coupon code bar

4. Add New Template for Discount Category

Add New Template

Once you’ve created the coupon code, it’s time to include it on the relevant product pages! To do that, go to the Divi Theme Builder and add a new template.

coupon code bar

Use On

Use this new template on the discount product category.

  • Use On: Product in Specific Product Category: Discount

coupon code bar

5. Reuse Global Product Page Body for New Template

Drag Product Template Body to New Template’s Body

You can reuse your regular product page template body by just dragging it over to your new template. In this tutorial, we’re using the bold product page layout we’ve created in another tutorial. You can download the layout’s JSON file in the blog post.

coupon code bar

6. Add Top Coupon Code Bar to New Template’s Body

Enter Body Template Editor

Once you’ve added the product page body to your new template, you can start editing it. The changes you make to this template will only appear on the product pages that are part of the discount product category.

coupon code bar

Add New Section to Top

Inside the template editor, the first thing we’ll do is add a new section to the top.

coupon code bar

Background Color

Open the section settings and change the background color.

  • Background Color: #e02b20

coupon code bar

Spacing

Remove all default top and bottom padding next.

  • Top Padding: 0px
  • Bottom Padding: 0px

coupon code bar

Animation

Complete the section settings by adding an animation.

  • Animation Style: Slide
  • Animation Direction: Down
  • Animation Duration: 1500ms
  • Animation Delay: 1000ms
  • Animation Starting Opacity: 100%
  • Animation Speed Curve: Ease-In-Out
  • Animation Repeat: Once

coupon code bar

Add New Row

Column Structure

Continue by adding a new row to the section using the following column structure:

coupon code bar

Sizing

Open the row settings and allow the row to take up the entire width of the section container.

  • Use Custom Gutter Width: Yes
  • Gutter Width: 1
  • Equalize Column Heights: Yes

coupon code bar

Spacing

Remove all default top and bottom padding next.

  • Top Padding: 0px
  • Bottom Padding: 0px

coupon code bar

Column 1

Spacing

Then, open the column 1 settings and add some top and bottom padding.

  • Top Padding: 25px
  • Bottom Padding: 25px

coupon code bar

Column 2

Background Color

Open the column 2 settings too and add a white background color.

  • Background Color: #ffffff

coupon code bar

Spacing

Add some custom top and bottom padding to this column as well.

  • Top Padding: 20px
  • Bottom Padding: 20px

coupon code bar

Border

And include some top left and right border radius.

  • Top Left + Top Right: 30px

coupon code bar

Add Text Module to Column 1

Add Content

The first and only module we need in column 1 is a Text Module. Enter some copy of your choice.

coupon code bar

Text Settings

Move on to the module’s design tab and change the text settings accordingly:

  • Text Font: Montserrat
  • Text Color: #ffffff
  • Text Size: 16px
  • Text Alignment: Center

coupon code bar

Add Text Module to Column 2

Add Coupon Code to Content Box

In the second column, add another Text Module with the discount code you’ve added in the first part of the tutorial.

coupon code bar

Text Settings

Change the module’s text settings as follows:

  • Text Font: Montserrat
  • Text Font Weight: Heavy
  • Text Color: #000000
  • Text Size: 19px
  • Text Alignment: Center

coupon code bar

Sizing

Then, modify the sizing settings.

  • Width: 50%
  • Module Alignment: Center

coupon code bar

Spacing

Add some bottom padding too.

  • Bottom Padding: 10px

coupon code bar

Border

And complete the module’s settings by adding a bottom border.

  • Bottom Border Width: 1px
  • Bottom Border Color: #333333

coupon code bar

7. Save Theme Builder Changes & View Result

Once you’ve completed the modified product page, you can save the template changes, exit the Theme Builder and view the outcome on the discount product pages!

coupon code bar

coupon code bar

Preview

Now that we’ve gone through all the steps, let’s take a final look at the outcome across different screen sizes.

Desktop

coupon code bar

Mobile

coupon code bar

Final Thoughts

In this post, we’ve shown you how to create a coupon code bar and allow it to automatically show up on product pages that are eligible for the coupon code in question. This is a great way to give extra incentive to visitors to buy your products. You were able to download the template JSON file for free as well! If you have any questions, make sure you leave a comment in the comment section below.

If you’re eager to learn more about Divi and get more Divi freebies, make sure you subscribe to our email newsletter and YouTube channel so you’ll always be one of the first people to know and get benefits from this free content.

Divi Marketplace

Are You A Divi User? Find Out How To Get More From Divi! 👇

Browse hundreds of modules and thousands of layouts.

Visit Marketplace
Divi Marketplace
Divi Cloud

Find Out How To Improve Your Divi Workflow 👇

Learn about the new way to manage your Divi assets.

Get Divi Cloud
Divi Cloud
Divi Hosting

Want To Speed Up Your Divi Website? Find Out How 👇

Get fast WordPress hosting optimized for Divi.

Speed Up Divi
Divi Hosting
Premade Layouts

Check Out These Related Posts

New Starter Site for AI (Quick Install)

New Starter Site for AI (Quick Install)

Posted on December 17, 2024 in Divi Resources

Divi empowers you to build the best websites possible, and now, Divi Quick Sites takes website creation to a whole new level. This revolutionary tool lets anyone, regardless of skill level, generate a complete website in under two minutes! Divi Quick Sites provides everything you need to launch...

View Full Post

5 Comments

  1. Interesting. Would like to play with this a bit and see if I can add the coupon bar to specific categories only.

  2. The title is certainly misleading, this is not dynamic. But it’s a clever idea, just expected something more like actual Dyanamic Content or something.

  3. Divi! one of the best tools for WordPress available right now, I’m waiting for the upcoming offer, i have more than two sites and i want to switch to Divi.

  4. Coupons are a really great way of adding value to a product or service. Thank you for another useful tutorial (explained really clearly) which I’ll be able to put into practice on a couple of sites.

  5. Lol, no way! I have just did this yestreday for a website I look after! I’m downloading yours now as its better!

Leave A Reply

Comments are reviewed and must adhere to our comments policy.

Join To Download Today