How to Enable Milestone Sales Alerts in Easy Digital Downloads

Home » Snippets » How to Enable Milestone Sales Alerts in Easy Digital Downloads
0

Created with:

Visibility: 

public

Creator: WPTurbo Team

Customize with WPTurbo AI
X

Add Snippet To Project

New Project
Add To Existing Project

Are you looking for a way to streamline your sales process and stay informed about your milestones in Easy Digital Downloads? Look no further! In this article, we will guide you through the process of enabling milestone sales alerts in Easy Digital Downloads. By setting up these alerts, you will be able to track your sales progress and celebrate important milestones along the way. Let’s dive in and learn how to make the most out of this powerful feature.

					function wpturbo_enable_milestone_sales_alerts() {
    if ( ! function_exists( 'edd_get_option' ) ) {
        return;
    }

    $threshold = edd_get_option( 'wpturbo_milestone_threshold', 1000 );
    $sales     = edd_get_option( 'wpturbo_milestone_sales', 100 );

    if ( $sales >= $threshold ) {
        $message = sprintf( __( 'Congratulations! You have reached %d sales on your website.', 'wpturbo' ), $sales );
        echo '<div class="notice notice-success">' . $message . '</div>';
    }
}
add_action( 'admin_notices', 'wpturbo_enable_milestone_sales_alerts' );
				

The code snippet provided above allows you to display a custom success message in the WordPress admin dashboard when a certain sales milestone is reached in Easy Digital Downloads (EDD).

To begin, we define a function named wpturbo_enable_milestone_sales_alerts(). This function checks if the edd_get_option() function exists, which is a built-in function provided by EDD that retrieves options from the database. If it does not exist, we return and stop the execution of the function.

Next, we retrieve the values for the milestone threshold and sales count from the EDD options. The threshold is obtained using edd_get_option( 'wpturbo_milestone_threshold', 1000 ), where wpturbo_milestone_threshold is the option name and 1000 is the default value if the option is not set. The sales count is obtained using edd_get_option( 'wpturbo_milestone_sales', 100 ).

We then compare the sales count with the threshold using an if statement. If the sales count is equal to or greater than the threshold, we proceed to display the success message.

Inside the if statement, we create the success message using the sprintf() function. This function allows us to insert the sales count dynamically into the message. The %d placeholder in the message will be replaced with the actual value of the sales count. The translated message is stored in the $message variable.

Finally, we use echo to output the success message wrapped in a div element with a class of notice-success. This class applies the appropriate styling for a success notice in the WordPress admin dashboard.

To make this functionality work, we hook the wpturbo_enable_milestone_sales_alerts() function into the admin_notices action. This ensures that the custom success message is displayed on the admin dashboard whenever WordPress renders its admin notices.

By using this code snippet and adjusting the threshold and sales count values in the EDD options, you can easily enable milestone sales alerts in Easy Digital Downloads.

Register an account to save your snippets or go Pro to get more features.