Code Snippets Archives - Divi Engine Boost the power of your Divi website Fri, 17 Nov 2023 12:40:54 +0000 en-US hourly 1 https://wordpress.org/?v=6.5.4 How to Customize a LearnDash Template in your Child Theme https://diviengine.com/how-to-customize-a-learndash-template-in-your-child-theme/ https://diviengine.com/how-to-customize-a-learndash-template-in-your-child-theme/#comments Fri, 11 Mar 2022 14:59:47 +0000 https://diviengine.com/?p=213990 The post How to Customize a LearnDash Template in your Child Theme appeared first on Divi Engine.

]]>

NOTE: This is an advanced post aimed at developers.

If you were struggling to figure out how to customize your LearnDash templates using your child theme, well, good luck!

Just Kidding!

It can be a pain to figure out how to customize your LearnDash templates with your existing Child Theme, we know this because we recently ran into this. Unfortunately, there are no real guides or documentation on how to customize your LearnDash templates, so we had to figure this one out, and thought we’d share.

Just follow along below and we’ll show you.

Steps to Customize a LearnDash Template

It is important to note that the steps might change depending on the LearnDash Theme you are using – but in most cases, all you’d need to do to customize your LearnDash theme is to change the name from ld30 to the name of whatever LearnDash Theme you are using.

Add LearnDash Folder

You’ll need to add a learndash folder to your Child Theme.

Add the Name

Next, you need to add the name of the Theme as a folder.

In our example, this will be ld30.

Add the File

Lastly, you need to add the file of the same name to your Child Theme.

Example 1

If you are overwriting: wp-content/plugins/sfwd-lms/themes/ld30/templates/lesson.php
The path in your child theme will be: wp-content/themes/child-theme/learndash/ld30/lesson.php

Example 2

If you are overwriting: wp-content/plugins/sfwd-lms/themes/ld30/templates/module/tabs.php
The path in your child theme will be: wp-content/themes/child-theme/learndash/ld30/module/tabs.php

And that is it, just add your styles and customizations there and you’ll be well on your way to learning how to customize your LearnDash templates.

The post How to Customize a LearnDash Template in your Child Theme appeared first on Divi Engine.

]]>
https://diviengine.com/how-to-customize-a-learndash-template-in-your-child-theme/feed/ 3
SNIPPET: Disable the New Full Site Front-End Editing For Divi https://diviengine.com/snippet-disable-the-new-full-site-front-end-editing-for-divi/ https://diviengine.com/snippet-disable-the-new-full-site-front-end-editing-for-divi/#comments Mon, 01 Nov 2021 11:11:52 +0000 https://diviengine.com/?p=209416 The post SNIPPET: Disable the New Full Site Front-End Editing For Divi appeared first on Divi Engine.

]]>

Soooo, have you folks heard about the new Full Site Front-End Editing For Divi? Everybody is talking about it and we can’t believe the sheer amount of features the team at Elegant Themes have released over the last month. Full Site Front-End Editing is another addition aimed at making us more efficient when building Divi sites.

Now here comes the but!

Not everybody is a big fan, and if you are an antiquated Divi user such as myself, you prefer things like the Classic Editor and that dusty odor extends to new things like the Full Site Front-End Editing For Divi. Elegant Themes has not added a setting to natively disable this feature, so we whipped up some CSS to remove it from the Front-End Editor, but before we look at that, let’s just quickly cover what this feature does.

 

What is Full Site Front-End Editing For Divi?

With the introduction of the Divi Theme Builder, we were finally given a space to create global layouts for various parts of our site like headers and footers. It was an unprecedented step towards greater efficiency for developers, but something was always missing, one could not edit these Theme Builder layouts on the front-end of our sites. We were always relegated to going through the back-end of our site to the Theme Builder section and then editing these layouts without seeing them as they would appear on the page.

Say hello to Full Site Front-End Editing For Divi, which solves this issue by allowing you to edit these Theme Builder layouts on the front-end as you would any other page. This is great as you can now see how it fits into your overall design and saves you time bouncing around, or as in my case, having 20 tabs open at any given time.

For more information on the Full Site Front-End Editing For Divi, check out the official post over at Elegant Themes.

 

Disable Full Site Front-End Editing For Divi

So as I mentioned before, maybe you are averse to change right now and want to cozy up to the idea of the new Full Site Front-End Editing For Divi and that is ok. With just a few lines of code, you can send this efficiency tool into oblivion.

Just follow the steps below, beat your chest, and claim your freedoms!

Head over to Divi > Theme Options > Custom CSS

Paste the code below in the Custom CSS box

Save

Disable the New Full Site Front-End Editing For Divi

Buh-bye Full Site Front-End Editing For Divi

Conclusion

Congrats, you did it. We understand that some of these new features are not always easy to get into at first, but we promise once you embrace them, that they will be a gamechanger for your efficiency….uh…game? You know what we mean.

Use this code as a breather but we encourage you to play with all the new Divi features as they come out and we will try to continue to release content that helps you on that journey.

We hope you found this post on how to Disable the New Full Site Front-End Editing For Divi helpful! We will be back soon with more valuable content.

Until next time 😁

 

The post SNIPPET: Disable the New Full Site Front-End Editing For Divi appeared first on Divi Engine.

]]>
https://diviengine.com/snippet-disable-the-new-full-site-front-end-editing-for-divi/feed/ 6
Highlight Links in the Divi Text Module with CSS https://diviengine.com/highlight-links-in-the-divi-text-module-with-css/ https://diviengine.com/highlight-links-in-the-divi-text-module-with-css/#comments Tue, 12 Oct 2021 12:40:54 +0000 https://diviengine.com/?p=208932 The post Highlight Links in the Divi Text Module with CSS appeared first on Divi Engine.

]]>

Having your text links highlighted can be a great way to get people exploring your website and let’s be honest if done right, can look pretty cool. You can Highlight Links in the Divi Text Module with CSS even if you are not a code ninja. You’ll see how with just a few lines of CSS code that you add a much more bespoke look to the links in the Divi Text module. 

Let’s take a look at what we will be building today.

Preview:

Bacon ipsum dolor amet anim esse tongue, ullamco voluptate pig nostrud sunt. T-bone pariatur bacon boudin aliquip, flank porchetta filet mignon jowl officia ea. Consectetur leberkas turkey ut, pork belly dolor drumstick. Leberkas alcatra in in doner pastrami, salami dolore voluptate pork chop. Pork belly tempor ea, turducken adipisicing ad bacon dolore. Laborum tenderloin ham kielbasa labore consectetur.

Labore est pastrami nulla boudin shoulder. In kevin drumstick commodo porchetta ribeye veniam boudin tri-tip meatloaf picanha pork belly landjaeger. Do id chislic venison cupidatat jowl pancetta. Sirloin picanha officia duis, deserunt shoulder nulla occaecat ham ground round in chicken consectetur aliqua. Chislic proident ut pig. Sint corned beef laborum pastrami alcatra elit pig in jerky ea tenderloin.

Video Tutorial

Table of Contents

Difficulty

Easy

Time

5 Minutes

Animate and Highlight Links in the Divi Text Module

Setting it Up

Preparing Our Text Module for the Animated Highlights

The first thing we need to do before adding the CSS that will highlight the links in our Divi Text module is to make sure we either already have a page with a Text Module containing some links, or we need to create one. If you do not, go ahead and quickly create a page and add a Divi Text module to the page and add some text with at least one link.

Text Module Settings > Advanced Tab > CSS ID & Classes > Add CSS Class de-highlights

Save

Adding the CSS Code

Transforming the Links into Animated Highlights

So the CSS we need to add here will look for the Divi Text module on the page that has the class de-highlights assigned which we did in the previous step, then apply the CSS to the <a> tags in the module. Just add that class to any text module where you want the CSS applied.

