Force account creation for a specific pricing option

Easy Digital Downloads has a “Disable Guest Checkout” option which when enabled, forces customers to create an account before they can make a purchase.

On the AffiliateWP website, we only wanted customers to be forced to create an account when they purchased a developer license. Creating an account for either the personal or business license should be optional.

Copy and paste the function below (mind the opening PHP tag) into your child theme’s functions.php or custom plugin. Modify the download ID and price ID accordingly.

Redirect customer at checkout when their cart is empty

Redirect the customer to another page or URL when the cart is empty in Easy Digital Downloads

When the cart in Easy Digital Downloads is empty, it will show the customer a “Your cart is empty” message and keep them on the checkout page.

We can redirect the customer when they remove the last item in their cart, or when they visit the checkout page and have no items in their cart. For example, you might like to redirect the customer to your shop page, so they can continue shopping.

Copy and paste the following function (mind the opening PHP tag) into your child theme’s functions.php or custom plugin and adjust the redirect variable as required.

Adding a custom checkout field in Easy Digital Downloads

This tutorial will show you a start to finish example on adding a custom field to the checkout screen, right through to including the field in email notifications.

This tutorial will show you a start to finish example on adding a custom field to the checkout screen in Easy Digital Downloads, right through to displaying the custom field in email notifications.

Here’s a run down on what we’ll be covering:

  1. Adding a phone number field to the checkout
  2. Making the phone number field required
  3. Setting an error when the phone number field is not filled out
  4. Storing the phone number into the payment meta
  5. Storing the phone number into the wp_usermeta table (so we can use it on the WP edit profile screen)
  6. Adding the phone number to the user’s “Contact Info” section on their WordPress profile page and allowing it to be modified.
  7. Adding the phone number field to the page where [[edd_profile_editor]] is used, making it required, and allowing the customer to modify it.
  8. Pre-populating the phone number field at checkout if the user if logged in and already has a phone number
  9. Adding the customer’s phone number to the “view order details” screen and being able to update it like the other fields
  10. Adding a new {phone} email tag so you can display the phone number in the email notifications (standard purchase receipt or admin notification)
The "phone" field added to the checkout screen in Easy Digital Downloads
The “phone” field added to the checkout screen

15804-view-order-details

 

The new {phone} email tag for use within the emails in Easy Digital Downloads
The new {phone} email tag for use within the emails

Copy and paste the following code (mind the opening PHP tag) into your child theme’s functions.php or custom plugin.

Show a download’s sale and download count

Here’s a short tutorial for Easy Digital Downloads that adds a download’s sales and download count to the Download Details widget, found under Appearance → Widgets. If you’d like to show the counts somewhere else, simply call each function and pass in your download’s ID.

sales-download-count
The Download Details widget shown on the 2013 theme

Copy and paste the following (mind the opening PHP tag) into your child theme’s functions.php or custom plugin.

Show user’s purchase history as a dashboard widget

By default, when a user registers via the checkout, they are automatically logged in and can access the WordPress’ dashboard as a subscriber. This snippet adds a customer’s purchase history as a dashboard widget.

Copy and paste the following functions (mind the opening PHP tag) into your child theme’s functions.php or custom plugin.

Show the Shop Vendor’s email for each download purchased

A user on the Easy Digital Downloads’ forums wanted a new email tag for the purchase receipt so they could list each email address of the Shop Vendor who added the download. This is so the customer who purchased the product knows who to get in contact with should they have any questions.

Simply copy and paste the following functions (mind the opening PHP tag) into your child theme’s functions.php or custom plugin.

In the purchase receipt field under downloads → settings → emails, you can enter this:

For more information about your order, please contact one of the following vendors:

{vendor_emails}

This will output the following in your purchase receipt assuming the user purchased 3 different downloads, added by 3 unique Shop Vendors:

For more information about your order, please contact one of the following vendors:

Download One
shopvendor1@email.com

Download Two
shopvendor2@email.com

Download Three
shopvendor3@email.com

Linking gallery images to the attachment page in Easy Image Gallery

This tutorial will show you how to link each image to the attachment page, instead of using the lightbox functionality.

Easy Image Gallery can either open your gallery images in a lightbox, or simply display them with no links. A user contacted me today asking if it’s possible to link each image to the attachment page, instead of using the lightbox functionality.

To do this, copy the following function into your child theme’s functions.php (mind the opening PHP tag) or custom plugin:

Note: if you need to add a CSS class on the anchor link, simply comment out the line of code shown in the code snippet and edit accordingly.

You can download Easy Image Gallery from WordPress.org.

How to change a payment gateway’s checkout label in Easy Digital Downloads

This tutorial will show you how you can change a payment gateway’s checkout label. This is the text that appears next to the radio input when there are multiple payment options.

For example, if you’re using the 2Checkout payment gateway, the checkout label says “2Checkout” by default. You might like to change this to “Credit Card”.

All of the payment gateways built for Easy Digital Downloads should be using a filter called edd_payment_gateways to register their gateway’s text labels for both the admin and checkout page. You’ll need to look inside the plugin to get the exact value for which the plugin has registered itself under as shown in the example below. This can easily be done by searching for the filter name.

The code

Copy and paste the following function (mind the opening PHP tag) into your child theme’s functions.php or custom plugin:

Here’s another example of changing the text, but this time for the Check payment gateway. A customer of the EDD forums requested “Checks” be “Bank Deposit”.

How to add custom text before the purchase button at checkout

This quick snippet will show you how to add some custom text just before the purchase button at checkout.

The 1000 in the add_action function represents the priority. The Purchase Total that shows just before the purchase button has a priority of 999, so if you’d like your text to appear before that, change the priority to something lower.

Copy and paste the following function (mind the opening PHP tag) into your child theme’s functions.php or custom plugin.

fancyBox and Easy Image Gallery v1.1

Up until this point, Easy Image Gallery has been packaged with fancyBox 2. Unfortunately I completely overlooked the licensing of fancyBox 2, which is licensed under the Creative Commons license. Non-GPL licensed software cannot be hosted on the WordPress repository and because of this, I’ve replaced fancyBox 2 with fancyBox 1, which is GPL licensed.

If you’d like to add fancyBox 2 back into the plugin, simply download the free Easy Image Gallery Extend plugin. After activation, you’ll find fancyBox 2 (as well as Colorbox) under the plugin’s settings.