It is already over – at least this time around – but I thought it might be interesting to show, how we handle our Black Friday sale in our store. (We use Easy Digital Downloads to handle Subscriptions and Licensing for picu Pro.)
Turn It On, Turn It Off
We use a regular EDD coupon for Black Friday, which is set to be active for a pre-defined timeframe, and we automatically apply it on checkout.
To activate Black Friday, we created a couple of custom settings:
- We can simply turn the deal on with a checkbox in the general settings
- There’s a field to set the coupon code that will be used
- The last day of the deal can be specified, so that we do not have to turn it off manually (in the middle of the night)
This is the (simplified) code we use to automatically apply a EDD coupon on checkout:
/**
* Automatically apply EDD coupon code on checkout
*/
function maybe_apply_discount() {
if ( get_option( 'picu_black_friday' ) == 'on' && time() < strtotime( get_option( 'picu_black_friday_end_date' ) ) + 86400 ) {
$discount_code = get_option( 'picu_black_friday_coupon' );
$cart_items = edd_get_cart_contents();
// Make sure there is a coupon and picu Pro is in the cart
if ( ! empty( $discount_code ) && is_array( $cart_items ) ) {
foreach ( $cart_items as $item ) {
if ( $item['id'] == 1234 ) {
$has_picu_pro = true;
}
}
}
// Apply or remove the coupon
if ( $has_picu_pro == true ) {
edd_set_cart_discount( $discount_code );
} else {
edd_unset_cart_discount( $discount_code );
}
}
}
add_action( 'edd_cart_items_before', 'maybe_apply_discount' );
Aside from checking the aforementioned options, we also make sure that picu Pro is actually in the cart, defined by ID 1234 in the example above.
Let It Be Known
Before switching to a FSE theme, we used the same mechanics directly in our PHP theme templates to display the Black Friday banners on the site.
This time around we switched to synced patterns, which makes it much easier and quicker to update the banners, as we can do it without updating the theme itself.
We used the Block Visibility plugin to show the banners during the time of the deal.
This setup works quite well for us and it only needs very little effort to setup every year.
Leave a Reply