Skip to content

Commit

Permalink
Merge pull request #161 from kimcoleman/dev
Browse files Browse the repository at this point in the history
Adjusting logic to allow admins to preview sales even when sale is no…
  • Loading branch information
kimcoleman authored Nov 6, 2023
2 parents 61624a4 + d5efc31 commit 09d3a2d
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
15 changes: 14 additions & 1 deletion classes/class-swsales-reports.php
Original file line number Diff line number Diff line change
Expand Up @@ -587,17 +587,29 @@ public static function admin_enqueue_scripts() {
* Setup JS vars and enqueue our JS for tracking user behavior
*/
public static function enqueue_tracking_js() {
$active_sitewide_sale = SWSales_Sitewide_Sale::get_active_sitewide_sale();
// If the user is an admin and the URL has a preview sale defined, return that sale as active.
if ( current_user_can( 'administrator' ) && isset( $_REQUEST['swsales_preview_sale_banner'] ) ) {
$active_sitewide_sale = SWSales_Sitewide_Sale::get_sitewide_sale( intval( $_REQUEST['swsales_preview_sale_banner'] ) );
$preview = true;
} else {
// Otherwise, try to get the current defined active sale via settings.
$active_sitewide_sale = SWSales_Sitewide_Sale::get_active_sitewide_sale();
}

// No active sale or previewed sale? Return.
if ( null === $active_sitewide_sale ) {
return;
}

// Is the active or previewed sale not running? Return.
if ( ! $active_sitewide_sale->is_running() ) {
return;
}

// Register our tracking script.
wp_register_script( 'swsales_tracking', plugins_url( 'js/swsales.js', SWSALES_BASENAME ), array( 'jquery', 'utils' ) );

// Set our JS vars.
$landing_page_post_id = $active_sitewide_sale->get_landing_page_post_id();
$swsales_data = array(
'landing_page' => ! empty( $landing_page_post_id ) && is_page( $landing_page_post_id ),
Expand All @@ -606,6 +618,7 @@ public static function enqueue_tracking_js() {
'ajax_url' => admin_url( 'admin-ajax.php' ),
);

// Localize and enqueue our tracking script.
wp_localize_script( 'swsales_tracking', 'swsales', $swsales_data );
wp_enqueue_script( 'swsales_tracking' );
}
Expand Down
2 changes: 1 addition & 1 deletion classes/class-swsales-sitewide-sale.php
Original file line number Diff line number Diff line change
Expand Up @@ -565,7 +565,7 @@ public function is_running() {

// Allow admins to preview the sale period and banners.
// This logic shows banner or landing page content regardless of whether sale is 'active' or in the 'sale' period.
if ( current_user_can( 'administrator' ) && isset( $_REQUEST['swsales_preview_time_period'] ) || isset( $_REQUEST['swsales_preview_sale_banner'] ) ) {
if ( current_user_can( 'administrator' ) && ( isset( $_REQUEST['swsales_preview_time_period'] ) || isset( $_REQUEST['swsales_preview_sale_banner'] ) ) ) {
return true;
}

Expand Down

0 comments on commit 09d3a2d

Please sign in to comment.