Add a Code Module

Paste the Code below in the Code Box between opening and closing <style> tags

Save

PRO TIP: If you wanted to add the highlight animation to all the <a> tags on the page, just delete all instances of the class de-highlights from the code you add here.

Polishing the Design

Changing the Colors

You can easily customize this CSS to highlight your links in the Divi Text module to fit the colors of your brand. You’ll see that the comments in the code show you exactly where to adjust the colors. For a quick guide, check below:

Text Color

Initial: Line 5
Hover: Line 17

Line Color

Initial: Line 6 Change the second linear-gradient color values (both) to your desired color
Hover: Line 6 Change the first linear-gradient color values (both) to your desired color

Look at them fancy highlighted links over there…

Changing your Divi site URL - The End

Conclusion

Today was a little shorter than usual, but as you can see, dynamite comes in small packages. If you blog often or create content with a bunch of links, this is a great way to make things just that little bit cleaner and easy to identify your linked content.

If you found this guide on how to Highlight Links in the Divi Text Module with CSS helpful, please consider subscribing to our Youtube Channel, and as always, we love hearing your thoughts and suggestions in the comments below.

Until next time!

The post Highlight Links in the Divi Text Module with CSS appeared first on Divi Engine.

]]>
https://diviengine.com/highlight-links-in-the-divi-text-module-with-css/feed/ 1
SNIPPET: 4 Styles for Your Divi Menu CTA Button https://diviengine.com/snippet-4-styles-for-your-divi-menu-cta-button/ https://diviengine.com/snippet-4-styles-for-your-divi-menu-cta-button/#comments Thu, 30 Sep 2021 21:09:27 +0000 https://diviengine.com/?p=208665 The post SNIPPET: 4 Styles for Your Divi Menu CTA Button appeared first on Divi Engine.

]]>

Copy & Paste todays Freebie Code Snippet for your Divi site.

It is FREEBIE FRIDAY and for this edition, we have 4 Styles for Your Divi Menu CTA Buttons that were lovingly crafted just for you!

These snippets work fantastic with this week’s tutorial on How to Add a CTA Button to the Divi Menu, so pick the button style you like, and get cracking!

Preview:

CTA Style 1
CTA Style 2
CTA Style 3
CTA Style 4

Using the Divi Menu CTA Button Styles:

Step 1) Decide Which Button Style you Like

Just scroll up to see all the styles again.

Step 2) Copy the Corresponding Style Code Below

With your style selected, scroll down to the style number and copy the CSS code and go paste it into the Custom CSS in Divi > Theme Options > Custom CSS

Step 3) Add the CSS Class to Your Divi Menu

Take note of the CSS Class for your button styles then head to Appearance > Menus and add the class to your button menu link.

For step-by-step instructions on how to do all this, check out our post on How to Add a CTA Button to the Divi Menu.

CSS Code for the Divi Menu CTA Button Styles:

Style 1: Full to Hollow Color Transition

Style 2: Skew to Straight

Style 3: Icon Button

Style 4: Gradient Flip

If you loved this FREE Snippet to Style Your Divi Menu CTA Button, you’ll love our other freebies. Click the link below to see other helpful tools to help you grow both your skills and business.

The post SNIPPET: 4 Styles for Your Divi Menu CTA Button appeared first on Divi Engine.

]]>
https://diviengine.com/snippet-4-styles-for-your-divi-menu-cta-button/feed/ 3
How to Reverse Loop Layout Columns in Divi Machine https://diviengine.com/how-to-reverse-loop-layout-columns-in-divi-machine/ https://diviengine.com/how-to-reverse-loop-layout-columns-in-divi-machine/#comments Fri, 24 Sep 2021 13:29:25 +0000 https://diviengine.com/?p=208494 The post How to Reverse Loop Layout Columns in Divi Machine appeared first on Divi Engine.

]]>

UPDATED: April 22nd, 2022

Today we have a quick Code Snippet for you that will allow you to Reverse Loop Layout Columns in Divi Machine. This is another Code Snippet that was inspired by a request that we received from one of our awesome customers, maybe it was you 😉

Basically, we are going to reverse the column order in our loop layout on an interval that we specify. This can mean that we will alternate the order of the columns for every 2nd, 3rd, or 4th loop, and so on, you get to decide! In our example today we will be alternating the column order for every second loop in our Divi Machine Archive Loop module and we’ll be doing all of this with some clever CSS.

Preview:

BEFORE
Divi Machine Loop Columns Before Reverse
AFTER
Divi Machine Loop Columns After Reverse

Video Tutorial

Let’s Talk CSS and :nth-child(n)

So like we mentioned, we want every second loop in our archive loop to reverse the order of the columns in that loop. That is heavy usage of the word loop and can get confusing, so definitely check out our support article on What Is The Custom Loop Layout to lift some of the fog on that topic.

To achieve this, we will need to convert every second loop to a flex layout, and then reverse the order by setting the flex-direction property to row-reverse. Sounds easy right? Well, it actually is because all we need here is 4 lines of IQ1000 CSS. But wait? How will my CSS be applied to only every second loop? Say hello to our little friend, Tony Mon:nth-child.

:nth What now? :nth-child‘s formal definition is as a structural pseudo-class which means that it is used to style content as it relates to its parent and sibling elements. Maybe you can now start to see how we would use this to select every second loop on the page and reverse those columns. We are not going to get too much into it for this post, but let me quickly explain How to Reverse Loop Layout Columns in Divi Machine using it.

:nth-child(n) takes an argument (n) which can be used in two ways.

:nth-child(2)

We can replace the (n) with an integer number which will literally count out the loops until it reaches the second loop as used in this example, then apply the relevant CSS to ONLY that loop. If you changed that (2) to (7), it would count out the loops until it reaches the seventh loop, and play the CSS and so forth.

:nth-child(2n)

Now when we prefix the (n) with an integer number, we are telling it to count out the loops until it reaches the second loop, apply the relevant CSS, BUT THEN, it restarts the count and continues to the page applying the CSS to EVERY second loop. Again, if you change the (2n) to (7n), it will apply the CSS to every seventh loop.

Now that we have theory lesson over and done with, let’s get to the code!

Adding the CSS Code

To add the code, we have two options, depending on the scope of where you want the CSS applied.

If we want the code to be applied across our entire site and to all the Divi Machine Archive Loop Modules, then we would add it to the DIvi Theme Options.

Or if we would like it to only be applied to a single page, we would add it to a Code Module on that page.

Entire Site

Go to Divi > Theme Options > Custom CSS

Paste the Code below in the Custom CSS Box

Save

Single Page

Add a Code Module

Paste the Code below in the Code Box between opening and closing <style> tags

Save

Much of this will look familiar now. We select our Archive Loop Module, then specify the 2nd Loop, and apply the CSS.

Tutorial Update – Reversing Margins

UPDATED: April 22nd, 2022

Sometime you may have margin added to your columns that are uneven, which means that you would need to reverse that uneven margin also. Margin can be added through the margin properties on columns, but also through the gutter between the columns, so you would need to inspect the page to determine whether there is uneven margin applied if you are unsure.

 

How to inspect the page for uneven margin?

To inspect the page all you need to do is right-click the loop where you want to reverse the columns, then click on inspect.

This will show you something similar to the image below, which is where you will see if margin is applied unevenly, and as you can see here, there is a margin-right of 5.5%.

This means that we need to apply some additional CSS.

Inspect page for margin

Adding the additional CSS

Entire Site

Go to Divi > Theme Options > Custom CSS

Paste the Code below in the Custom CSS Box

Save

Single Page

Add a Code Module

Paste the Code below in the Code Box between opening and closing <style> tags

Save

All done! Now repeat after me…

Changing your Divi site URL - The End

Conclusion

