Skip to content

Commit 67b3028

Browse files
fix: black friday for 2025
1 parent 970e9f8 commit 67b3028

4 files changed

Lines changed: 468 additions & 27 deletions

File tree

assets/src/dashboard/parts/connected/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ const ConnectedLayout = ({
9393
}
9494
}, [ canSave ]);
9595

96-
const showBFBanner = 'free' === plan && optimoleDashboardApp?.bf_notices?.banner;
96+
const showBFBanner = Boolean( optimoleDashboardApp?.bf_notices?.banner );
9797

9898
return (
9999
<div className="optml-connected 2xl:max-w-screen-xl max-w-screen px-4 mx-auto">

inc/admin.php

Lines changed: 75 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -720,6 +720,15 @@ public static function get_upgrade_base_link() {
720720
return $base_url;
721721
}
722722

723+
/**
724+
* Get contact URL.
725+
*
726+
* @return string Contact URL.
727+
*/
728+
public static function get_contact_base_link() {
729+
return tsdk_translate_link( 'https://optimole.com/contact' );
730+
}
731+
723732
/**
724733
* Retrieve Optimole account email.
725734
*
@@ -1396,6 +1405,9 @@ private function localize_dashboard_app() {
13961405
$service_data['renews_on_formatted'] = date_i18n( get_option( 'date_format' ), $service_data['renews_on'] );
13971406

13981407
}
1408+
1409+
$user_plan = isset( $service_data['plan'] ) ? $service_data['plan'] : 'free';
1410+
13991411
return [
14001412
'strings' => $this->get_dashboard_strings(),
14011413
'assets_url' => OPTML_URL . 'assets/',
@@ -1432,7 +1444,7 @@ private function localize_dashboard_app() {
14321444
'hash' => '#settings',
14331445
],
14341446
],
1435-
'bf_notices' => $this->get_bf_notices(),
1447+
'bf_notices' => $this->get_bf_notices( $user_plan ),
14361448
'spc_banner' => $this->get_spc_banner(),
14371449
'show_exceed_plan_quota_notice' => $this->should_show_exceed_quota_warning(),
14381450
'show_free_user_with_offload_notice' => get_option( 'optml_has_offloading_enabled_on_upgrade', 'no' ),
@@ -1443,7 +1455,7 @@ private function localize_dashboard_app() {
14431455
'utm_campaign' => 'report_issue',
14441456
'contact_website' => home_url(),
14451457
],
1446-
tsdk_translate_link( 'https://optimole.com/contact/' )
1458+
self::get_contact_base_link()
14471459
),
14481460
];
14491461
}
@@ -1535,25 +1547,73 @@ private function get_spc_status() {
15351547
/**
15361548
* Get the black friday notices.
15371549
*
1538-
* @return array
1550+
* @param non-empty-string $user_plan User plan.
1551+
*
1552+
* @return array<string, mixed> Notice data.
15391553
*/
1540-
public function get_bf_notices() {
1541-
$date = new DateTime();
1554+
public function get_bf_notices( $user_plan ) {
1555+
1556+
$has_free_plan = 'free' === $user_plan;
1557+
$has_monthly_plan = strpos( $user_plan, '-yearly' ) === false && ! $has_free_plan;
1558+
1559+
if ( ! $has_free_plan && ! $has_monthly_plan ) {
1560+
return [];
1561+
}
15421562

1543-
$now = time();
1544-
$start = strtotime( '2024-11-25 00:00:00' );
1545-
$end = strtotime( '2024-12-03 23:59:59' );
1563+
/**
1564+
* The black friday sale period flag.
1565+
*
1566+
* @var bool $is_black_friday Whether is black friday sale period or not.
1567+
*/
1568+
$is_black_friday = apply_filters( 'themeisle_sdk_is_black_friday_sale', false );
15461569

1547-
if ( $now < $start || $now > $end ) {
1570+
if ( ! $is_black_friday ) {
15481571
return [];
15491572
}
15501573

1574+
/**
1575+
* The current date.
1576+
*
1577+
* @var DateTime $now Current date.
1578+
*/
1579+
$now = apply_filters( 'themeisle_sdk_current_date', new \DateTime( 'now' ) );
1580+
$current_year = $now->format( 'Y' );
1581+
1582+
$black_friday_day = new DateTime( "last Friday of November $current_year" );
1583+
$sale_start = clone $black_friday_day;
1584+
$sale_start->modify( 'monday this week' );
1585+
$sale_start->setTime( 0, 0 );
1586+
1587+
$end = clone $sale_start;
1588+
$end->modify( '+7 days' );
1589+
$end->setTime( 23, 59, 59 );
1590+
1591+
$message = sprintf(
1592+
/* translators: 1 is the promo code, 2 is the discount amount ('25 off') */
1593+
__( 'Use coupon code %1$s for an instant %2$s on your first billing cycle on Optimole plan.', 'optimole-wp' ),
1594+
'<span class="border-b border-0 border-white border-dashed text-promo-orange">BFCM2525</span>',
1595+
'<span class="text-promo-orange uppercase">' . __( '25% off', 'optimole-wp' ) . '</span>'
1596+
);
1597+
$cta_link = esc_url_raw( tsdk_utmify( tsdk_translate_link( self::get_upgrade_base_link() ), 'bfcm25', 'notice' ) );
1598+
$cta_text = __( 'Claim now', 'optimole-wp' );
1599+
1600+
if ( $has_monthly_plan ) {
1601+
$message = sprintf(
1602+
/* translators: 1 is the promo code, 2 is the discount amount ('25 off') */
1603+
__( '%1$sSwitch to a yearly plan%2$s and get an instant %3$s on your payment. Contact us to reedem your deal', 'optimole-wp' ),
1604+
'<span class=" text-promo-orange">',
1605+
'</span>',
1606+
'<span class="text-promo-orange uppercase">' . __( '15% off', 'optimole-wp' ) . '</span>'
1607+
);
1608+
$cta_link = esc_url_raw( tsdk_utmify( tsdk_translate_link( self::get_contact_base_link() ), 'bfcm25', 'notice' ) );
1609+
$cta_text = __( 'Contact us', 'optimole-wp' );
1610+
}
1611+
15511612
$notices = [
15521613
'sidebar' => [
15531614
'title' => sprintf(
1554-
'<span class="text-promo-orange">%1$s:</span> %2$s',
1615+
'<span class="text-promo-orange">%1$s:</span>',
15551616
__( 'Private Sale', 'optimole-wp' ),
1556-
__( '25 Nov - 03 Dec', 'optimole-wp' )
15571617
),
15581618
'subtitle' => sprintf(
15591619
/* translators: 1 is the promo code, 2 is the discount amount ('25 off') */
@@ -1571,17 +1631,12 @@ public function get_bf_notices() {
15711631

15721632
$notices['banner'] = [
15731633
/* translators: number of days left */
1574-
'urgency' => sprintf( __( 'Hurry up! only %s left', 'optimole-wp' ), human_time_diff( $end, $now ) ),
1634+
'urgency' => sprintf( __( 'Hurry up! only %s left', 'optimole-wp' ), human_time_diff( $end->getTimestamp(), $now->getTimestamp() ) ),
15751635
/* translators: private sale */
15761636
'title' => sprintf( __( 'Black Friday %s', 'optimole-wp' ), '<span class="text-promo-orange">' . __( 'private sale', 'optimole-wp' ) . '</span>' ),
1577-
'subtitle' => sprintf(
1578-
/* translators: 1 is the promo code, 2 is the discount amount ('25 off') */
1579-
__( 'Use coupon code %1$s for an instant %2$s on Optimole yearly plans', 'optimole-wp' ),
1580-
'<span class="border-b border-0 border-white border-dashed text-promo-orange">BFCM2425</span>',
1581-
'<span class="text-promo-orange">' . __( '25% discount', 'optimole-wp' ) . '</span>'
1582-
),
1583-
'cta_text' => __( 'Claim now', 'optimole-wp' ),
1584-
'cta_link' => esc_url_raw( tsdk_utmify( tsdk_translate_link( self::get_upgrade_base_link() ), 'bfcm24', 'dismissiblenotice' ) ),
1637+
'subtitle' => $message,
1638+
'cta_text' => $cta_text,
1639+
'cta_link' => $cta_link,
15851640
'dismiss_key' => self::BF_PROMO_DISMISS_KEY,
15861641
];
15871642

phpstan-baseline.neon

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -168,12 +168,6 @@ parameters:
168168
count: 1
169169
path: inc/admin.php
170170

171-
-
172-
message: '#^Method Optml_Admin\:\:get_bf_notices\(\) return type has no value type specified in iterable type array\.$#'
173-
identifier: missingType.iterableValue
174-
count: 1
175-
path: inc/admin.php
176-
177171
-
178172
message: '#^Method Optml_Admin\:\:get_dashboard_strings\(\) return type has no value type specified in iterable type array\.$#'
179173
identifier: missingType.iterableValue

0 commit comments

Comments
 (0)