:nth-child(n) is a super powerful CSS structural pseudo-class that can help you create all sorts of dynamic styles. Today it showed us How to Reverse Loop Layout Columns in Divi Machine, but that is just the beginning. Maybe we’ll look at making some other tutorials using this if you guys liked it 😁

If you don’t yet have a Divi Machine License, definitely check out the Product Page, you’ll see how it is a game-changer for creating more dynamic websites using the power of custom post types and advanced custom fields.

 

The post How to Reverse Loop Layout Columns in Divi Machine appeared first on Divi Engine.

]]>
https://diviengine.com/how-to-reverse-loop-layout-columns-in-divi-machine/feed/ 2
How to Add a Filtered Portfolio Triggered by any Divi Module https://diviengine.com/how-to-add-a-filtered-portfolio-triggered-by-any-divi-module/ https://diviengine.com/how-to-add-a-filtered-portfolio-triggered-by-any-divi-module/#comments Tue, 07 Sep 2021 14:43:50 +0000 https://diviengine.com/?p=208022 The post How to Add a Filtered Portfolio Triggered by any Divi Module appeared first on Divi Engine.

]]>

Enhancing some of the stock Divi modules is easier than you think, with just a little bit of code, we can make some pretty awesome changes to give your Divi site more of a custom feel that wows your clients! In this week’s tutorial, we are going to show you How to Add a Filtered Portfolio Triggered by any Divi Module using jQuery and CSS.

You can use the tutorial to have the stock Divi Filterable Portfolio Module filter the Projects by clicking on a Blurb Module, Text Module, or any other Divi Module you decide. We will also talk about the code a little so that you can even further customize the way your Filterable Portfolio Module works and is displayed.

Video Tutorial

Adding Projects to Your Portfolio

The first thing we need to make sure of is that you already have some projects assigned to categories on your Divi site. You might already have them set up, but just in case you do not, follow the steps below to get set up for the rest of the tutorial.

Create Project Categories

Head over to Projects > Categories > Then Add Your Categories.

Make sure to make a note of the Category Slugs, because we will use this in our code and layout.

WooCommerce Checkout with No Order Bump

Add Some Projects

Head over to Projects > Add New1.

Add a Title2, Description3, and Featured Image4.

Assign a Category5.

Publish6 the Portfolio.

Repeat this process until you have about 4 Portfolio items for each category.

WooCommerce Checkout with No Order Bump

Create and Style Your Filter Trigger Modules

So we need a place where we will display this unique Filtered Portfolio Triggered by any Divi Module. so you can either use an existing page that you have created, or you can create a new one from scratch. Whichever you choose, we suggest you place it in it’s own section on said page.

Add a Divi Filterable Portfolio Module

In a new single column row, add a Filterable Portfolio module.

On the Design Tab, set the Layout Style to Grid.

Head to the Advanced Tab and add the CSS Class divi-engine-filter, which we will be using in our code.

Under Custom CSS, scroll down to Portfolio Filters, and add the line display: none; as we are busy replacing that with our very own fancy filters.

You can style the rest of the module however you like.

Add a Divi Text Module

In a new three column row, add a Text module in the first column.

Type the Name of the first Category you created earlier in the Body.

Head to the Advanced Tab and add the CSS ID which is the same as your first category slug , this was filter-item-1 in our example, but your will be whatever you set it to.

You can style the rest of the module however you like.

Now make 2 copies of this text module and drag each one into its own column.

For each copy, change the text in the body to reflect the Category name, and change the CSS ID to the appropriate slug for that Category.

Open the Settings for the 3-Column Row and on the Advanced Tab, add the CSS ID custom-grid-control. Our jQuery will wait to see if we click on any of the filters in this row.

WooCommerce Checkout with No Order Bump

Add the Custom jQuery

Now it gets interesting, we are going to add some jQuery which will wait for us to click one of the trigger modules that we created in the previous steps, and then filter by that Category. We will also use some magic to add a CSS class that will indicate which filter is active.

Add a Code Module

Add a Code Module below your Filterable Portfolio Module.

Copy and Paste the code below between opening and closing <script> tags in the code module.

You need to modify the code on lines 4, 5, and 6 to match your Category slugs if they are different from ours.

NOTE: When adding things like code modules, we recommend that you give it an Admin Name so that they are easy to spot when editing your pages. We called ours “Portfolio jQuery Code”, that way we know exactly where we need to make any edits if need be.

WooCommerce Checkout with No Order Bump
NOTE: Make sure the class matches the module you are using, for example a blurb would be .et_pb_blurb

Add the Custom CSS

To make sure that everything works correctly and is displayed as we intend to, we need to use some CSS to pull it all together.

Add a Code Module

Add a Code Module below your jQuery Code Module.

Copy and Paste the code below between opening and closing <style> tags in the code module.

WooCommerce Checkout with No Order Bump
NOTE: Make sure the class matches the module you are using, for example a blurb would be .et_pb_blurb

And that is it, if you now publish and view this page on the frontend, you should have a shiny new filterable portfolio that filters when you click on the text modules.

WooCommerce Checkout with No Order Bump

You can modify the code in the CSS Code Module to change various visual elements.

For example, if you changed the width property in the .divi-engine-filter class from 25% to 33.3%, you will have 3 columns instead of 4 columns.

You can also make changes to the .de-active class to change the way you indicate which filter is selected.

For more on that, or if you get stuck, definitely check out the video at the top of this post.

You can also download a working version of this layout by checking out this post -> FREE Filterable Portfolios Layouts for Divi.

Filter, ENHANCE!

Changing your Divi site URL - The End

Conclusion

We really hope this guide on How to Add a Filtered Portfolio Triggered by any Divi Module will be a great asset to your workflow in creating some amazing websites. Be sure to check out the video at the top for a little more details and an explanation of the code we used. It can also be helpful if you get stuck.

Until next time, folks!

The post How to Add a Filtered Portfolio Triggered by any Divi Module appeared first on Divi Engine.

]]>
https://diviengine.com/how-to-add-a-filtered-portfolio-triggered-by-any-divi-module/feed/ 7
How to Add a WooCommerce Discount Automatically at Checkout (2 Methods) https://diviengine.com/how-to-add-a-woocommerce-discount-automatically-at-checkout-2-methods/ https://diviengine.com/how-to-add-a-woocommerce-discount-automatically-at-checkout-2-methods/#respond Tue, 31 Aug 2021 20:12:28 +0000 https://diviengine.com/?p=207888 The post How to Add a WooCommerce Discount Automatically at Checkout (2 Methods) appeared first on Divi Engine.

]]>

Coupons are a great way to convert some visitors into customers, but what if you wanted to Add a WooCommerce Discount Automatically at checkout without needing your customer to enter a code? Or maybe you want some tiered deals based on the number of items in your prospective buyer’s cart.

In this tutorial, we are going to show you 2 methods that will allow you to either have a pre-made WooCommerce coupon automatically applied to the cart, or have different discounts applied based on predetermined criteria. We will include the code snippets that get the magic done, and talk a little about how you can customize that code to suit your needs.

Video Tutorial

Why Add a WooCommerce Discount Automatically at Checkout?

WooCommerce natively comes with a feature that allows you to create coupons and make them available to your visitors, but the functionality unfortunately is a bit limited if you wanted to do more complicated things. There might be situations where it makes sense to have a free shipping coupon be applied automatically, or maybe you want to offer better discounts as your users add more things to their cart.

It is no secret that folks that shop online are on the lookout for the best deals, so why not build that right into your site. This gives you the ability to display a nice banner at the top of your page announcing price breaks or other offers which could encourage them to spend more. This deepens engagement and obviously impacts your bottom line in a very attractive way.

Doing away with coupon codes having to be entered will also show your customers that you care which in turn will increase their LTV. If you are willing to automatically add discounts for purchases that meet certain criteria, you are probably willing to go the extra mile for them in other ways.

Adding a Coupon Code Automatically based on Minimum Spend

The first method we will be looking at will add a coupon code you created to your cart automatically. A perfect use case for this would be if you wanted to offer free shipping if customers spent over $100. The choice is really yours, and I will show you how to add the code below to your site in a few simple steps, but first, let’s create our free shipping option and coupon code.

Free Shipping Option

  1. Go to WooCommerce > Settings
  2. Click on Shipping
  3. Click on your Shipping Zone
  4. Click Add Shipping Method
  5. Select Free Shipping
  6. Save it by clicking Add Shipping Method then edit it
  7. Click the Free Shipping Requires… drop-down > Select A Valid Free Shipping Coupon
  8. Save Changes
WooCommerce Checkout with No Order Bump
WooCommerce Checkout with No Order Bump
WooCommerce Checkout with No Order Bump

Free Shipping Coupon Setup

  1. Go to MarketingCoupons and create a new coupon
  2. Enter the code (we used “freeshipping“) you want people to enter in the Title field (this should be less than 8 characters)
  3. Select Fixed Cart Discount from the Discount Type drop-down
  4. Tick the Allows Free Shipping option
  5. Click Publish
WooCommerce Checkout with No Order Bump

Ok, we have everything set up now, all we need to do is add the code to the functions.php file to get it working. For this tutorial, we will edit the functions.php in our child theme by using the Theme Editor baked into WordPress.

Add the Code for Adding a Coupon Code Automatically based on Minimum Spend

  1. With the code below copied to your clipboard, head to Appearance > Theme Editor
  2. Select the functions.php file on the right
  3. Paste the copied code right above the closing PHP tag.
  4. Update File

NOTE: If you are not using a child theme, we strongly suggest you create one. You can follow our guide on How to set up a Divi Child Theme with Dynamic CSS which will help you do so.

WooCommerce Checkout with No Order Bump

Adding a Discount Automatically Based on the Number of Items in the Cart

Our second method offers another take on automatically adding a discount to the cart at checkout. With this method we will not be creating a coupon code ahead of time, instead, we will offer a calculated discount based on the number of items in the cart.

If there is 1 item in the cart the discount is 10%, if there are 2 items the discount is 15%, and when there are 3 items the discount is 25%.

To accomplish this, we will follow the same steps we did before where we added some code to the functions.php file in our child theme.

Add the Code for Adding a Coupon Code Automatically based on Minimum Spend

  1. With the code below copied to your clipboard, head to Appearance > Theme Editor
  2. Select the functions.php file on the right
  3. Paste the copied code right above the closing PHP tag.
  4. Update File
WooCommerce Checkout with No Order Bump

Sweet sweet automation…

Changing your Divi site URL - The End

Conclusion

That wasn’t so bad? Was it? Learning How to Add a WooCommerce Discount Automatically at Checkout is something that will sharpen your skills as a Divi and WordPress developer and offer your clients a new option when building their online stores. Customizing this code to extend or change the functionality is also super easy, so definitely check out the video at the start of this post to get into how you would do that.

Hopefully, this content was helpful, so if you like it, please subscribe to our youtube channel and let us know your comments and feedback below in the comments.

The post How to Add a WooCommerce Discount Automatically at Checkout (2 Methods) appeared first on Divi Engine.

]]>
https://diviengine.com/how-to-add-a-woocommerce-discount-automatically-at-checkout-2-methods/feed/ 0
How to add attention-grabbing pure CSS Animations to your Divi Modules https://diviengine.com/how-to-add-attention-grabbing-pure-css-animations-to-your-divi-modules/ https://diviengine.com/how-to-add-attention-grabbing-pure-css-animations-to-your-divi-modules/#comments Tue, 22 Jun 2021 16:36:47 +0000 https://diviengine.com/?p=205845 The post How to add attention-grabbing pure CSS Animations to your Divi Modules appeared first on Divi Engine.

]]>

In this week’s tutorial, we are going to show you how you can add attention-grabbing pure CSS Animations to your Divi modules. We will work together to add the CSS code to your Divi install, customize the CSS to change things like the duration of the CSS animations, and more.

This might sound complicated, but I promise you’ll be a pro in no time. Check out the preview below to have a quick look at what we will be creating.

COMPLEXITY

Easy

TIME

10 Minutes

ASSUMPTIONS

  • Basic knowledge of Divi and WordPress.
  • Divi and your Child Theme are already installed and configured.

 

VERSIONS

Divi 4.9.7

Preview:

Add attention grabbing pure CSS Animations to your Divi modules

Why add attention-grabbing pure CSS Animations to your Divi modules?

Because they are AWESOME! That is why.

Thank you for coming to my TED Talk.

Jokes. Mostly. Divi already comes with 7 stock animations that are super simple to use if you want to create some basic animations, but what do you do when you want something more complex and unique? You hit up the Divi Engine blog of course!

With more complex animations you can draw the user’s attention to certain parts of your page like a buy button, maybe a sale you have going on, or maybe you just want to add some creative flair.

In this tutorial, we are going to show you how to add attention-grabbing pure CSS Animations to your Divi modules that accomplish pretty complex effects by utilizing keyframes. Don’t know what keyframes are? Think of them as different styles, positions, or shapes applied to your Divi module over a specific time period. This time period can be broken up into percentages (or waypoints) so that your Divi module can have different states at different times within that specified period.

What are CSS keyframes?

CSS Keyframes definition by the Mozilla team  ⬆️

Basic Anatomy of CSS Animations and Keyframes

I just want to spend another second on CSS Keyframes before diving into how to add attention-grabbing pure CSS Animations to your Divi modules because you can do some cool things if you understand what they do better.

Let’s take a look at the code below:

animation: colorchange 4s infinite;

So, in that code, we have a class that declares our animation. It will use the keyframes defined in “colorchange”, the entire animation will last 4 seconds, and it will repeat an infinite number of times.


@keyframes colorchange {

0% {background-color: red;}

25% {background-color: green;}

75% {background-color: blue;}

100% {background-color: yellow;}

}

On line 5 we declare the set of CSS Keyframes which we also used on line 2 where we declared our animation. Moving to lines 6 to 9, the percentages represent a percentage of our 4-second animation and the value of a CSS property at that time.

Can you guess what happens if you add this code to a Divi module?

You’re right! At 0 seconds, the module with that “.de-colorchange” class assigned will have a red background, between second 0 and second 1, it will fade to green, between second 1 and second 2, it will fade from green to blue, and so forth. In the end, the animation will start over.

Granted, this is a very simple example, but how cool is that? Are those gears in your head turning yet?

Now that we have a better idea of how CSS animations work, let’s look at how to add attention-grabbing pure CSS Animations to your Divi modules.

How to add attention-grabbing pure CSS Animations to your Divi modules

Armed with some basic knowledge of CSS animations it is time to add some gorgeous CSS animations we crafted for you to your Divi site. We put together 3 animations we thought were pretty awesome, and we hope so do you. All you need to do is choose the animation you want to add, copy the code, then follow along with the tutorial.

You can follow along with the video, or you can follow the text instructions below.

Our 3 CSS Animations to choose from for this Tutorial:

Divi Engine

Focus-In Animation

This is a very cinematic animation that would work great as a title reveal on a creative site for something like a production company, or maybe you just feel like getting a little fancy, do you 🙃

NOTE: This CSS Animations looks and works best when it is centered on the page.

Divi Engine

Text Pop-Up Animation

This makes for another great animation that literally looks like it is jumping off the page. It would work fantastic for a title or maybe just some statement you want to impressive you visitor.

Attention Wobble Animation

Nothing like a good wobble to grab the attention of your visitors, this is my go-to for reminding them that there is a call to action here. This works great for buttons intended to draw the user in. The slight wobble is subtle and draws the eye every few seconds.

NOTE: This CSS Animations looks and works best when it is centered on the page.

Video Tutorial

Text Instructions

If you prefer to quickly copy and paste the text and settings for this tutorial, please scroll down and you will see everything as it relates to the steps found in the video tutorial.

Step1) Select the CSS Animation you want to add to your Divi module

Click here or scroll up to our 3 CSS animations and copy the code below the one you’d like to give a spin.

Step 2) Add a Code Module and Paste the Code

Navigate to the page where you will add the CSS animation to your Divi module.
Add a code module anywhere on the page.
Open the code module and paste the CSS code between opening and closing style tags.

Paste Divi CSS Animation code here

Step 3) Add the CSS class to your Divi Module

Copy the CSS class in for the CSS animation you want to add to your Divi module.
Open the settings for the Divi module which you want to animate.
Head over to the advanced tab.
Past the class (without the preceding . ) into the CSS class field.
Save your work!

Divi CSS Animation Class

NOTE: Don’t be alarmed if the animation you chose does not loop as they do in the previews because we did that intentionally to demonstrate the animations. Some animations would be overkill if they looped in the infinity. That said if you would like to loop the animation infinitely all you need to do is add infinite in the animation declaration. More on how to do that over here.

How awesome are you? You did it!

pure CSS Animations to your Divi modules

Conclusion

When you add attention-grabbing pure CSS Animations to your Divi modules, you say no mediocrity, not today! With just a tiny little bit of new knowledge and practice, you are on your way to stop making that Divi site look like a Divi site. There are plenty of resources online to find some awesome CSS animations, just check out Codepen for some inspiration, or create your own from scratch over at CSS Animate.

The post How to add attention-grabbing pure CSS Animations to your Divi Modules appeared first on Divi Engine.

]]>
https://diviengine.com/how-to-add-attention-grabbing-pure-css-animations-to-your-divi-modules/feed/ 1
Snippet: Display the Product Title & Price in the Divi WooCommerce Shop Module with CSS & jQuery https://diviengine.com/snippet-display-the-product-title-price-in-the-divi-woocommerce-shop-module-with-css-jquery/ https://diviengine.com/snippet-display-the-product-title-price-in-the-divi-woocommerce-shop-module-with-css-jquery/#comments Mon, 10 May 2021 20:56:17 +0000 https://diviengine.com/?p=71412 The post Snippet: Display the Product Title & Price in the Divi WooCommerce Shop Module with CSS & jQuery appeared first on Divi Engine.

]]>

COMPLEXITY

Easy

TIME

10 Minutes

ASSUMPTIONS

  • Basic knowledge on Divi and WooCommerce.
  • Divi and WooCommerce are already installed and configured.
  • You have some products with assigned categories in WooCommerce.

 

VERSIONS

Divi 4.9.4
WooCommerce 5.2.2

So we’ve all seen those Shopify and SquareSpace product cards that show you the Product Title and Product Price as a cool overlay when you hover over them. Well, in this tutorial I’m going to show you how to create a Product Title and Price Overlay for your Shop Page in Divi and WooCommerce using some CSS and jQuery. It is going to look great, and your clients will love this option.

Why add the Product Title and Price as an Overlay to the Divi Shop Module?

So, let’s ignore the fact that this Divi overlay looks awesome on our WooCommerce loops, there is a deeper reason than just eye candy. Doing this focuses the users’ attention on the product image which in turn creates value and attachment before they know the price. Psychologically we have now primed our user to make the purchase even before the price is revealed. This is a great tool for products that have a greater visual impact such as art or other high-end products.

Additionally, it adds a layer of interactivity for the user which further engages them on the page. The more engaged, the more likely you are to convert with your Product Title Overlay on your Divi WooCommerce Shop Module.

Now feel free to follow along with the video, or skip to the text instructions at the bottom.

Preview:

How to create a Product Title and Price Overlay for your Shop Page in Divi and WooCommerce

Video Tutorial

Text Instructions

If you prefer to quickly copy and paste the text and settings for this tutorial, please scroll down and you will see everything as it relates to the steps found in the video tutorial.

Step 1) Create a new Page and add a Divi Shop Module

Add a Single Column Row

Add a Shop Module

Shop Module

Design Tab

Overlay

Overlay Icon Color: #0fe5a8
Overlay Background Color: rgba(84,48,206,0.75)

Title Text

Title Font: Poppins Title Font Weight: Semi-Bold Title Font Style: Uppercase Title Text Alignment: Centered Title Text Color: White Title Text Size: 18px Title Text Shadow: Option 1

Price Text

Price Font: Poppins Price Font Weight: Light Price Text Alignment: Centered Price Text Color: White Price Text Size: 18px Price Text Shadow: Option 1

Step 2) Add jQuery Code

Add a Code Module below the Shop Module

Code Module

Content Tab

Text

Code: Copy and Paste the text below into this box

PRO-TIP: To learn more about jQuery detach, check out the documentation.

Step 3) Add CSS Code

Add a Code Module below the jQuery Code Module

Code Module

Content Tab

Text

Code: Copy and Paste the text below into this box

Step 4) Add the CSS Class to the Shop Module

Let’s go back to our Divi Shop Module and head to the Advanced Tab

Shop Module

Advanced Tab

CSS ID & Classes

CSS Class: divi-engine-custom-overlay

All done!

Divi Engine High Five

Conclusion

That was super easy, right? Adding a Product Title and Price to your overlay in Divi WooCommerce couldn’t have been easier. Now you can go and take it a step further and modify the code to change the position of the Divi WooCommerce Product Title or Text, or you can use it as is. Things like this give you another tool in your belt and another option for your clients to help differentiate their site from the competition. For another great tutorial on adding functionality using jQuery, check out our post on How to add a CSS class to Divi on scroll with some real case examples.

Thanks for checking this Tutorial out and we will catch you in the next one!

The post Snippet: Display the Product Title & Price in the Divi WooCommerce Shop Module with CSS & jQuery appeared first on Divi Engine.

]]>
https://diviengine.com/snippet-display-the-product-title-price-in-the-divi-woocommerce-shop-module-with-css-jquery/feed/ 3
Snippet: How to add a CSS class to Divi on scroll – with some real case examples https://diviengine.com/snippet-how-to-add-a-css-class-to-divi-on-scroll/ https://diviengine.com/snippet-how-to-add-a-css-class-to-divi-on-scroll/#respond Tue, 20 Apr 2021 03:00:49 +0000 https://diviengine.com/?p=70245 The post Snippet: How to add a CSS class to Divi on scroll – with some real case examples appeared first on Divi Engine.

]]>
Divi is a fantastic tool for rapidly building websites that look and feel amazing, but sometimes there is just this one awesome thing you see on another website that Divi might not be capable of doing yet.

Enter jQuery. jQuery is a lightweight Javascript library included with every Divi install that helps simplify implementing common Javascript tasks with very little code. This coupled with some of the other Javascript libraries included with Divi, really opens the door to a ton of creative posibilities.

Don’t worry if this sounds complicated, in this post we are going to walk you through an overview of a piece of jQuery code, and then show you two examples of how you can start writing your own creative jQuery functions that are ready to wow your clients.

So, let’s start by taking a look at a few ways we can include jQuery code into our Divi website.

How to add some jQuery code to Divi

There are technically 3 ways to add jQuery code to Divi, but we will only be covering the 2 most common methods here but will mention the 3rd. The method you choose will depend on where you would like the code to run.

Divi Integration Tab

This is where you would add your jQuery code if you want it on every page throughout your website. An example of this might be if you wrote a function that changed the background color of your site header as the user scrolls through a page.

To find the Integration Tab you browse to your Divi Options page, then click on the Integration Tab. The code will be placed between open and closing <script> tags inside the <head> of your site.

Divi Theme Integration Tab

Divi Code Module

The code module is great when you are adding some jQuery that will only impact a single page on your site. The example we will cover is having fixed blurbs appear and disappear on screen as we scroll up and down a page. You can add the code module to any row on the page your want the jQuery to be executed on. Similar to the integration tab, this code needs to be placed between open and closing <script> tags inside the code module.

Divi Theme Code Module
Divi Theme Code Module Settings
NOTE: The third way to add some jQuery is to add your code to a Javascript JS file and adding it to your child theme. You would then also need to enqueue this script in your functions.php file. More on that in this article by the Elegant Themes team.

Quick overview of a jQuery function

Let’s take a look at some jQuery code that will add a class to an element once the user has started scrolling.

<script> </script>

These are always required to “open” and “close” any Javascript or jQuery code that you enter into either the Integration Tab or Code Module. It just tells the browser that you are about to write some code. The “type=“text/javascript” is just us telling the browser that this is Javascript code. This is required.

jQuery(document).ready(function( $ )

This basically means that our code will only run once the page Document Object Model (DOM) is ready for JavaScript code to execute. This is required.

function check_from_top_de()

Now we are getting to some actual custom code. This is where we create our function, the piece of code that will execute to do something cool on our site. We named our function check_from_top_de, because we are going to see how far the user has scrolled then do something, but you can name this whatever you want.

var scroll = $(window).scrollTop();

We have created a variable called scroll which gets assigned the distance that we have scrolled from the top of the page. This value gets returned in pixels which we can then use to apply some logic to add our class to our target selector.

if (scroll >= 300)

If the user has scrolled down the page 300 pixels or more

$("#your-target-element").addClass("class-to-be-added");

So first we point out (or select) which element we want the class to be added to, then we tell it the class name that we are adding. You would replace those with your own selectors and classes, but you get the idea.

else

If the user has not scrolled down 300 pixels or more, we want to do something else.

$("#your-target-element").removeClass("class-that-we-added");

We are going to remove the class we added if the user scrolls back up on the page.

check_from_top_de();

This runs our awesome function that we just coded as soon as the browser is ready to run code. Remember, we gave our function the name check_from_top_de, so enter your function name if you used a different one.

$(window).scroll(function()

If the user is busy scrolling, we also want to check how far they have scrolled, so we need to run our function as the user scrolls.

check_from_top_de();

Our function will be run if the user is detected scrolling on the page.

Are you feeling like a coder yet? You should, because this is some valuable information that will have you adding jQuery to your Divi site in no time. But now, how do we apply this practically on a site? Well, we are going to show you 2 applications of adding jQuery to Divi which should get your gears turning on other ways you can use this awesome new skill you have.

Practical applications of adding jQuery to your Divi site

Up next is two examples with code of using what we just learned to add some jQuery to your Divi site.

Changing the site header color on scroll

In this example, we wrote a function that changes the background color of our site header as the user scrolls through a page.

 

Preview:

Adding jQuery to Divi Example 1
Taking what we learned, we targeted the main header on our page, then changed the background color for that header once we have scrolled 300 pixels down the page. Since we want this to happen on all of the pages on our Divi site, we will add the code to the Integration Tab of the Divi Theme Options.

Take a look at the code below, then we will briefly cover what you need to do to add this to your site.

You can copy and paste the code above into the Integration Tab found inside your Divi Theme Options. Make sure to place it inside the <head> of your site.
$("#main-header").addClass("change-bg-color") This code is going to look for the #main-header element on our site and then add the class “change-bg-color” to that element. This CSS class is what will handle changing the color. You can call this class anything, just remember, it is good to use descriptive names.
$("#main-header").removeClass("change-bg-color") We want to restore the original color of the header when the user has scrolled up, so best to remove the class that changed the color.
With our jQuery code in place, we need to add a very tiny bit of CSS. Let’s take look at the code.
You can copy and paste the code above into the Custom CSS box found inside your Divi Theme Options.
.change-bg-color {
background-color: springGreen!important;
}
This code is pretty self-explanatory, we are just changing our background to “springGreen”. We added the !important operator to override any other colors assigned to the header background
Now when you save and reload your site, you should see the color changing when you scroll down and return to the original color when you are at the top of the page.

You can do so many other things by simply adding CSS classes to elements. This should really get the gears turning. With just one line of CSS we can even change the logo on scroll.

Add the following line of code below the CSS you just saved into the CSS box in your Divi Theme Options.

.change-bg-color #logo {
content: url('https://your-image-url/logo.png'
}
This single line of code will select the #logo in the element you added the .change-bg-color class to, in this case our #main-header. We then change the URL to that logo image to the one we want to display on scroll. Check out the awesome result below.
Divi jQuery logo swap
NOTE: Firefox can sometimes be temperamental with the CSS that changes the logo image. For a full-proof tutorial on how to change the header logo on scroll check out our article on How to change your logo on scroll in the Divi theme.

Making fixed blurb modules appear and disappear on scroll

For the second example we made some cool blurbs that fade in as you scroll over three fullwidth header modules, then fade out again as you scroll up.

 

Preview:

Adding jQuery to Divi Example 2
Here we used a code module because we are only adding the jQuery to this Divi page, so it would be unnecessary to add it throughout our entire site by using the Integration Tab. This example also uses Waypoint.js, a Javascript library that helps with triggering events as the user scrolls, which is also included in all Divi websites.

Take a look at the code below, then we will briefly cover what you need to do to add this to your site.

You can copy and paste the code above into a Code Module, but if you use this code exactly as is, you need to do a few things first.

 

    1. Add 4 modules/rows/section on the page that will trigger our waypoint code
    2. Add #start-top to the first element, and #module-one, #module-two, #module-three to the subsequent elements
    3. Create a 3-column row at the bottom of your page and add a blurb to each row
    4. Set the “position” setting for this row to “fixed” and “z-index” to “9”
    5. For the blurbs, give the first blurb assign #one, second #two, third #three and add “display: none;” to the “main element” box in the custom CSS
$('#module-one').waypoint(function() This is telling the Waypoint.js library which module we are watching for the scroll.
$('#one').fadeIn(); Here we are telling Waypoint.js that we want the element selected by #one to be faded in once #module-one has been scrolled into view.
{offset: '25%'}); Lastly, the offset checks how far we need to have scrolled from the top of the window to execute the code in our waypoint. This can be expressed in either a percentage or pixels. We went with 25%.

Conclusion

Adding jQuery to your Divi site is a powerful tool that now firmly sits on your belt. We only scratched the surface on what is possible when using jQuery and Divi together, but hopefully, this was helpful in showing what is possible. Keep an eye out, because we intend to release some more posts about adding features and effects to your Divi sites with the power of jQuery.

The post Snippet: How to add a CSS class to Divi on scroll – with some real case examples appeared first on Divi Engine.

]]>
https://diviengine.com/snippet-how-to-add-a-css-class-to-divi-on-scroll/feed/ 0
Snippet: Adding a Divi WooCommerce Add-to-Cart Icon Button on Shop Pages https://diviengine.com/snippet-adding-a-divi-woocommerce-add-to-cart-icon-button-on-shop-pages/ https://diviengine.com/snippet-adding-a-divi-woocommerce-add-to-cart-icon-button-on-shop-pages/#comments Fri, 02 Apr 2021 06:04:53 +0000 https://diviengine.com/?p=70437 The post Snippet: Adding a Divi WooCommerce Add-to-Cart Icon Button on Shop Pages appeared first on Divi Engine.

]]>
One question we often get is how does one do some fancy things with Add-to-Cart buttons. Or, more specifically, how do I make the button just an icon that is displayed next to the quantity field on the shop pages of my Divi WooCommerce site. Well, we are back again with an awesome code snippet you can use to add a creative Add-to-Cart Icon Button right next to the quantity field for your Divi WooCommerce site.

Let’s take a look at what the snippet does exactly.

Preview:

Divi WooCommerce Add-to-Cart Icon Button with Quantity
Pretty cool stuff, right? We can see that we will be adding the quantity field to our Divi WooCommerce shop page and then adding an Ajax-powered Add-to-Cart Icon Button right next to it.

Now that we know what it will look like, let’s take a look at the code you’ll be adding to make this magic happen.

functions.php

Copy and paste this code into the functions.php file of your child theme. Be sure to place it between the PHP tags.

NOTE: Be careful editing the functions.php file as it is easy to break your site if you do not know what you are doing. Also, make sure you are using Divi child theme. If you are not using one, download one for free that can be found in this post on How to set up a Divi Child Theme with Dynamic CSS.

Divi Settings Custom CSS

Copy and paste this code into the Custom CSS box in the Divi Theme Settings.

PRO-TIP: Feel free to play around with the CSS to change things like the color and hover effects of the button.

BodyCommerce Users

Because of the way BodyCommerce works, we need to use some CSS that looks a little bit different. Please use the CSS below instead of the CSS above if you are using BodyCommerce.

Boom, all done! If you browse to your shop page now, you will see both the quantity fields and new add-to-cart icon buttons added to the page.

Conclusion

That was a rather large and awesome change with very little code. We hope you found this snippet helpful, and if there are any other topics you would like us to cover, please leave a comment below.

Until next time!

Order Another fantastic way to enhance your Divi WooCommerce sites is to use BodyCommerce. BodyCommerce literally has 100’s of customizations on both front and backend hand crafted to make your sites stand out and convert.

The post Snippet: Adding a Divi WooCommerce Add-to-Cart Icon Button on Shop Pages appeared first on Divi Engine.

]]>
https://diviengine.com/snippet-adding-a-divi-woocommerce-add-to-cart-icon-button-on-shop-pages/feed/ 9
Automatically Update the WooCommerce Cart on Quantity Change https://diviengine.com/update-woocommerce-cart-on-quantity-change/ https://diviengine.com/update-woocommerce-cart-on-quantity-change/#comments Mon, 01 Mar 2021 10:47:46 +0000 https://diviengine.com/?p=69257 The post Automatically Update the WooCommerce Cart on Quantity Change appeared first on Divi Engine.

]]>

Today we have a quick Snippet for you that will allow you to have your cart totals update automatically as you change the quantity field without having to click the update button on the cart page.

Simply add these to Divi > Theme Options > Integrations tab, under the Body section.

WooCommerce Cart Page

If you are NOT using our custom quantity feature from Divi BodyCommerce, use the code below.

WooCommerce Cart Page with BodyCommerce custom quantity

If you are using WooCommerce with BodyCommerce you can do so much more. If you are using our custom quantity feature (form field customiser), use the code below.

The post Automatically Update the WooCommerce Cart on Quantity Change appeared first on Divi Engine.

]]>
https://diviengine.com/update-woocommerce-cart-on-quantity-change/feed/ 12
Show WooCommerce product images in the cart on mobile devices with Divi https://diviengine.com/show-woocommerce-product-images-in-the-cart-on-mobile-devices-with-divi/ https://diviengine.com/show-woocommerce-product-images-in-the-cart-on-mobile-devices-with-divi/#comments Mon, 04 Jan 2021 13:12:59 +0000 https://diviengine.com/?p=67643 The post Show WooCommerce product images in the cart on mobile devices with Divi appeared first on Divi Engine.

]]>
By default, WooCommerce hides the product images on the cart page when viewing from a mobile device. This can be quite annoying as images really help sell your products.

Add this CSS to Divi > Theme Options > Custom CSS to fix

Before
Show product images in WooCommerce cart on mobile
After
Show product images in WooCommerce cart on mobile

The post Show WooCommerce product images in the cart on mobile devices with Divi appeared first on Divi Engine.

]]>
https://diviengine.com/show-woocommerce-product-images-in-the-cart-on-mobile-devices-with-divi/feed/ 5
Change a select option using jQuery in Divi https://diviengine.com/change-a-select-option-using-jquery-in-divi/ https://diviengine.com/change-a-select-option-using-jquery-in-divi/#comments Thu, 23 Jul 2020 14:27:12 +0000 https://diviengine.com/?p=63805 The post Change a select option using jQuery in Divi appeared first on Divi Engine.

]]>

How to dynamically change a select option in a dropdown using jQuery

Here is a nifty trick – if you have a select dropdown but want to have something a bit nicer in appearance and change the value of this drop down dynamically. Not sure what I am talking about?

Scenario 1: You have a WooCommerce website and have variations, these are in a select drop down. Maybe you want to have images for each variation and when the customer clicks on this image, it changes the variation to add to cart.

Scenario 2: You have a select drop down to filter posts but you want a nice image instead.

Both of these scenarios are not the only applications but you get the idea of what you can do with this quick bit of code.

Step 1: Create a select dropdown

Below is a bit of code that will create the select dropdown – for testing purposes we have simply added this dummy code. We will show you a real life application after.

 

Step 2: Add target to change the select option

The next step is to add whatever you want that will change the select value. This could be an image, icon, blurb, button or anything else you can think will work. For our purposes, we will use a blurb module. Go ahead and add your blurb module, upload a nice image or use an icon.

There is one key thing you need to do here, which is to add to the blurb module an ID that corresponds with the value of the select. In our example we have “web-design” as a value in the select option. We give one of the blurbs an ID of “web-design”, this way when they click this, it will tell our jQuery code which to change to. See the image below (1 = the value you want it to change)

One final thing we need to do here is to add the ID “custom-grid-control” to our row or section that the blurbs are in. This way we can target just these blurbs using jQuery.

change-select-otion-with-jquery

Step 3: Add jQuery

The final step is to add the jQuery – we have added comments next to each line to tell you what it does – also watch the video at the bottom of this post which we explain it all in-depth if you need more help.

Step 4: Fine tune

And that’s it, now when you click on the blurb with the ID “web-design”, it will change the select to be Web Design, likewise, if you click on a blurb with an ID “social” it will change the select option to be the Social option.

Live example

change select dropdown using jquery

Now we understand how we can do this, let’s show you a live example. We are (at the time of writing) working on a new layout pack for our plugin Divi Machine for projects. On this layout we decided to use this code. We have some projects and using Divi Machine, filtering them based on their categories.

We have set up the archive loop module and the filter module. In the filter module, we have specified just the categories to be an option to filter (make sure you select the option to update on the change field rather than the button). Now this is all set up we can filter our projects.

This is great but maybe we want to use images instead, we can use the technique above to do this. Add some blurbs to the page and make sure you give each one the ID that corresponds to the option value (the category slug). Now we have done this, add the jQuery code and when you click on the blurb, it will update the select dropdown in the filter and then filter the posts.

One thing to think of is in our example above we have added a div called “custom-filter-posts” around our dummy select dropdown – we need to make sure to add this same CSS class to our filter module in the CSS section.

We have also added some extra CSS to make things a little bit better (see below with comments)

Check the video below for more details on this all

The post Change a select option using jQuery in Divi appeared first on Divi Engine.

]]>
https://diviengine.com/change-a-select-option-using-jquery-in-divi/feed/ 2
How to make a divi sticky section on scroll https://diviengine.com/how-to-make-a-divi-sticky-section-on-scroll/ https://diviengine.com/how-to-make-a-divi-sticky-section-on-scroll/#comments Mon, 11 May 2020 11:26:45 +0000 https://diviengine.com/?p=61176 The post How to make a divi sticky section on scroll appeared first on Divi Engine.

]]>

Have you ever wanted a section to be sticky when scrolling to it and be fixed?

For years we have been using jQuery to target a specific section and then add a class name. Once this class name has been added to add some custom CSS to make it fixed and set the position. This could cause headaches as sometimes the size would change or at the bottom, it would overflow the text or images of other section. It would become a big task to get it looking perfect.

Fear not, with this simple piece of code, you can avoid all this and get it working first time, so easily.

You can add a class to the section, column or row – lets say “sticky-section” or even modify our CSS below to target the section you already have.

This is all the code you need to add – I know, crazy right?

 

Want to see a live example? Well look at our sidebar on this page, this is how we do it.

The code “postion: sticky” will automatically stop the section from being fixed when it hits the end of the area and reaches another section below.

The only other bit of code you need is to make the page-container overflow visible. If it has hidden, it won’t work.

Are you astounded as much as I was when first discovered this?

Want to do some other cool things? Check below an example

Just some dummy text

Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.

Backpack Shop Layout pack - Bodycommerce

Fixed Section

Just some dummy text

Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.

Backpack Shop Layout pack - Bodycommerce

Fixed Section

Fixed Section

Just some dummy text

Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.

Backpack Shop Layout pack - Bodycommerce

The post How to make a divi sticky section on scroll appeared first on Divi Engine.

]]>
https://diviengine.com/how-to-make-a-divi-sticky-section-on-scroll/feed/ 27
SNIPPET: Make Divi Search Products Only https://diviengine.com/snippet-make-divi-search-products-only/ https://diviengine.com/snippet-make-divi-search-products-only/#comments Tue, 05 May 2020 19:43:14 +0000 https://diviengine.com/?p=60979 The post SNIPPET: Make Divi Search Products Only appeared first on Divi Engine.

]]>

If you want Divi to search ONLY products, you are in the right place. We know how frustrating it is that Divi does not search the products but searches everything. This is not great for your customers UX so the snippet below will solve this for you.

Add this code to Divi > Theme Options > Integration > Body. 

Once added, some code will by dynamically added which will make the search bar in the header and all the search modules search products only.

We hope this helps you and any questions please ask.

If using the theme builder and adding the search module, please exclude pages and posts as seen below

theme builder exclude post and pages

The post SNIPPET: Make Divi Search Products Only appeared first on Divi Engine.

]]>
https://diviengine.com/snippet-make-divi-search-products-only/feed/ 44
Snippet: Show SKU in cart and checkout https://diviengine.com/show-sku-in-cart-and-checkout/ https://diviengine.com/show-sku-in-cart-and-checkout/#comments Thu, 16 Apr 2020 06:40:45 +0000 https://diviengine.com/?p=59378 The post Snippet: Show SKU in cart and checkout appeared first on Divi Engine.

]]>

If you want to display your SKU on the cart and checkout pages, simply add this code to your child theme in the functions.php file. It hooks into the action “woocommerce_cart_item_name” which is perfect.

We hope this helps you in some way.

The post Snippet: Show SKU in cart and checkout appeared first on Divi Engine.

]]>
https://diviengine.com/show-sku-in-cart-and-checkout/feed/ 9
SNIPPET: Make WooCommerce Checkout Fields Not Required https://diviengine.com/snippet-make-woocommerce-checkout-fields-not-required/ https://diviengine.com/snippet-make-woocommerce-checkout-fields-not-required/#comments Mon, 10 Feb 2020 10:48:18 +0000 https://diviengine.com/?p=54446 The post SNIPPET: Make WooCommerce Checkout Fields Not Required appeared first on Divi Engine.

]]>

Do you want to make some checkout fields not required such as phone number or the first name? Use this snippet below to do this.

In the above we are making the billing first name, last name, phone number, email and country as not required.

To add more you need to just add the HTML names of the fields. You can use inspect to check the names on the checkout page. For your reference we have added them below.

Likewise you can change the text “false” to be “true” to make them required.

Billing Fields

  • billing_first_name
  • billing_last_name
  • billing_company
  • billing_country
  • billing_address_1
  • billing_address_2
  • billing_city
  • billing_state
  • billing_postcode
  • billing_phone
  • billing_email

Shipping Fields

  • shipping_first_name
  • shipping_last_name
  • shipping_company
  • shipping_country
  • shipping_address_1
  • shipping_address_2
  • shipping_city
  • shipping_state
  • shipping_postcode

Order Fields

  • order_comments

The post SNIPPET: Make WooCommerce Checkout Fields Not Required appeared first on Divi Engine.

]]>
https://diviengine.com/snippet-make-woocommerce-checkout-fields-not-required/feed/ 5
SNIPPET: Add Class To Body https://diviengine.com/how-to-a-add-class-to-body/ https://diviengine.com/how-to-a-add-class-to-body/#respond Fri, 07 Feb 2020 10:37:33 +0000 https://diviengine.com/?p=54442 The post SNIPPET: Add Class To Body appeared first on Divi Engine.

]]>

Have you needed to have a class added to your body for a particular job. Maybe you just need one added or maybe you need one added based on the user role – have you ever wanted to know how to add the user role as a class name to the body? Below are two snippets to add to your functions.php file.

You can use the user role class to customise the page (using CSS) based on the user or you can hide sections/modules. 

Add class on all pages
Add user role class on all pages - for example role-customer

The post SNIPPET: Add Class To Body appeared first on Divi Engine.

]]>
https://diviengine.com/how-to-a-add-class-to-body/feed/ 0
SNIPPET: Change WooCommerce Text https://diviengine.com/snippet-change-woocommerce-text/ https://diviengine.com/snippet-change-woocommerce-text/#comments Mon, 06 Jan 2020 10:14:50 +0000 https://diviengine.com/?p=52229 The post SNIPPET: Change WooCommerce Text appeared first on Divi Engine.

]]>

Need to change the text of a string on your WooCommerce shop such as “Billing Details” or “Product” to be something else.

Here is a snippet that will help. We have given a few examples so simply replace/remove as you need. Add this text to your functions.php file in your child theme.

The post SNIPPET: Change WooCommerce Text appeared first on Divi Engine.

]]>
https://diviengine.com/snippet-change-woocommerce-text/feed/ 11
SNIPPET: How to move WordPress admin bar to bottom https://diviengine.com/how-to-move-wordpress-admin-bar-to-bottom/ https://diviengine.com/how-to-move-wordpress-admin-bar-to-bottom/#comments Thu, 02 Jan 2020 14:30:30 +0000 https://diviengine.com/?p=52106 The post SNIPPET: How to move WordPress admin bar to bottom appeared first on Divi Engine.

]]>

Has the admin bar ever annoyed you at the top or just wanted to move WP admin bar to the bottom of the browser?

Use this snippet to move it to the bottom. Add this to your functions.php file in your child theme.

The post SNIPPET: How to move WordPress admin bar to bottom appeared first on Divi Engine.

]]>
https://diviengine.com/how-to-move-wordpress-admin-bar-to-bottom/feed/ 1
SNIPPET: Add CSS to admin https://diviengine.com/snippet-add-css-to-admin/ https://diviengine.com/snippet-add-css-to-admin/#respond Mon, 30 Dec 2019 19:12:09 +0000 https://diviengine.com/?p=52101 The post SNIPPET: Add CSS to admin appeared first on Divi Engine.

]]>

Ever wanted to add some CSS to WordPress admin to customise the appearance? Maybe you want to style the admin to look like your agency or if you are like me, love a certain colour and want to see this more often.

Simply add this php code to your functions.php file in your child them. You can add any CSS you want.

The code below will change the background and border colour of your primary button.

We hope this helps

The post SNIPPET: Add CSS to admin appeared first on Divi Engine.

]]>
https://diviengine.com/snippet-add-css-to-admin/feed/ 0