'Hot Flame', 'bolt-gold' => 'Flash Sale', 'star-gold' => 'Golden Star', 'tag-color' => 'Offer Tag', 'gift-color' => 'Gift Box', 'none' => 'No Icon', ); } /** * Allowed HTML tags and attributes (including inline SVG icons) for wp_kses escaping. */ public static function allowed_html() { $allowed = wp_kses_allowed_html( 'post' ); $svg_common = array( 'class' => true, 'style' => true, 'fill' => true, 'stroke' => true, 'stroke-width' => true, 'stroke-linecap' => true, 'stroke-linejoin' => true, 'opacity' => true, ); $allowed['svg'] = array_merge( $svg_common, array( 'width' => true, 'height' => true, 'viewbox' => true, 'xmlns' => true, ) ); $allowed['path'] = array_merge( $svg_common, array( 'd' => true ) ); $allowed['polygon'] = array_merge( $svg_common, array( 'points' => true ) ); $allowed['polyline'] = array_merge( $svg_common, array( 'points' => true ) ); $allowed['rect'] = array_merge( $svg_common, array( 'x' => true, 'y' => true, 'width' => true, 'height' => true, 'rx' => true, 'ry' => true ) ); $allowed['circle'] = array_merge( $svg_common, array( 'cx' => true, 'cy' => true, 'r' => true ) ); $allowed['line'] = array_merge( $svg_common, array( 'x1' => true, 'y1' => true, 'x2' => true, 'y2' => true ) ); $allowed['g'] = $svg_common; if ( isset( $allowed['div'] ) ) { $allowed['div']['data-of-countdown'] = true; $allowed['div']['data-of-reloaded'] = true; $allowed['div']['data-product_id'] = true; $allowed['div']['data-id'] = true; } if ( isset( $allowed['span'] ) ) { $allowed['span']['data-of-countdown'] = true; } if ( isset( $allowed['img'] ) ) { $allowed['img']['loading'] = true; $allowed['img']['decoding'] = true; $allowed['img']['srcset'] = true; $allowed['img']['sizes'] = true; } return $allowed; } /** * Allowed URL protocols including data URIs for uploaded custom icon thumbnails. */ public static function allowed_protocols() { return array_merge( wp_allowed_protocols(), array( 'data' ) ); } /** * Enqueue OfferCrisp admin CSS & JS only on plugin screens. */ public function enqueue_admin_assets( $hook_suffix ) { if ( false === strpos( (string) $hook_suffix, 'offercrisp' ) ) { return; } wp_enqueue_style( 'offercrisp-admin', plugin_dir_url( __FILE__ ) . 'assets/css/admin.css', array(), self::VERSION ); wp_enqueue_script( 'offercrisp-admin', plugin_dir_url( __FILE__ ) . 'assets/js/admin.js', array(), self::VERSION, true ); wp_localize_script( 'offercrisp-admin', 'offercrispAdminData', array( 'ajaxUrl' => admin_url( 'admin-ajax.php' ), 'nonce' => wp_create_nonce( 'offercrisp_ajax_nonce' ), ) ); } public function render_slot_icon( $preset_key, $custom_val = '', $size = 20 ) { $custom_val = trim( (string) $custom_val ); $s = absint( $size ); if ( '' !== $custom_val ) { if ( preg_match( '/^(https?:\/\/|data:image\/[a-z0-9+\-.]+;base64,)/i', $custom_val ) ) { $safe_src = ( 0 === stripos( $custom_val, 'data:image/' ) ) ? esc_attr( $custom_val ) : esc_url( $custom_val ); return ''; } return '' . esc_html( $custom_val ) . ''; } if ( 'none' === $preset_key || '' === $preset_key ) { return ''; } return self::icon( $preset_key, $s ); } public static function icon( $name, $size = 16 ) { if ( 'none' === $name || '' === $name ) { return ''; } $s = absint( $size ); $icons = array( 'flame-color' => '', 'bolt-gold' => '', 'sparkles-gold' => '', 'crown-gold' => '', 'diamond-cyan' => '', 'perfume-gold' => '', 'gift-color' => '', 'tag-color' => '', 'star-gold' => '', 'rocket-color' => '', 'trophy-gold' => '', 'heart-glow' => '', 'upload-img' => '', 'bell-gold' => '', 'flame' => '', 'bolt' => '', 'sliders' => '', 'percent' => '', 'calendar' => '', 'clock' => '', 'type' => '', 'palette' => '', 'tag' => '', 'globe' => '', 'eye' => '', 'save' => '', 'check' => '', 'layers' => '', 'bell' => '', 'user' => '', ); return isset( $icons[ $name ] ) ? '' . $icons[ $name ] . '' : ''; } /** * Default Settings (100% English, Unlimited Products Display by Default) */ public function get_default_settings() { return array( 'enabled' => '0', 'offer_name' => 'Offer', 'badge_text' => 'OFFER', 'tag_slug' => 'offer', 'apply_all' => '0', 'offer_page_id' => 0, 'pricing_method' => 'table', // 'table' | 'global_percent' | 'global_fixed' 'discount_value' => '20', 'discount_base' => 'sale', // 'sale' | 'regular' 'table_override' => '1', 'schedule_enabled' => '0', // ON/OFF toggle for Global Campaign Schedule 'countdown_start' => '', 'offer_start' => '', 'offer_end' => '', 'page_title' => 'Deal of the Day', 'page_description' => 'A limited-time, high-impact flash sale — grab your favorite deals before time runs out.', 'upcoming_message' => 'A new special offer is starting soon. Stay tuned for Deal of the Day.', 'ended_message' => 'The Offer has ended. Stay tuned for the next one.', 'special_pill_text' => 'SPECIAL OFFER', 'active_pill_text' => 'Flash Sale Active', 'bar_subtitle' => 'Flash Sale — Limited Time Only', 'hurry_text' => 'Hurry — limited time offer', 'preset' => 'classic_slate', 'primary_color' => '#2563EB', 'primary_dark' => '#111827', 'secondary_color' => '#3B82F6', 'live_green' => '#16A34A', 'upcoming_purple' => '#475569', 'hero_bg' => '#111827', 'hero_title_accent' => '#93C5FD', 'hero_timer_bg' => '#1F2937', 'sp_bar_mid' => '#1E293B', 'sp_bar_end' => '#111827', 'sp_bar_text' => '#FFFFFF', 'sp_bar_timer_bg' => '#0F172A', 'tz_offset_mins' => 360, 'icon_sp_box' => 'flame-color', 'custom_icon_sp_box' => '', 'icon_sp_title' => 'bolt-gold', 'custom_icon_sp_title' => '', 'icon_hero_sale' => 'bolt-gold', 'custom_icon_hero_sale' => '', 'icon_card_badge' => 'flame-color', 'custom_icon_card_badge' => '', 'products_per_page' => -1, ); } public function get_settings() { if ( null === $this->settings ) { $saved = get_option( self::OPTION_KEY, array() ); $this->settings = wp_parse_args( is_array( $saved ) ? $saved : array(), $this->get_default_settings() ); } return $this->settings; } public function on_terms_changed( $object_id, $terms, $tt_ids, $taxonomy ) { if ( 'product_tag' === $taxonomy || 'product_cat' === $taxonomy ) { $this->clear_performance_caches(); } } public function clear_performance_caches() { delete_transient( self::TRANSIENT_DATA ); $this->runtime_cache = null; $this->price_cache = array(); if ( function_exists( 'wc_delete_product_transients' ) ) { wc_delete_product_transients(); } if ( class_exists( 'WC_Cache_Helper' ) ) { WC_Cache_Helper::get_transient_version( 'product', true ); WC_Cache_Helper::get_transient_version( 'shipping', true ); } if ( has_action( 'litespeed_purge_all' ) ) { // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedHooknameFound -- Third-party LiteSpeed Cache purge hook. do_action( 'litespeed_purge_all' ); } } private function sync_selected_offer_page( $new_page_id, $old_page_id = 0 ) { if ( $old_page_id > 0 && $old_page_id !== $new_page_id ) { $old_post = get_post( $old_page_id ); if ( $old_post && 'page' === $old_post->post_type ) { $cleaned = trim( str_replace( '[offercrisp_page]', '', (string) $old_post->post_content ) ); wp_update_post( array( 'ID' => $old_page_id, 'post_content' => $cleaned, ) ); } } if ( $new_page_id > 0 ) { $new_post = get_post( $new_page_id ); if ( $new_post && 'page' === $new_post->post_type ) { $existing_content = trim( (string) $new_post->post_content ); if ( false === strpos( $existing_content, '[offercrisp_page]' ) ) { $updated_content = ( '' === $existing_content ) ? '[offercrisp_page]' : $existing_content . "\n\n[offercrisp_page]"; wp_update_post( array( 'ID' => $new_page_id, 'post_content' => $updated_content, ) ); } } } } public function on_activate() { $s = $this->get_settings(); if ( empty( $s['offer_page_id'] ) || ! get_post( absint( $s['offer_page_id'] ) ) ) { $page_id = $this->create_dedicated_offer_page(); if ( $page_id ) { $s['offer_page_id'] = $page_id; update_option( self::OPTION_KEY, $s, true ); $this->settings = $s; } } if ( taxonomy_exists( 'product_tag' ) && ! term_exists( 'offer', 'product_tag' ) ) { wp_insert_term( 'Offer', 'product_tag', array( 'slug' => 'offer' ) ); } $this->clear_performance_caches(); } public function on_deactivate() { $this->clear_performance_caches(); } private function create_dedicated_offer_page() { // Only reuse an existing page if it was explicitly created by OfferCrisp. $existing = get_page_by_path( 'offercrisp-offers' ); if ( $existing && 'page' === $existing->post_type ) { $is_managed = '1' === get_post_meta( $existing->ID, '_offercrisp_managed_page', true ); $has_sc = false !== strpos( (string) $existing->post_content, '[offercrisp_page]' ); if ( $is_managed || $has_sc ) { return absint( $existing->ID ); } } $page_id = wp_insert_post( array( 'post_title' => 'Flash Offers', 'post_name' => 'offercrisp-offers', 'post_content' => '[offercrisp_page]', 'post_status' => 'publish', 'post_type' => 'page', 'comment_status' => 'closed', ) ); if ( ! $page_id ) { return 0; } update_post_meta( absint( $page_id ), '_offercrisp_managed_page', '1' ); return absint( $page_id ); } public function is_selected_offer_page() { if ( is_admin() ) { return false; } $s = $this->get_settings(); $page_id = absint( $s['offer_page_id'] ); $qid = get_queried_object_id(); if ( $page_id > 0 && ( is_page( $page_id ) || ( $qid > 0 && $qid === $page_id ) ) ) { return true; } return false; } /** * O(1) Transient + Memory Runtime Cache of Tagged Product IDs, Schedules & Offer Prices */ private function get_runtime_cache() { if ( null !== $this->runtime_cache ) { return $this->runtime_cache; } $cached = get_transient( self::TRANSIENT_DATA ); if ( is_array( $cached ) && isset( $cached['parents'], $cached['schedules'], $cached['prices'], $cached['free_delivery'] ) ) { $this->runtime_cache = $cached; return $this->runtime_cache; } $s = $this->get_settings(); $raw_tags = trim( (string) $s['tag_slug'] ); $parents = array(); if ( '1' === (string) $s['apply_all'] ) { $ids = get_posts( array( 'post_type' => 'product', 'post_status' => 'publish', 'posts_per_page' => -1, 'fields' => 'ids', 'no_found_rows' => true, 'update_post_meta_cache' => false, 'update_post_term_cache' => false, ) ); $parents = array_fill_keys( array_map( 'absint', $ids ), true ); } elseif ( '' !== $raw_tags ) { $raw_parts = array_filter( array_map( 'trim', explode( ',', $raw_tags ) ) ); $tag_slugs = array_filter( array_map( 'sanitize_title', $raw_parts ) ); if ( empty( $tag_slugs ) ) { $tag_slugs = array( sanitize_title( $raw_tags ) ); } $ids = get_posts( array( 'post_type' => 'product', 'post_status' => 'publish', 'posts_per_page' => -1, 'fields' => 'ids', 'no_found_rows' => true, 'update_post_meta_cache' => false, 'update_post_term_cache' => false, // phpcs:ignore WordPress.DB.SlowDBQuery.slow_db_query_tax_query -- Required to filter products by offer tag/category; results are transient-cached. 'tax_query' => array( 'relation' => 'OR', array( 'taxonomy' => 'product_tag', 'field' => 'slug', 'terms' => $tag_slugs, ), array( 'taxonomy' => 'product_tag', 'field' => 'name', 'terms' => $raw_parts, ), array( 'taxonomy' => 'product_cat', 'field' => 'slug', 'terms' => $tag_slugs, ), ), ) ); $parents = array_fill_keys( array_map( 'absint', $ids ), true ); } $schedules = array(); $prices = array(); $free_delivery = array(); if ( ! empty( $parents ) ) { foreach ( array_keys( $parents ) as $pid ) { $st = (string) get_post_meta( $pid, self::META_START, true ); $en = (string) get_post_meta( $pid, self::META_END, true ); $pr = (string) get_post_meta( $pid, self::META_PRICE, true ); if ( '' !== $st || '' !== $en ) { $schedules[ $pid ] = array( 'start' => $st, 'end' => $en, ); } if ( '' !== $pr && is_numeric( $pr ) && floatval( $pr ) > 0 ) { $prices[ $pid ] = floatval( $pr ); } if ( '1' === (string) get_post_meta( $pid, self::META_FREE_DELIVERY, true ) ) { $free_delivery[ $pid ] = true; } $children = get_posts( array( 'post_parent' => $pid, 'post_type' => 'product_variation', 'post_status' => array( 'publish', 'private' ), 'posts_per_page' => -1, 'fields' => 'ids', 'no_found_rows' => true, 'update_post_meta_cache' => false, 'update_post_term_cache' => false, ) ); foreach ( $children as $vid ) { $vpr = (string) get_post_meta( $vid, self::META_PRICE, true ); if ( '' !== $vpr && is_numeric( $vpr ) && floatval( $vpr ) > 0 ) { $prices[ absint( $vid ) ] = floatval( $vpr ); } if ( '1' === (string) get_post_meta( $vid, self::META_FREE_DELIVERY, true ) ) { $free_delivery[ absint( $vid ) ] = true; } } } } $data = array( 'parents' => $parents, 'schedules' => $schedules, 'prices' => $prices, 'free_delivery' => $free_delivery, ); set_transient( self::TRANSIENT_DATA, $data, 4 * HOUR_IN_SECONDS ); $this->runtime_cache = $data; return $this->runtime_cache; } public function get_effective_tz_offset_seconds() { $wp_offset = (float) get_option( 'gmt_offset', 0 ); if ( 0.0 !== $wp_offset ) { return (int) round( $wp_offset * 3600 ); } $s = $this->get_settings(); $mins = isset( $s['tz_offset_mins'] ) ? intval( $s['tz_offset_mins'] ) : 360; return $mins * 60; } public function get_now_local_ts() { return time() + $this->get_effective_tz_offset_seconds(); } public function parse_local_dt( $dt_str ) { $dt_str = trim( (string) $dt_str ); if ( '' === $dt_str ) { return 0; } $clean = str_replace( 'T', ' ', $dt_str ); $ts = strtotime( $clean . ' UTC' ); return $ts ? (int) $ts : 0; } public static function hex_to_rgba( $hex, $alpha = 1.0 ) { $hex = ltrim( trim( (string) $hex ), '#' ); if ( 3 === strlen( $hex ) ) { $hex = $hex[0] . $hex[0] . $hex[1] . $hex[1] . $hex[2] . $hex[2]; } if ( 6 !== strlen( $hex ) ) { return 'rgba(236, 72, 153, ' . floatval( $alpha ) . ')'; } $r = hexdec( substr( $hex, 0, 2 ) ); $g = hexdec( substr( $hex, 2, 2 ) ); $b = hexdec( substr( $hex, 4, 2 ) ); return 'rgba(' . $r . ', ' . $g . ', ' . $b . ', ' . floatval( $alpha ) . ')'; } public function get_global_state() { $s = $this->get_settings(); if ( empty( $s['enabled'] ) || '1' !== (string) $s['enabled'] ) { return 'inactive'; } if ( empty( $s['schedule_enabled'] ) || '1' !== (string) $s['schedule_enabled'] ) { return 'live'; } $now = $this->get_now_local_ts(); $off_start = ! empty( $s['offer_start'] ) ? $this->parse_local_dt( $s['offer_start'] ) : 0; $off_end = ! empty( $s['offer_end'] ) ? $this->parse_local_dt( $s['offer_end'] ) : 0; if ( $off_end > 0 && $now >= $off_end ) { return 'ended'; } if ( $off_start > 0 && $now < $off_start ) { return 'upcoming'; } return 'live'; } public function is_product_in_offer_scope( $product, $for_single_banner = true ) { $parent_id = $this->resolve_parent_id( $product ); if ( ! $parent_id ) { return false; } $cache = $this->get_runtime_cache(); if ( isset( $cache['parents'][ $parent_id ] ) || isset( $cache['prices'][ $parent_id ] ) || isset( $cache['schedules'][ $parent_id ] ) ) { return true; } $s = $this->get_settings(); if ( '1' === (string) $s['apply_all'] ) { return true; } $raw_tags = trim( (string) $s['tag_slug'] ); if ( '' !== $raw_tags ) { $parts = array_filter( array_map( 'trim', explode( ',', $raw_tags ) ) ); $slugs = array_map( 'sanitize_title', $parts ); $terms = array_unique( array_merge( $parts, $slugs ) ); if ( has_term( $terms, 'product_tag', $parent_id ) || has_term( $terms, 'product_cat', $parent_id ) ) { return true; } } if ( $for_single_banner && empty( $cache['parents'] ) ) { return true; } return false; } public function get_product_banner_state( $product, $for_single_banner = true ) { $s = $this->get_settings(); if ( empty( $s['enabled'] ) || '1' !== (string) $s['enabled'] ) { return 'inactive'; } if ( ! $this->is_product_in_offer_scope( $product, $for_single_banner ) ) { return 'inactive'; } $parent_id = $this->resolve_parent_id( $product ); $cache = $this->get_runtime_cache(); $st_str = isset( $cache['schedules'][ $parent_id ]['start'] ) ? $cache['schedules'][ $parent_id ]['start'] : (string) get_post_meta( $parent_id, self::META_START, true ); $en_str = isset( $cache['schedules'][ $parent_id ]['end'] ) ? $cache['schedules'][ $parent_id ]['end'] : (string) get_post_meta( $parent_id, self::META_END, true ); if ( '' !== $st_str || '' !== $en_str ) { $now = $this->get_now_local_ts(); $st_ts = '' !== $st_str ? $this->parse_local_dt( $st_str ) : 0; $en_ts = '' !== $en_str ? $this->parse_local_dt( $en_str ) : 0; if ( $en_ts > 0 && $now >= $en_ts ) { return 'inactive'; } if ( $st_ts > 0 && $now < $st_ts ) { return 'upcoming'; } return 'live'; } $global_state = $this->get_global_state(); if ( 'inactive' === $global_state || 'ended' === $global_state ) { return 'inactive'; } if ( 'upcoming' === $global_state ) { return 'upcoming'; } return 'live'; } public function is_product_live( $product ) { return ( 'live' === $this->get_product_banner_state( $product ) ); } public function get_product_end_timestamp( $product ) { $parent_id = $this->resolve_parent_id( $product ); $cache = $this->get_runtime_cache(); $now = $this->get_now_local_ts(); $b_state = $this->get_product_banner_state( $product, true ); if ( 'upcoming' === $b_state ) { $st_str = isset( $cache['schedules'][ $parent_id ]['start'] ) ? $cache['schedules'][ $parent_id ]['start'] : (string) get_post_meta( $parent_id, self::META_START, true ); if ( '' !== $st_str ) { $st_ts = $this->parse_local_dt( $st_str ); if ( $st_ts > 0 ) { return $st_ts; } } $s = $this->get_settings(); if ( '1' === (string) $s['schedule_enabled'] && ! empty( $s['offer_start'] ) ) { $glob_start = $this->parse_local_dt( $s['offer_start'] ); if ( $glob_start > 0 ) { return $glob_start; } } } $en_str = isset( $cache['schedules'][ $parent_id ]['end'] ) ? $cache['schedules'][ $parent_id ]['end'] : (string) get_post_meta( $parent_id, self::META_END, true ); if ( '' !== $en_str ) { $en_ts = $this->parse_local_dt( $en_str ); if ( $en_ts > 0 ) { return $en_ts; } } $s = $this->get_settings(); if ( '1' === (string) $s['schedule_enabled'] && ! empty( $s['offer_end'] ) ) { $glob_end = $this->parse_local_dt( $s['offer_end'] ); if ( $glob_end > 0 ) { return $glob_end; } } return strtotime( 'tomorrow 00:00:00 UTC', $now ); } public function get_offer_page_target_timestamp( $state = null ) { if ( null === $state ) { $state = $this->get_global_state(); } $s = $this->get_settings(); $now = $this->get_now_local_ts(); if ( 'upcoming' === $state && '1' === (string) $s['schedule_enabled'] && ! empty( $s['offer_start'] ) ) { return $this->parse_local_dt( $s['offer_start'] ); } if ( 'live' === $state ) { $cache = $this->get_runtime_cache(); $nearest_end = 0; $nearest_next = 0; foreach ( array_keys( $cache['parents'] ) as $pid ) { if ( isset( $cache['schedules'][ $pid ] ) ) { $st = ! empty( $cache['schedules'][ $pid ]['start'] ) ? $this->parse_local_dt( $cache['schedules'][ $pid ]['start'] ) : 0; $en = ! empty( $cache['schedules'][ $pid ]['end'] ) ? $this->parse_local_dt( $cache['schedules'][ $pid ]['end'] ) : 0; $is_active = ( 0 === $st || $now >= $st ) && ( 0 === $en || $now < $en ); if ( $is_active && $en > $now ) { if ( 0 === $nearest_end || $en < $nearest_end ) { $nearest_end = $en; } } elseif ( $st > $now ) { if ( 0 === $nearest_next || $st < $nearest_next ) { $nearest_next = $st; } } } } if ( $nearest_end > 0 ) { return $nearest_end; } if ( $nearest_next > 0 ) { return $nearest_next; } if ( '1' === (string) $s['schedule_enabled'] && ! empty( $s['offer_end'] ) ) { return $this->parse_local_dt( $s['offer_end'] ); } return strtotime( 'tomorrow 00:00:00 UTC', $now ); } return 0; } private function resolve_parent_id( $product ) { if ( is_numeric( $product ) ) { if ( ! function_exists( 'wc_get_product' ) ) { return absint( $product ); } $p = wc_get_product( absint( $product ) ); if ( ! $p ) { return absint( $product ); } $product = $p; } if ( is_object( $product ) ) { if ( method_exists( $product, 'is_type' ) && $product->is_type( 'variation' ) ) { return absint( $product->get_parent_id() ); } if ( method_exists( $product, 'get_id' ) ) { return absint( $product->get_id() ); } } return 0; } public function local_ts_to_utc( $local_ts ) { if ( ! $local_ts ) { return 0; } return (int) round( $local_ts - $this->get_effective_tz_offset_seconds() ); } /** * Get the raw pre-offer base price of a product or variation ( bypassing our own price filters ) */ private function get_raw_base_price( $product ) { if ( ! is_object( $product ) ) { return 0.0; } $s = $this->get_settings(); $raw_reg = (float) $product->get_regular_price( 'edit' ); $raw_sale = (float) $product->get_sale_price( 'edit' ); $raw_cur = (float) $product->get_price( 'edit' ); if ( $raw_reg <= 0 ) { $meta_reg = get_post_meta( $product->get_id(), '_regular_price', true ); if ( '' !== $meta_reg && is_numeric( $meta_reg ) ) { $raw_reg = (float) $meta_reg; } } if ( $raw_sale <= 0 ) { $meta_sale = get_post_meta( $product->get_id(), '_sale_price', true ); if ( '' !== $meta_sale && is_numeric( $meta_sale ) ) { $raw_sale = (float) $meta_sale; } } if ( $raw_cur <= 0 ) { $meta_p = get_post_meta( $product->get_id(), '_price', true ); if ( '' !== $meta_p && is_numeric( $meta_p ) ) { $raw_cur = (float) $meta_p; } } if ( 'sale' === $s['discount_base'] && $raw_sale > 0 ) { return $raw_sale; } if ( $raw_reg > 0 ) { return $raw_reg; } if ( $raw_sale > 0 ) { return $raw_sale; } return max( 0.0, $raw_cur ); } /** * Look up saved custom Table Offer Price for an item ID or its parent ID (with direct postmeta fallback) */ private function get_saved_table_price( $item_id, $parent_id = 0 ) { $cache = $this->get_runtime_cache(); if ( $item_id > 0 && isset( $cache['prices'][ $item_id ] ) && $cache['prices'][ $item_id ] > 0 ) { return (float) $cache['prices'][ $item_id ]; } if ( $item_id > 0 ) { $m = get_post_meta( $item_id, self::META_PRICE, true ); if ( '' !== $m && is_numeric( $m ) && floatval( $m ) > 0 ) { return floatval( $m ); } } if ( $parent_id > 0 && $parent_id !== $item_id ) { if ( isset( $cache['prices'][ $parent_id ] ) && $cache['prices'][ $parent_id ] > 0 ) { return (float) $cache['prices'][ $parent_id ]; } $pm = get_post_meta( $parent_id, self::META_PRICE, true ); if ( '' !== $pm && is_numeric( $pm ) && floatval( $pm ) > 0 ) { return floatval( $pm ); } } return 0.0; } /** * Calculate Offer Price for a Product or Variation */ private function calculate_offer_price( $product ) { if ( ! is_object( $product ) || ! method_exists( $product, 'get_id' ) ) { return null; } $item_id = absint( $product->get_id() ); $parent_id = $this->resolve_parent_id( $product ); if ( isset( $this->price_cache[ $item_id ] ) ) { return false === $this->price_cache[ $item_id ] ? null : $this->price_cache[ $item_id ]; } if ( ! $this->is_product_live( $product ) ) { $this->price_cache[ $item_id ] = false; return null; } $s = $this->get_settings(); $base = $this->get_raw_base_price( $product ); $custom_price = $this->get_saved_table_price( $item_id, $parent_id ); // If a custom Offer Price is set in the table (e.g. 2450, 3000, 3550), always apply it when Table mode or Table Priority is active if ( $custom_price > 0 && ( 'table' === $s['pricing_method'] || '1' === (string) $s['table_override'] ) ) { $this->price_cache[ $item_id ] = $custom_price; return $custom_price; } if ( $base <= 0 ) { if ( $custom_price > 0 ) { $this->price_cache[ $item_id ] = $custom_price; return $custom_price; } $this->price_cache[ $item_id ] = false; return null; } if ( 'global_percent' === $s['pricing_method'] ) { $pct = max( 0.0, min( 99.0, floatval( $s['discount_value'] ) ) ); if ( $pct > 0 ) { $final = round( $base * ( 1.0 - ( $pct / 100.0 ) ) ); $this->price_cache[ $item_id ] = max( 1.0, $final ); return $this->price_cache[ $item_id ]; } } elseif ( 'global_fixed' === $s['pricing_method'] ) { $amt = max( 0.0, floatval( $s['discount_value'] ) ); if ( $amt > 0 && $amt < $base ) { $final = round( $base - $amt ); $this->price_cache[ $item_id ] = max( 1.0, $final ); return $this->price_cache[ $item_id ]; } } if ( $custom_price > 0 ) { $this->price_cache[ $item_id ] = $custom_price; return $custom_price; } $this->price_cache[ $item_id ] = false; return null; } public function filter_product_price( $price, $product ) { $s = $this->get_settings(); if ( $this->applying_price || empty( $s['enabled'] ) || '1' !== (string) $s['enabled'] ) { return $price; } $this->applying_price = true; $offer_p = $this->calculate_offer_price( $product ); $this->applying_price = false; return ( null !== $offer_p ) ? (string) $offer_p : $price; } public function filter_product_sale_price( $sale_price, $product ) { $s = $this->get_settings(); if ( $this->applying_price || empty( $s['enabled'] ) || '1' !== (string) $s['enabled'] ) { return $sale_price; } $this->applying_price = true; $offer_p = $this->calculate_offer_price( $product ); $this->applying_price = false; return ( null !== $offer_p ) ? (string) $offer_p : $sale_price; } public function filter_product_regular_price( $reg_price, $product ) { $s = $this->get_settings(); if ( $this->applying_price || empty( $s['enabled'] ) || '1' !== (string) $s['enabled'] ) { return $reg_price; } $this->applying_price = true; $offer_p = $this->calculate_offer_price( $product ); $base_p = $this->get_raw_base_price( $product ); $this->applying_price = false; if ( null !== $offer_p && $base_p > $offer_p ) { return (string) $base_p; } return $reg_price; } /** * Top-level filter on woocommerce_variation_prices (Runs even when Redis Object Cache / wc_var_prices_ transient is hit!) */ public function filter_woocommerce_variation_prices( $prices_array, $product, $for_display ) { if ( ! is_array( $prices_array ) || empty( $prices_array['price'] ) ) { return $prices_array; } if ( ! $this->is_product_live( $product ) ) { return $prices_array; } $this->applying_price = true; foreach ( array_keys( $prices_array['price'] ) as $vid ) { $var_obj = wc_get_product( $vid ); if ( ! $var_obj ) { continue; } $offer_p = $this->calculate_offer_price( $var_obj ); if ( null !== $offer_p && $offer_p > 0 ) { $base_p = $this->get_raw_base_price( $var_obj ); $prices_array['price'][ $vid ] = (string) $offer_p; $prices_array['sale_price'][ $vid ] = (string) $offer_p; if ( $base_p > $offer_p ) { $prices_array['regular_price'][ $vid ] = (string) $base_p; } } } $this->applying_price = false; asort( $prices_array['price'] ); asort( $prices_array['regular_price'] ); asort( $prices_array['sale_price'] ); return $prices_array; } public function filter_variation_prices_array( $prices_array, $product, $for_display ) { if ( ! is_array( $prices_array ) || empty( $prices_array ) ) { return $prices_array; } $this->applying_price = true; foreach ( $prices_array as $vid => $orig_p ) { $var_obj = wc_get_product( $vid ); if ( $var_obj ) { $offer_p = $this->calculate_offer_price( $var_obj ); if ( null !== $offer_p ) { $prices_array[ $vid ] = (string) $offer_p; } } } $this->applying_price = false; asort( $prices_array ); return $prices_array; } public function filter_variation_regular_prices_array( $prices_array, $product, $for_display ) { if ( ! is_array( $prices_array ) || empty( $prices_array ) ) { return $prices_array; } $this->applying_price = true; foreach ( $prices_array as $vid => $orig_reg ) { $var_obj = wc_get_product( $vid ); if ( $var_obj ) { $offer_p = $this->calculate_offer_price( $var_obj ); $base_p = $this->get_raw_base_price( $var_obj ); if ( null !== $offer_p && $base_p > $offer_p ) { $prices_array[ $vid ] = (string) $base_p; } } } $this->applying_price = false; asort( $prices_array ); return $prices_array; } public function filter_product_is_on_sale( $on_sale, $product ) { if ( $this->applying_price ) { return $on_sale; } if ( ! is_object( $product ) || ! $this->is_product_live( $product ) ) { return $on_sale; } $this->applying_price = true; if ( method_exists( $product, 'is_type' ) && $product->is_type( 'variable' ) ) { $children = $product->get_children(); foreach ( $children as $vid ) { $var_obj = wc_get_product( $vid ); if ( $var_obj && null !== $this->calculate_offer_price( $var_obj ) ) { $this->applying_price = false; return true; } } } $offer_p = $this->calculate_offer_price( $product ); $this->applying_price = false; return ( null !== $offer_p ) ? true : $on_sale; } public function filter_variation_prices_hash( $hash ) { $s = $this->get_settings(); $cache = $this->get_runtime_cache(); $hash[] = self::VERSION . '_' . $this->get_global_state() . '_' . md5( wp_json_encode( array( $s['pricing_method'], $s['discount_value'], $s['discount_base'], $s['tag_slug'], $cache['prices'], $cache['schedules'] ) ) ); return $hash; } /** * Guarantee formatted Offer Price HTML (Old Price Offer Price) for both Simple and Variable Products */ public function filter_woocommerce_get_price_html( $price_html, $product ) { if ( is_admin() || $this->applying_price || ! is_object( $product ) || ! function_exists( 'wc_get_product' ) ) { return $price_html; } if ( ! $this->is_product_live( $product ) ) { return $price_html; } $this->applying_price = true; // 1. Variable Product (e.g. Perfume with 100ml variation or multiple variations) if ( method_exists( $product, 'is_type' ) && $product->is_type( 'variable' ) ) { $children = $product->get_children(); $offer_items = array(); $all_eff = array(); $all_orig = array(); if ( is_array( $children ) && ! empty( $children ) ) { foreach ( $children as $vid ) { $var_obj = wc_get_product( $vid ); if ( ! $var_obj ) { continue; } $orig_p = $this->get_raw_base_price( $var_obj ); $offer_p = $this->calculate_offer_price( $var_obj ); if ( null !== $offer_p && $offer_p > 0 ) { $offer_items[] = array( 'orig' => $orig_p > 0 ? $orig_p : $offer_p, 'offer' => $offer_p, ); $all_eff[] = $offer_p; $all_orig[] = $orig_p > 0 ? $orig_p : $offer_p; } elseif ( $orig_p > 0 ) { $all_eff[] = $orig_p; $all_orig[] = $orig_p; } } } if ( ! empty( $offer_items ) ) { // If only 1 variation has an offer price (e.g. a single discounted variation), or all offered variations share the same offer price, display 2,700.00৳ 2,450.00৳ $o_vals = array_column( $offer_items, 'offer' ); $b_vals = array_column( $offer_items, 'orig' ); $min_o = min( $o_vals ); $max_o = max( $o_vals ); $min_b = min( $b_vals ); $max_b = max( $b_vals ); if ( $min_o === $max_o ) { $this->applying_price = false; if ( $max_b > $min_o ) { return wc_format_sale_price( wc_price( $max_b ), wc_price( $min_o ) ); } return '' . wc_price( $min_o ) . ''; } else { $this->applying_price = false; $orig_range = ( $min_b !== $max_b ) ? wc_format_price_range( $min_b, $max_b ) : wc_price( $min_b ); $offer_range = wc_format_price_range( $min_o, $max_o ); return ' ' . $offer_range . ''; } } $this->applying_price = false; return $price_html; } // 2. Simple Product or Single Variation $offer_p = $this->calculate_offer_price( $product ); $orig_p = $this->get_raw_base_price( $product ); $this->applying_price = false; if ( null !== $offer_p && $offer_p > 0 ) { if ( $orig_p > $offer_p ) { return wc_format_sale_price( wc_price( $orig_p ), wc_price( $offer_p ) ); } return '' . wc_price( $offer_p ) . ''; } return $price_html; } /** * Ensure WooCommerce always outputs price_html inside available_variations for live Offer products */ public function filter_show_variation_price( $show, $product ) { if ( is_object( $product ) && $this->is_product_live( $product ) ) { return true; } return $show; } /** * Check if a specific variation ID (or its parent product) has Free Delivery enabled */ public function is_item_free_delivery( $item_id, $parent_id = 0 ) { $item_id = absint( $item_id ); $parent_id = absint( $parent_id ); $cache = $this->get_runtime_cache(); if ( $item_id > 0 ) { if ( isset( $cache['free_delivery'][ $item_id ] ) ) { return true; } if ( '1' === (string) get_post_meta( $item_id, self::META_FREE_DELIVERY, true ) ) { return true; } } if ( $parent_id > 0 && $parent_id !== $item_id ) { if ( isset( $cache['free_delivery'][ $parent_id ] ) ) { return true; } if ( '1' === (string) get_post_meta( $parent_id, self::META_FREE_DELIVERY, true ) ) { return true; } } return false; } /** * Filter variation JSON data so custom themes & WooCommerce always receive crossed-out regular/sale price + Free Delivery flag */ public function filter_available_variation( $data, $parent_product, $variation ) { if ( ! is_array( $data ) || ! is_object( $variation ) || ! is_object( $parent_product ) ) { return $data; } if ( ! $this->is_product_live( $parent_product ) ) { return $data; } $this->applying_price = true; $offer_p = $this->calculate_offer_price( $variation ); $base_p = $this->get_raw_base_price( $variation ); $raw_reg = (float) get_post_meta( $variation->get_id(), '_regular_price', true ); if ( $raw_reg > $base_p ) { $base_p = $raw_reg; } $this->applying_price = false; if ( null !== $offer_p && $offer_p > 0 ) { $disp_offer = function_exists( 'wc_get_price_to_display' ) ? (float) wc_get_price_to_display( $variation, array( 'price' => $offer_p ) ) : (float) $offer_p; $disp_base = function_exists( 'wc_get_price_to_display' ) ? (float) wc_get_price_to_display( $variation, array( 'price' => $base_p ) ) : (float) $base_p; $data['display_price'] = $disp_offer; if ( $disp_base > $disp_offer ) { $data['display_regular_price'] = $disp_base; $data['price_html'] = '' . wc_format_sale_price( wc_price( $disp_base ), wc_price( $disp_offer ) ) . ''; } else { $data['price_html'] = '' . wc_price( $disp_offer ) . ''; } } $is_free_deliv = $this->is_item_free_delivery( $variation->get_id(), $parent_product->get_id() ); $data['of_free_delivery'] = $is_free_deliv; if ( $is_free_deliv ) { $free_badge = '
' . self::icon( 'check', 13 ) . ' Free Delivery on This Option
'; if ( isset( $data['variation_description'] ) ) { $data['variation_description'] .= $free_badge; } } return $data; } /** * Make shipping cost 0 in Cart & Checkout when any live Offer item with Free Delivery enabled is in the package */ public function filter_free_delivery_shipping_rates( $rates, $package ) { if ( ! is_array( $rates ) || empty( $rates ) || ! is_array( $package ) || empty( $package['contents'] ) ) { return $rates; } if ( is_admin() && ! wp_doing_ajax() ) { return $rates; } $has_free_offer_item = false; foreach ( $package['contents'] as $cart_item ) { if ( ! is_array( $cart_item ) ) { continue; } $prod_id = isset( $cart_item['product_id'] ) ? absint( $cart_item['product_id'] ) : 0; $var_id = isset( $cart_item['variation_id'] ) ? absint( $cart_item['variation_id'] ) : 0; $item_id = $var_id > 0 ? $var_id : $prod_id; if ( $prod_id > 0 && $this->is_product_live( $prod_id ) && $this->is_item_free_delivery( $item_id, $prod_id ) ) { $has_free_offer_item = true; break; } } if ( ! $has_free_offer_item ) { return $rates; } foreach ( $rates as $rate_id => $rate ) { if ( ! is_object( $rate ) ) { continue; } $method_id = method_exists( $rate, 'get_method_id' ) ? (string) $rate->get_method_id() : ( isset( $rate->method_id ) ? (string) $rate->method_id : '' ); if ( 'local_pickup' === $method_id ) { continue; } if ( method_exists( $rate, 'set_cost' ) ) { $rate->set_cost( 0 ); } else { $rate->cost = 0; } if ( method_exists( $rate, 'set_taxes' ) ) { $rate->set_taxes( array() ); } else { $rate->taxes = array(); } $cur_lbl = method_exists( $rate, 'get_label' ) ? (string) $rate->get_label() : ( isset( $rate->label ) ? (string) $rate->label : 'Delivery' ); if ( false === stripos( $cur_lbl, 'Free' ) ) { $new_lbl = $cur_lbl . ' (Free Delivery)'; if ( method_exists( $rate, 'set_label' ) ) { $rate->set_label( $new_lbl ); } else { $rate->label = $new_lbl; } } } return $rates; } /** * Show Free Delivery tag on Cart & Checkout item summary */ public function filter_cart_item_free_delivery_badge( $item_data, $cart_item ) { if ( ! is_array( $item_data ) || ! is_array( $cart_item ) ) { return $item_data; } $prod_id = isset( $cart_item['product_id'] ) ? absint( $cart_item['product_id'] ) : 0; $var_id = isset( $cart_item['variation_id'] ) ? absint( $cart_item['variation_id'] ) : 0; $item_id = $var_id > 0 ? $var_id : $prod_id; if ( $prod_id > 0 && $this->is_product_live( $prod_id ) && $this->is_item_free_delivery( $item_id, $prod_id ) ) { $item_data[] = array( 'key' => 'Offer Perk', 'value' => 'Free Delivery', 'display' => 'Free Delivery', ); } return $item_data; } /** * AJAX: Save Single Product / Variation Offer Price, Free Delivery & Schedule from Table */ public function ajax_save_single_item() { check_ajax_referer( 'offercrisp_ajax_nonce', 'nonce' ); if ( ! current_user_can( 'manage_options' ) ) { wp_send_json_error( array( 'message' => 'Unauthorized' ) ); } $item_id = isset( $_POST['item_id'] ) ? absint( $_POST['item_id'] ) : 0; $parent_id = isset( $_POST['parent_id'] ) ? absint( $_POST['parent_id'] ) : $item_id; $price = isset( $_POST['offer_price'] ) ? sanitize_text_field( wp_unslash( $_POST['offer_price'] ) ) : ''; $free_delivery = isset( $_POST['free_delivery'] ) ? sanitize_text_field( wp_unslash( $_POST['free_delivery'] ) ) : null; $start = isset( $_POST['offer_start'] ) ? sanitize_text_field( wp_unslash( $_POST['offer_start'] ) ) : null; $end = isset( $_POST['offer_end'] ) ? sanitize_text_field( wp_unslash( $_POST['offer_end'] ) ) : null; if ( ! $item_id && ! $parent_id ) { wp_send_json_error( array( 'message' => 'Invalid product ID' ) ); } if ( $item_id > 0 && isset( $_POST['offer_price'] ) ) { if ( '' === $price || floatval( $price ) <= 0 ) { delete_post_meta( $item_id, self::META_PRICE ); } else { update_post_meta( $item_id, self::META_PRICE, floatval( $price ) ); } } if ( $item_id > 0 && null !== $free_delivery ) { if ( '1' === (string) $free_delivery ) { update_post_meta( $item_id, self::META_FREE_DELIVERY, '1' ); } else { delete_post_meta( $item_id, self::META_FREE_DELIVERY ); } } if ( null !== $start && $parent_id > 0 ) { if ( '' === $start ) { delete_post_meta( $parent_id, self::META_START ); } else { update_post_meta( $parent_id, self::META_START, substr( str_replace( ' ', 'T', trim( $start ) ), 0, 16 ) ); } } if ( null !== $end && $parent_id > 0 ) { if ( '' === $end ) { delete_post_meta( $parent_id, self::META_END ); } else { update_post_meta( $parent_id, self::META_END, substr( str_replace( ' ', 'T', trim( $end ) ), 0, 16 ) ); } } if ( isset( $_POST['tz_offset_mins'] ) && '' !== $_POST['tz_offset_mins'] ) { $s = $this->get_settings(); $s['tz_offset_mins'] = intval( wp_unslash( $_POST['tz_offset_mins'] ) ); update_option( self::OPTION_KEY, $s, true ); $this->settings = $s; } $this->clear_performance_caches(); wp_send_json_success( array( 'message' => 'Saved' ) ); } private function should_load_frontend_assets() { $s = $this->get_settings(); if ( ! empty( $s['enabled'] ) && '1' === (string) $s['enabled'] ) { return true; } if ( $this->is_selected_offer_page() || $this->is_single_product_context() ) { return true; } global $post; if ( is_a( $post, 'WP_Post' ) && has_shortcode( $post->post_content, 'offer_page' ) ) { return true; } return false; } /** * Enqueue Frontend CSS & Vanilla JS */ public function enqueue_frontend_assets() { if ( ! $this->should_load_frontend_assets() ) { return; } $s = $this->get_settings(); wp_register_style( 'offercrisp-frontend', false, array(), self::VERSION ); wp_enqueue_style( 'offercrisp-frontend' ); $c_prim = ! empty( $s['primary_color'] ) ? $s['primary_color'] : '#EC4899'; $c_pdark = ! empty( $s['primary_dark'] ) ? $s['primary_dark'] : '#BE185D'; $c_sec = ! empty( $s['secondary_color'] ) ? $s['secondary_color'] : '#F97316'; $c_live = ! empty( $s['live_green'] ) ? $s['live_green'] : '#10B981'; $c_up = ! empty( $s['upcoming_purple'] ) ? $s['upcoming_purple'] : '#A855F7'; $c_hbg = ! empty( $s['hero_bg'] ) ? $s['hero_bg'] : '#0F0208'; $c_htitle = ! empty( $s['hero_title_accent'] ) ? $s['hero_title_accent'] : '#F59E0B'; $c_htimer = ! empty( $s['hero_timer_bg'] ) ? $s['hero_timer_bg'] : '#241520'; $c_sp_mid = ! empty( $s['sp_bar_mid'] ) ? $s['sp_bar_mid'] : $c_prim; $c_sp_end = ! empty( $s['sp_bar_end'] ) ? $s['sp_bar_end'] : $c_sec; $c_sp_text = ! empty( $s['sp_bar_text'] ) ? $s['sp_bar_text'] : '#FFFFFF'; $c_sp_timer = ! empty( $s['sp_bar_timer_bg'] ) ? $s['sp_bar_timer_bg'] : '#3A0E24'; $custom_css = " :root { --of-primary: " . esc_attr( $c_prim ) . "; --of-primary-dark: " . esc_attr( $c_pdark ) . "; --of-secondary: " . esc_attr( $c_sec ) . "; --of-live: " . esc_attr( $c_live ) . "; --of-upcoming: " . esc_attr( $c_up ) . "; --of-hero-bg: " . esc_attr( $c_hbg ) . "; --of-hero-title-accent: " . esc_attr( $c_htitle ) . "; --of-hero-timer-bg: " . esc_attr( $c_htimer ) . "; --of-sp-mid: " . esc_attr( $c_sp_mid ) . "; --of-sp-end: " . esc_attr( $c_sp_end ) . "; --of-sp-text: " . esc_attr( $c_sp_text ) . "; --of-sp-timer-bg: " . esc_attr( $c_sp_timer ) . "; --of-primary-glow: " . self::hex_to_rgba( $c_prim, 0.22 ) . "; --of-secondary-glow: " . self::hex_to_rgba( $c_sec, 0.16 ) . "; --of-secondary-border: " . self::hex_to_rgba( $c_sec, 0.50 ) . "; --of-live-bg: " . self::hex_to_rgba( $c_live, 0.16 ) . "; --of-live-border: " . self::hex_to_rgba( $c_live, 0.42 ) . "; --of-upcoming-bg: " . self::hex_to_rgba( $c_up, 0.18 ) . "; --of-upcoming-border: " . self::hex_to_rgba( $c_up, 0.45 ) . "; --of-font: -apple-system, BlinkMacSystemFont, 'Segoe UI', Inter, Roboto, Oxygen, Ubuntu, sans-serif; } .of-offer-wrap, .of-offer-wrap *, .of-single-product-bar, .of-single-product-bar *, .of-floating-badge { font-family: var(--of-font) !important; box-sizing: border-box; } .of-offer-wrap { max-width: 1240px; width: 100%; margin: 24px auto 48px; padding: 0 16px; } .of-hero-banner { position: relative; background: var(--of-hero-bg); border-radius: 14px; overflow: hidden; padding: 40px 44px; color: #ffffff; display: flex; align-items: center; justify-content: space-between; gap: 36px; border: 1px solid rgba(255, 255, 255, 0.08); box-shadow: 0 12px 30px rgba(15, 23, 42, 0.14); margin-bottom: 28px; } .of-hero-banner::before { content: ''; position: absolute; top: 0; left: 0; right: 0; height: 3px; background: var(--of-primary); z-index: 3; } .of-hero-glow { display: none; } .of-hero-rings { display: none; } .of-hero-left { position: relative; z-index: 2; flex: 1 1 58%; } .of-hero-right { position: relative; z-index: 2; flex: 0 0 360px; border-left: 1px solid rgba(255, 255, 255, 0.08); padding-left: 40px; display: flex; flex-direction: column; align-items: center; text-align: center; } .of-status-pill { display: inline-flex; align-items: center; gap: 8px; padding: 6px 16px; border-radius: 999px; font-size: 11px; font-weight: 700; letter-spacing: 1px; text-transform: uppercase; margin-bottom: 18px; } .of-status-pill.is-inactive { background: rgba(255, 255, 255, 0.07); border: 1px solid rgba(255, 255, 255, 0.12); color: rgba(255, 255, 255, 0.55); } .of-status-pill.is-inactive .of-dot { width: 7px; height: 7px; border-radius: 50%; background: rgba(255, 255, 255, 0.4); } .of-status-pill.is-live { background: rgba(255, 255, 255, 0.08); border: 1px solid rgba(255, 255, 255, 0.16); color: #F8FAFC; } .of-status-pill.is-live .of-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--of-live); } .of-status-pill.is-upcoming { background: rgba(255, 255, 255, 0.08); border: 1px solid rgba(255, 255, 255, 0.16); color: #E2E8F0; } .of-status-pill.is-upcoming .of-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--of-upcoming); } .of-hero-title { font-size: 40px; font-weight: 800; line-height: 1.15; margin: 0 0 12px; letter-spacing: -0.02em; color: #ffffff !important; } .of-hero-title .of-title-accent { color: var(--of-hero-title-accent) !important; -webkit-text-fill-color: var(--of-hero-title-accent) !important; } .of-hero-desc { font-size: 14.5px; color: rgba(255, 255, 255, 0.72) !important; margin: 0 0 20px; max-width: 540px; line-height: 1.6; } .of-hero-tags { display: flex; flex-wrap: wrap; gap: 10px; } .of-tag-special { padding: 6px 14px; border-radius: 8px; font-size: 11px; font-weight: 700; letter-spacing: 0.5px; text-transform: uppercase; background: rgba(255, 255, 255, 0.10); border: 1px solid rgba(255, 255, 255, 0.16); color: #F8FAFC; } .of-tag-active { display: inline-flex; align-items: center; gap: 7px; padding: 6px 14px; border-radius: 8px; font-size: 11px; font-weight: 600; background: rgba(255, 255, 255, 0.06); border: 1px solid rgba(255, 255, 255, 0.14); color: #E2E8F0; } .of-tag-active::before { content: ''; width: 6px; height: 6px; border-radius: 50%; background: var(--of-live); } .of-sale-emblem { width: 64px; height: 64px; border-radius: 50%; border: 1px solid rgba(255, 255, 255, 0.18); background: rgba(255, 255, 255, 0.06); display: flex; flex-direction: column; align-items: center; justify-content: center; margin-bottom: 14px; color: #FFFFFF; } .of-sale-emblem .of-sale-lbl { font-size: 9px; font-weight: 700; letter-spacing: 1.5px; color: rgba(255, 255, 255, 0.72); margin-top: 3px; } .of-ends-header { font-size: 11.5px; font-weight: 700; letter-spacing: 1.4px; text-transform: uppercase; color: rgba(255, 255, 255, 0.88); margin-bottom: 14px; display: flex; align-items: center; gap: 6px; } .of-countdown-grid { display: flex; align-items: center; gap: 8px; margin-bottom: 14px; } .of-cd-col { display: flex; flex-direction: column; align-items: center; } .of-cd-box { width: 58px; height: 58px; border-radius: 12px; background: var(--of-hero-timer-bg); border: 1px solid rgba(255, 255, 255, 0.16); display: flex; align-items: center; justify-content: center; font-size: 23px; font-weight: 800; color: #ffffff; letter-spacing: 0.5px; font-variant-numeric: tabular-nums; box-shadow: inset 0 1px 1px rgba(255, 255, 255, 0.12); } .of-cd-sep { font-size: 20px; font-weight: 700; color: rgba(255, 255, 255, 0.4); margin-top: -16px; } .of-cd-unit { font-size: 9.5px; font-weight: 700; letter-spacing: 1px; text-transform: uppercase; color: rgba(255, 255, 255, 0.55); margin-top: 6px; } .of-hurry-note { font-size: 12px; color: rgba(255, 255, 255, 0.65); font-weight: 500; } .of-products-card { background: #ffffff; border: 1px solid #EAECEF; border-radius: 18px; padding: 28px; box-shadow: 0 8px 30px rgba(0, 0, 0, 0.04); } .of-product-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); gap: 22px; } .of-product-item { position: relative; background: #ffffff; border: 1px solid #F1F5F9; border-radius: 14px; padding: 18px 16px; text-align: center; transition: transform 0.2s ease, box-shadow 0.2s ease; text-decoration: none !important; display: flex; flex-direction: column; align-items: center; } .of-product-item:hover { transform: translateY(-4px); box-shadow: 0 12px 28px rgba(15, 23, 42, 0.08); border-color: #CBD5E1; } .of-product-thumb-wrap { position: relative; width: 100%; height: 180px; display: flex; align-items: center; justify-content: center; margin-bottom: 14px; } .of-product-thumb-wrap img { max-width: 100%; max-height: 165px; width: auto; height: auto; object-fit: contain; } .of-floating-badge { position: absolute; top: 8px; right: 8px; z-index: 25; background: linear-gradient(135deg, var(--of-primary-dark) 0%, var(--of-sp-mid) 50%, var(--of-sp-end) 100%) !important; color: var(--of-sp-text) !important; font-size: 10.5px !important; font-weight: 800 !important; letter-spacing: 0.5px !important; text-transform: uppercase !important; padding: 5px 12px !important; border-radius: 999px !important; white-space: nowrap !important; box-shadow: 0 6px 16px var(--of-primary-glow), inset 0 1px 0 rgba(255, 255, 255, 0.28) !important; border: 1px solid rgba(255, 255, 255, 0.22) !important; display: inline-flex !important; align-items: center !important; justify-content: center !important; gap: 5px !important; line-height: 1.1 !important; pointer-events: none; } .of-offer-wrap .of-product-thumb-wrap .of-floating-badge { top: 6px; right: 6px; } .of-upgraded-sale-badge { background: linear-gradient(135deg, var(--of-primary-dark) 0%, var(--of-sp-mid) 50%, var(--of-sp-end) 100%) !important; color: var(--of-sp-text) !important; font-size: 10.5px !important; font-weight: 800 !important; letter-spacing: 0.5px !important; text-transform: uppercase !important; padding: 5px 12px !important; border-radius: 999px !important; white-space: nowrap !important; box-shadow: 0 6px 16px var(--of-primary-glow), inset 0 1px 0 rgba(255, 255, 255, 0.28) !important; border: 1px solid rgba(255, 255, 255, 0.22) !important; display: inline-flex !important; align-items: center !important; justify-content: center !important; gap: 4px !important; line-height: 1.1 !important; width: auto !important; height: auto !important; min-width: 0 !important; min-height: 0 !important; } .of-product-name { font-size: 14px; font-weight: 700; color: #1E293B !important; margin: 0 0 8px; line-height: 1.4; } .of-product-price { font-size: 14.5px; font-weight: 700; color: #EF4444; } .of-product-price del { color: #94A3B8; font-weight: 500; margin-right: 6px; font-size: 13px; } .of-product-price ins { text-decoration: none; color: #EF4444; font-weight: 800; } .of-single-product-bar { width: 100%; flex: 0 0 100%; grid-column: 1 / -1; clear: both; background: linear-gradient(90deg, var(--of-primary-dark) 0%, var(--of-sp-mid) 48%, var(--of-sp-end) 100%); border-radius: 16px; padding: 16px 28px; margin: 8px 0 24px 0; color: var(--of-sp-text); display: flex; flex-direction: row; align-items: center; justify-content: space-between; gap: 20px; box-shadow: 0 12px 30px var(--of-primary-glow); z-index: 20; position: relative; } .of-sp-left { display: flex; flex-direction: row; align-items: center; gap: 14px; min-width: 0; } .of-sp-icon-box { width: 48px; height: 48px; border-radius: 13px; background: rgba(255, 255, 255, 0.14); border: 1px solid rgba(255, 255, 255, 0.28); display: flex; align-items: center; justify-content: center; flex-shrink: 0; } .of-sp-title { font-size: 16px; font-weight: 800; line-height: 1.2; margin: 0 0 4px; color: var(--of-sp-text) !important; display: flex; align-items: center; gap: 6px; white-space: nowrap; } .of-sp-sub { font-size: 12px; color: var(--of-sp-text) !important; opacity: 0.9; margin: 0; white-space: nowrap; } .of-sp-center { display: flex; align-items: center; gap: 10px; flex-shrink: 0; } .of-sp-pill-flash { padding: 7px 20px; border-radius: 999px; background: rgba(255, 255, 255, 0.18); border: 1px solid rgba(255, 255, 255, 0.42); font-size: 11.5px; font-weight: 800; letter-spacing: 0.9px; text-transform: uppercase; color: var(--of-sp-text); } .of-sp-pill-ends { padding: 7px 15px; border-radius: 999px; background: var(--of-sp-timer-bg); border: 1px solid rgba(255, 255, 255, 0.22); font-size: 10.5px; font-weight: 700; letter-spacing: 0.8px; text-transform: uppercase; color: var(--of-sp-text); } .of-sp-right { flex-shrink: 0; } .of-sp-right .of-countdown-grid { margin-bottom: 0; } .of-sp-right .of-cd-box { width: 48px; height: 48px; font-size: 19px; border-radius: 11px; background: var(--of-sp-timer-bg); color: var(--of-sp-text); border: 1px solid rgba(255, 255, 255, 0.35); } .of-sp-right .of-cd-unit { color: rgba(255, 255, 255, 0.85); font-size: 8.5px; margin-top: 5px; } .of-sp-right .of-cd-sep { color: rgba(255, 255, 255, 0.65); } @keyframes ofPulseDot { 0%, 100% { transform: scale(1); opacity: 1; } 50% { transform: scale(1.35); opacity: 0.65; } } @keyframes ofFloatGlow { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-4px); } } @media (max-width: 768px) { .of-hero-banner { flex-direction: column; padding: 28px 20px; text-align: center; gap: 22px; } .of-hero-tags { justify-content: center; } .of-hero-title { font-size: 28px; } .of-hero-right { border-left: none; border-top: 1px solid rgba(255, 255, 255, 0.1); padding-left: 0; padding-top: 22px; width: 100%; flex: unset; } .of-product-grid { grid-template-columns: repeat(2, 1fr); gap: 12px; } .of-single-product-bar { flex-direction: row !important; align-items: center !important; justify-content: space-between !important; padding: 14px 14px !important; gap: 10px !important; border-radius: 14px !important; text-align: left !important; } .of-sp-center { display: none !important; } .of-sp-left { flex-direction: row !important; align-items: center !important; gap: 10px !important; flex: 1 1 auto; min-width: 0; } .of-sp-icon-box { width: 38px !important; height: 38px !important; border-radius: 10px !important; } .of-sp-icon-box svg { width: 22px !important; height: 22px !important; } .of-sp-title { font-size: 13.5px !important; margin: 0 0 2px !important; white-space: nowrap; } .of-sp-sub { font-size: 10px !important; line-height: 1.25 !important; white-space: normal; } .of-sp-right { flex: 0 0 auto; } .of-sp-right .of-countdown-grid { gap: 4px !important; margin-bottom: 0 !important; } .of-sp-right .of-cd-col { display: flex !important; flex-direction: column !important; align-items: center !important; } .of-sp-right .of-cd-box { width: 34px !important; height: 34px !important; font-size: 13px !important; border-radius: 8px !important; } .of-sp-right .of-cd-sep { font-size: 13px !important; margin-top: -12px !important; } .of-sp-right .of-cd-unit { font-size: 7px !important; margin-top: 3px !important; letter-spacing: 0.5px !important; } } "; wp_add_inline_style( 'offercrisp-frontend', $custom_css ); wp_register_script( 'offercrisp-countdown', false, array(), self::VERSION, true ); wp_enqueue_script( 'offercrisp-countdown' ); $js = " window.offercrispUpdateTimers = function(){ if(document.hidden) return; var timers = document.querySelectorAll('[data-of-countdown]'); if(!timers.length) return; var nowSec = Math.floor(Date.now() / 1000); for(var i = 0; i < timers.length; i++){ var el = timers[i]; var target = parseInt(el.getAttribute('data-of-countdown'), 10); if(!target) continue; var diff = target - nowSec; if(diff <= 0){ diff = 0; if(!el.getAttribute('data-of-reloaded')){ el.setAttribute('data-of-reloaded', '1'); setTimeout(function(){ window.location.reload(); }, 1000); } } var pad = function(n){ return n < 10 ? '0' + n : '' + n; }; var d = pad(Math.floor(diff / 86400)); var h = pad(Math.floor((diff % 86400) / 3600)); var m = pad(Math.floor((diff % 3600) / 60)); var s = pad(diff % 60); var dEl = el.querySelector('.of-val-day'); var hEl = el.querySelector('.of-val-hour'); var mEl = el.querySelector('.of-val-min'); var sEl = el.querySelector('.of-val-sec'); if(dEl && dEl.textContent !== d) dEl.textContent = d; if(hEl && hEl.textContent !== h) hEl.textContent = h; if(mEl && mEl.textContent !== m) mEl.textContent = m; if(sEl && sEl.textContent !== s) sEl.textContent = s; } }; if(document.readyState === 'loading'){ document.addEventListener('DOMContentLoaded', window.offercrispUpdateTimers); } else { window.offercrispUpdateTimers(); } setInterval(window.offercrispUpdateTimers, 1000); "; wp_add_inline_script( 'offercrisp-countdown', $js ); } private function format_hero_title( $title ) { $title = trim( wp_strip_all_tags( $title ) ); if ( '' === $title ) { return ''; } $parts = preg_split( '/\s+/', $title, 2 ); if ( count( $parts ) < 2 ) { return '' . esc_html( $title ) . ''; } return esc_html( $parts[0] ) . ' ' . esc_html( $parts[1] ) . ''; } /** * Build the Offer Page HTML (Hero Banner + Unlimited Active Tagged Products Grid) */ private function build_offer_page_html() { $s = $this->get_settings(); $state = $this->get_global_state(); $target_ts = $this->get_offer_page_target_timestamp( $state ); $target_utc = $this->local_ts_to_utc( $target_ts ); ob_start(); ?>
LIVE NOW

format_hero_title( $s['page_title'] ), self::allowed_html(), self::allowed_protocols() ); ?>

UPCOMING

format_hero_title( $s['page_title'] ), self::allowed_html(), self::allowed_protocols() ); ?>

INACTIVE

format_hero_title( $s['page_title'] ), self::allowed_html(), self::allowed_protocols() ); ?>

render_slot_icon( $s['icon_hero_sale'], $s['custom_icon_hero_sale'], 22 ), self::allowed_html(), self::allowed_protocols() ); ?> SALE
00
DAY
:
00
HOUR
:
00
MIN
:
00
SEC
get_runtime_cache(); $active_ids = array(); foreach ( array_keys( $cache['parents'] ) as $pid ) { if ( $this->is_product_live( $pid ) ) { $active_ids[] = $pid; } } $badge_label = ! empty( $s['badge_text'] ) ? $s['badge_text'] : strtoupper( $s['offer_name'] ); ?>
-1) $products_q = new WP_Query( array( 'post_type' => 'product', 'post_status' => 'publish', 'post__in' => $active_ids, 'posts_per_page' => -1, 'orderby' => 'post__in', 'ignore_sticky_posts' => true, 'no_found_rows' => true, 'update_post_term_cache' => false, ) ); ?>

No active offer products right now for tag .

offer_page_rendered ) { return ''; } $this->offer_page_rendered = true; return $this->build_offer_page_html(); } public function maybe_inject_offer_page_content( $content ) { if ( is_admin() || wp_doing_ajax() || is_feed() ) { return $content; } if ( doing_filter( 'wp_head' ) || ! did_action( 'wp_head' ) ) { return $content; } $s = $this->get_settings(); if ( '1' !== (string) $s['enabled'] ) { return $content; } if ( $this->is_selected_offer_page() ) { if ( $this->offer_page_rendered ) { return $content; } return $this->render_offer_page_shortcode(); } return $content; } public function maybe_render_on_wc_archive() { $s = $this->get_settings(); if ( '1' !== (string) $s['enabled'] ) { return; } if ( $this->is_selected_offer_page() && ! $this->offer_page_rendered ) { echo wp_kses( $this->render_offer_page_shortcode(), self::allowed_html(), self::allowed_protocols() ); } } public function render_offer_page_dom_guarantee() { $s = $this->get_settings(); if ( '1' !== (string) $s['enabled'] ) { return; } if ( ! $this->is_selected_offer_page() ) { return; } $page_html = $this->build_offer_page_html(); wp_enqueue_script( 'offercrisp-offer-page', plugin_dir_url( __FILE__ ) . 'assets/js/offer-page.js', array(), self::VERSION, true ); wp_localize_script( 'offercrisp-offer-page', 'offercrispPageData', array( 'html' => $page_html, ) ); } private function get_single_product_bar_html( $product ) { $s = $this->get_settings(); $b_state = $this->get_product_banner_state( $product, true ); $target_ts = $this->get_product_end_timestamp( $product ); $target_utc = $this->local_ts_to_utc( $target_ts ); $pill_main = ( 'upcoming' === $b_state ) ? 'UPCOMING' : 'FLASH SALE'; $pill_time = ( 'upcoming' === $b_state ) ? 'STARTS IN' : 'ENDS IN'; ob_start(); ?>
render_slot_icon( $s['icon_sp_box'], $s['custom_icon_sp_box'], 26 ); ?>
render_slot_icon( $s['icon_sp_title'], $s['custom_icon_sp_title'], 17 ), self::allowed_html(), self::allowed_protocols() ); ?>

00
DAY
:
00
HOUR
:
00
MIN
:
00
SEC
resolve_current_single_product(); if ( is_object( $p ) ) { $this->early_product = $p; } } private function resolve_current_single_product() { if ( is_object( $this->early_product ) ) { return $this->early_product; } if ( ! function_exists( 'wc_get_product' ) ) { return null; } $qobj = get_queried_object(); if ( is_object( $qobj ) && isset( $qobj->post_type ) && 'product' === $qobj->post_type && ! empty( $qobj->ID ) ) { $p = wc_get_product( $qobj->ID ); if ( is_object( $p ) ) { return $p; } } $qid = get_queried_object_id(); if ( $qid && 'product' === get_post_type( $qid ) ) { $p = wc_get_product( $qid ); if ( is_object( $p ) ) { return $p; } } global $product, $post; if ( is_object( $product ) && method_exists( $product, 'get_id' ) ) { return $product; } if ( is_object( $post ) && isset( $post->post_type ) && 'product' === $post->post_type ) { $p = wc_get_product( $post->ID ); if ( is_object( $p ) ) { return $p; } } if ( ! empty( $_SERVER['REQUEST_URI'] ) ) { $req_path = wp_parse_url( sanitize_text_field( wp_unslash( $_SERVER['REQUEST_URI'] ) ), PHP_URL_PATH ); if ( $req_path ) { $slug = sanitize_title( basename( untrailingslashit( $req_path ) ) ); if ( '' !== $slug && 'shop' !== $slug && 'offer' !== $slug ) { $found = get_posts( array( 'name' => $slug, 'post_type' => 'product', 'post_status' => 'publish', 'posts_per_page' => 1, 'fields' => 'ids', 'no_found_rows' => true, 'update_post_meta_cache' => false, 'update_post_term_cache' => false, ) ); if ( ! empty( $found[0] ) ) { $p = wc_get_product( absint( $found[0] ) ); if ( is_object( $p ) ) { return $p; } } } } } return null; } private function is_single_product_context() { if ( is_object( $this->early_product ) ) { return true; } if ( ( function_exists( 'is_product' ) && is_product() ) || is_singular( 'product' ) || 'product' === get_post_type() ) { return true; } return ( null !== $this->resolve_current_single_product() ); } public function render_single_product_offer_bar() { if ( $this->single_bar_rendered ) { return; } if ( ! $this->is_single_product_context() ) { return; } $product = $this->resolve_current_single_product(); if ( ! $product ) { return; } $b_state = $this->get_product_banner_state( $product, true ); if ( 'live' !== $b_state && 'upcoming' !== $b_state ) { return; } $this->single_bar_rendered = true; echo wp_kses( $this->get_single_product_bar_html( $product ), self::allowed_html(), self::allowed_protocols() ); } /** * Universal Single Product Banner Placement Engine (Guarantees Banner is ALWAYS Above the Product Image on Mobile & Desktop) */ public function render_single_product_bar_fallback() { if ( ! $this->is_single_product_context() ) { return; } $product = $this->resolve_current_single_product(); if ( ! ( $product instanceof WC_Product ) ) { return; } $b_state = $this->get_product_banner_state( $product, true ); if ( 'live' !== $b_state && 'upcoming' !== $b_state ) { return; } $bar_html = $this->get_single_product_bar_html( $product ); $prod_title = wp_strip_all_tags( $product->get_name() ); $raw_cur_sym = function_exists( 'get_woocommerce_currency_symbol' ) ? get_woocommerce_currency_symbol() : '$'; $currency_symbol = html_entity_decode( wp_strip_all_tags( $raw_cur_sym ), ENT_QUOTES, 'UTF-8' ); $decimals = function_exists( 'wc_get_price_decimals' ) ? wc_get_price_decimals() : 2; $var_offer_map = array(); $this->applying_price = true; if ( $product->is_type( 'variable' ) ) { $children = $product->get_children(); foreach ( $children as $vid ) { $vobj = function_exists( 'wc_get_product' ) ? wc_get_product( $vid ) : null; if ( ! $vobj ) { continue; } $offer_p = $this->calculate_offer_price( $vobj ); $base_p = $this->get_raw_base_price( $vobj ); $raw_reg = (float) get_post_meta( $vid, '_regular_price', true ); if ( $raw_reg > $base_p ) { $base_p = $raw_reg; } $attrs = method_exists( $vobj, 'get_variation_attributes' ) ? array_values( $vobj->get_variation_attributes() ) : array(); $var_offer_map[] = array( 'id' => absint( $vid ), 'attrs' => array_values( array_filter( array_map( 'strval', $attrs ) ) ), 'offer' => ( null !== $offer_p && $offer_p > 0 ) ? (float) $offer_p : 0.0, 'base' => (float) $base_p, 'base_fmt' => number_format( (float) $base_p, $decimals, '.', ',' ) . $currency_symbol, 'pct_off' => ( $offer_p > 0 && $base_p > $offer_p ) ? (int) round( ( ( $base_p - $offer_p ) / $base_p ) * 100 ) : 0, 'free_deliv' => $this->is_item_free_delivery( $vid, $product->get_id() ), ); } } else { $offer_p = $this->calculate_offer_price( $product ); $base_p = $this->get_raw_base_price( $product ); $raw_reg = (float) get_post_meta( $product->get_id(), '_regular_price', true ); if ( $raw_reg > $base_p ) { $base_p = $raw_reg; } $var_offer_map[] = array( 'id' => absint( $product->get_id() ), 'attrs' => array(), 'offer' => ( null !== $offer_p && $offer_p > 0 ) ? (float) $offer_p : 0.0, 'base' => (float) $base_p, 'base_fmt' => number_format( (float) $base_p, $decimals, '.', ',' ) . $currency_symbol, 'pct_off' => ( $offer_p > 0 && $base_p > $offer_p ) ? (int) round( ( ( $base_p - $offer_p ) / $base_p ) * 100 ) : 0, 'free_deliv' => $this->is_item_free_delivery( $product->get_id(), $product->get_id() ), ); } $this->applying_price = false; wp_enqueue_script( 'offercrisp-single-product', plugin_dir_url( __FILE__ ) . 'assets/js/single-product.js', array(), self::VERSION, true ); wp_localize_script( 'offercrisp-single-product', 'offercrispSingleData', array( 'prodTitle' => $prod_title, 'html' => $bar_html, 'offerVarMap' => $var_offer_map, 'curSym' => $currency_symbol, ) ); } private function get_outside_card_badge_html() { $s = $this->get_settings(); $badge_label = ! empty( $s['badge_text'] ) ? $s['badge_text'] : strtoupper( $s['offer_name'] ); $ico_html = $this->render_slot_icon( $s['icon_card_badge'], $s['custom_icon_card_badge'], 12 ); return '' . $ico_html . ( '' !== $ico_html ? ' ' : '' ) . '' . esc_html( $badge_label ) . ''; } public function filter_woocommerce_sale_flash( $html, $post, $product ) { if ( is_object( $product ) && $this->is_product_live( $product ) ) { return $this->get_outside_card_badge_html(); } return $html; } public function render_outside_card_badge_upgrader() { if ( 'live' !== $this->get_global_state() ) { return; } $s = $this->get_settings(); $cache = $this->get_runtime_cache(); $apply_all = ( '1' === (string) $s['apply_all'] || empty( $cache['parents'] ) ); $live_slugs = array(); $live_ids = array(); if ( ! $apply_all && ! empty( $cache['parents'] ) ) { foreach ( array_keys( $cache['parents'] ) as $pid ) { if ( $this->is_product_live( $pid ) ) { $live_ids[] = absint( $pid ); $p_post = get_post( $pid ); if ( $p_post && ! empty( $p_post->post_name ) ) { $live_slugs[ $p_post->post_name ] = true; } } } } if ( ! $apply_all && empty( $live_ids ) ) { return; } $badge_label = ! empty( $s['badge_text'] ) ? $s['badge_text'] : strtoupper( $s['offer_name'] ); $ico_html = $this->render_slot_icon( $s['icon_card_badge'], $s['custom_icon_card_badge'], 12 ); $badge_inner = $ico_html . ( '' !== $ico_html ? ' ' : '' ) . '' . esc_html( $badge_label ) . ''; $full_badge = $this->get_outside_card_badge_html(); wp_enqueue_script( 'offercrisp-card-badges', plugin_dir_url( __FILE__ ) . 'assets/js/card-badges.js', array(), self::VERSION, true ); wp_localize_script( 'offercrisp-card-badges', 'offercrispBadgeData', array( 'applyAll' => (bool) $apply_all, 'liveSlugs' => $live_slugs, 'liveIds' => $live_ids, 'badgeInner' => $badge_inner, 'fullBadge' => $full_badge, ) ); } /** * Register Main Menu + Individual Submenu Items for Each Section */ public function register_admin_menu() { add_menu_page( 'OfferCrisp — General', 'OfferCrisp', 'manage_options', 'offercrisp-manager', array( $this, 'render_admin_page' ), 'dashicons-tag', 56 ); add_submenu_page( 'offercrisp-manager', 'General Configuration', 'General', 'manage_options', 'offercrisp-manager', array( $this, 'render_admin_page' ) ); add_submenu_page( 'offercrisp-manager', 'Products & Prices', 'Products & Prices', 'manage_options', 'offercrisp-products', array( $this, 'render_admin_page' ) ); add_submenu_page( 'offercrisp-manager', 'Global Schedule', 'Schedule', 'manage_options', 'offercrisp-schedule', array( $this, 'render_admin_page' ) ); add_submenu_page( 'offercrisp-manager', 'Content & Titles', 'Content & Titles', 'manage_options', 'offercrisp-content', array( $this, 'render_admin_page' ) ); add_submenu_page( 'offercrisp-manager', 'Color Theme', 'Color Theme', 'manage_options', 'offercrisp-colors', array( $this, 'render_admin_page' ) ); } public function handle_save_settings() { if ( ! current_user_can( 'manage_options' ) ) { wp_die( 'Unauthorized' ); } check_admin_referer( 'offercrisp_save_nonce' ); $current_saved = $this->get_settings(); $old_page_id = isset( $current_saved['offer_page_id'] ) ? absint( $current_saved['offer_page_id'] ) : 0; $defaults = $this->get_default_settings(); $new = array(); $new['enabled'] = isset( $_POST['enabled'] ) ? '1' : '0'; $new['apply_all'] = isset( $_POST['apply_all'] ) ? '1' : '0'; $new['table_override'] = isset( $_POST['table_override'] ) ? '1' : '0'; $new['schedule_enabled'] = isset( $_POST['schedule_enabled'] ) ? '1' : '0'; $new['offer_name'] = isset( $_POST['offer_name'] ) ? sanitize_text_field( wp_unslash( $_POST['offer_name'] ) ) : $defaults['offer_name']; $new['badge_text'] = isset( $_POST['badge_text'] ) ? sanitize_text_field( wp_unslash( $_POST['badge_text'] ) ) : $defaults['badge_text']; $new['tag_slug'] = isset( $_POST['tag_slug'] ) ? sanitize_text_field( wp_unslash( $_POST['tag_slug'] ) ) : $defaults['tag_slug']; $new['offer_page_id'] = isset( $_POST['offer_page_id'] ) ? absint( $_POST['offer_page_id'] ) : 0; $new['pricing_method'] = isset( $_POST['pricing_method'] ) ? sanitize_key( $_POST['pricing_method'] ) : 'table'; $new['discount_value'] = isset( $_POST['discount_value'] ) ? sanitize_text_field( wp_unslash( $_POST['discount_value'] ) ) : '20'; $new['discount_base'] = isset( $_POST['discount_base'] ) ? sanitize_key( $_POST['discount_base'] ) : 'sale'; $new['countdown_start'] = isset( $_POST['countdown_start'] ) ? sanitize_text_field( wp_unslash( $_POST['countdown_start'] ) ) : ''; $new['offer_start'] = isset( $_POST['offer_start'] ) ? sanitize_text_field( wp_unslash( $_POST['offer_start'] ) ) : ''; $new['offer_end'] = isset( $_POST['offer_end'] ) ? sanitize_text_field( wp_unslash( $_POST['offer_end'] ) ) : ''; $new['page_title'] = isset( $_POST['page_title'] ) ? sanitize_text_field( wp_unslash( $_POST['page_title'] ) ) : $defaults['page_title']; $new['page_description'] = isset( $_POST['page_description'] ) ? sanitize_text_field( wp_unslash( $_POST['page_description'] ) ) : $defaults['page_description']; $new['upcoming_message'] = isset( $_POST['upcoming_message'] ) ? sanitize_textarea_field( wp_unslash( $_POST['upcoming_message'] ) ) : $defaults['upcoming_message']; $new['ended_message'] = isset( $_POST['ended_message'] ) ? sanitize_textarea_field( wp_unslash( $_POST['ended_message'] ) ) : $defaults['ended_message']; $new['special_pill_text'] = isset( $_POST['special_pill_text'] ) ? sanitize_text_field( wp_unslash( $_POST['special_pill_text'] ) ) : $defaults['special_pill_text']; $new['active_pill_text'] = isset( $_POST['active_pill_text'] ) ? sanitize_text_field( wp_unslash( $_POST['active_pill_text'] ) ) : $defaults['active_pill_text']; $new['bar_subtitle'] = isset( $_POST['bar_subtitle'] ) ? sanitize_text_field( wp_unslash( $_POST['bar_subtitle'] ) ) : $defaults['bar_subtitle']; $new['hurry_text'] = isset( $_POST['hurry_text'] ) ? sanitize_text_field( wp_unslash( $_POST['hurry_text'] ) ) : $defaults['hurry_text']; $new['preset'] = isset( $_POST['preset'] ) ? sanitize_key( $_POST['preset'] ) : 'crimson'; $new['primary_color'] = ! empty( $_POST['primary_color'] ) ? sanitize_hex_color( wp_unslash( $_POST['primary_color'] ) ) : $defaults['primary_color']; $new['primary_dark'] = ! empty( $_POST['primary_dark'] ) ? sanitize_hex_color( wp_unslash( $_POST['primary_dark'] ) ) : $defaults['primary_dark']; $new['secondary_color'] = ! empty( $_POST['secondary_color'] ) ? sanitize_hex_color( wp_unslash( $_POST['secondary_color'] ) ) : $defaults['secondary_color']; $new['live_green'] = ! empty( $_POST['live_green'] ) ? sanitize_hex_color( wp_unslash( $_POST['live_green'] ) ) : $defaults['live_green']; $new['upcoming_purple'] = ! empty( $_POST['upcoming_purple'] ) ? sanitize_hex_color( wp_unslash( $_POST['upcoming_purple'] ) ) : $defaults['upcoming_purple']; $new['hero_bg'] = ! empty( $_POST['hero_bg'] ) ? sanitize_hex_color( wp_unslash( $_POST['hero_bg'] ) ) : $defaults['hero_bg']; $new['hero_title_accent'] = ! empty( $_POST['hero_title_accent'] ) ? sanitize_hex_color( wp_unslash( $_POST['hero_title_accent'] ) ) : $defaults['hero_title_accent']; $new['hero_timer_bg'] = ! empty( $_POST['hero_timer_bg'] ) ? sanitize_hex_color( wp_unslash( $_POST['hero_timer_bg'] ) ) : $defaults['hero_timer_bg']; $new['sp_bar_mid'] = ! empty( $_POST['sp_bar_mid'] ) ? sanitize_hex_color( wp_unslash( $_POST['sp_bar_mid'] ) ) : $new['primary_color']; $new['sp_bar_end'] = ! empty( $_POST['sp_bar_end'] ) ? sanitize_hex_color( wp_unslash( $_POST['sp_bar_end'] ) ) : $new['secondary_color']; $new['sp_bar_text'] = ! empty( $_POST['sp_bar_text'] ) ? sanitize_hex_color( wp_unslash( $_POST['sp_bar_text'] ) ) : $defaults['sp_bar_text']; $new['sp_bar_timer_bg'] = ! empty( $_POST['sp_bar_timer_bg'] ) ? sanitize_hex_color( wp_unslash( $_POST['sp_bar_timer_bg'] ) ) : $defaults['sp_bar_timer_bg']; $new['tz_offset_mins'] = isset( $_POST['tz_offset_mins'] ) && '' !== $_POST['tz_offset_mins'] ? intval( wp_unslash( $_POST['tz_offset_mins'] ) ) : $defaults['tz_offset_mins']; $new['icon_sp_box'] = isset( $_POST['icon_sp_box'] ) ? sanitize_key( $_POST['icon_sp_box'] ) : $defaults['icon_sp_box']; $new['custom_icon_sp_box'] = isset( $_POST['custom_icon_sp_box'] ) ? sanitize_text_field( wp_unslash( $_POST['custom_icon_sp_box'] ) ) : ''; $new['icon_sp_title'] = isset( $_POST['icon_sp_title'] ) ? sanitize_key( $_POST['icon_sp_title'] ) : $defaults['icon_sp_title']; $new['custom_icon_sp_title'] = isset( $_POST['custom_icon_sp_title'] ) ? sanitize_text_field( wp_unslash( $_POST['custom_icon_sp_title'] ) ) : ''; $new['icon_hero_sale'] = isset( $_POST['icon_hero_sale'] ) ? sanitize_key( $_POST['icon_hero_sale'] ) : $defaults['icon_hero_sale']; $new['custom_icon_hero_sale'] = isset( $_POST['custom_icon_hero_sale'] ) ? sanitize_text_field( wp_unslash( $_POST['custom_icon_hero_sale'] ) ) : ''; $new['icon_card_badge'] = isset( $_POST['icon_card_badge'] ) ? sanitize_key( $_POST['icon_card_badge'] ) : $defaults['icon_card_badge']; $new['custom_icon_card_badge'] = isset( $_POST['custom_icon_card_badge'] ) ? sanitize_text_field( wp_unslash( $_POST['custom_icon_card_badge'] ) ) : ''; $new['products_per_page'] = -1; $new = apply_filters( 'offercrisp_before_save_settings', $new ); update_option( self::OPTION_KEY, $new, true ); do_action( 'offercrisp_after_save_settings', $new ); $this->settings = $new; if ( isset( $_POST['prod_start'] ) && is_array( $_POST['prod_start'] ) ) { $starts = array_map( 'sanitize_text_field', wp_unslash( $_POST['prod_start'] ) ); foreach ( $starts as $pid => $st_val ) { $pid = absint( $pid ); $st_val = sanitize_text_field( $st_val ); if ( $pid > 0 ) { if ( '' === $st_val ) { delete_post_meta( $pid, self::META_START ); } else { update_post_meta( $pid, self::META_START, substr( str_replace( ' ', 'T', trim( $st_val ) ), 0, 16 ) ); } } } } if ( isset( $_POST['prod_end'] ) && is_array( $_POST['prod_end'] ) ) { $ends = array_map( 'sanitize_text_field', wp_unslash( $_POST['prod_end'] ) ); foreach ( $ends as $pid => $en_val ) { $pid = absint( $pid ); $en_val = sanitize_text_field( $en_val ); if ( $pid > 0 ) { if ( '' === $en_val ) { delete_post_meta( $pid, self::META_END ); } else { update_post_meta( $pid, self::META_END, substr( str_replace( ' ', 'T', trim( $en_val ) ), 0, 16 ) ); } } } } if ( isset( $_POST['item_offer_price'] ) && is_array( $_POST['item_offer_price'] ) ) { $prices = array_map( 'sanitize_text_field', wp_unslash( $_POST['item_offer_price'] ) ); $free_flags = isset( $_POST['item_free_delivery'] ) && is_array( $_POST['item_free_delivery'] ) ? array_map( 'sanitize_text_field', wp_unslash( $_POST['item_free_delivery'] ) ) : array(); foreach ( $prices as $iid => $pr_val ) { $iid = absint( $iid ); $pr_val = sanitize_text_field( $pr_val ); if ( $iid > 0 ) { if ( '' === $pr_val || floatval( $pr_val ) <= 0 ) { delete_post_meta( $iid, self::META_PRICE ); } else { update_post_meta( $iid, self::META_PRICE, floatval( $pr_val ) ); } if ( isset( $free_flags[ $iid ] ) && '1' === (string) $free_flags[ $iid ] ) { update_post_meta( $iid, self::META_FREE_DELIVERY, '1' ); } else { delete_post_meta( $iid, self::META_FREE_DELIVERY ); } } } } $this->sync_selected_offer_page( $new['offer_page_id'], $old_page_id ); $this->clear_performance_caches(); $active_slug = isset( $_POST['active_page_slug'] ) ? sanitize_key( wp_unslash( $_POST['active_page_slug'] ) ) : 'offercrisp-manager'; wp_safe_redirect( admin_url( 'admin.php?page=' . $active_slug . '&saved=1' ) ); exit; } /** * Get ALL Tagged Products for the Admin Table (No 10-item truncation so all 35+ products show together) */ private function get_admin_tagged_products( $paged = 1, $per_page = 500 ) { $cache = $this->get_runtime_cache(); $all_ids = array_keys( $cache['parents'] ); $total = count( $all_ids ); if ( 0 === $total ) { return array( 'ids' => array(), 'total' => 0, 'total_pages' => 1, 'paged' => 1, ); } $total_pages = max( 1, (int) ceil( $total / $per_page ) ); $paged = min( max( 1, $paged ), $total_pages ); $offset = ( $paged - 1 ) * $per_page; $slice = array_slice( $all_ids, $offset, $per_page ); return array( 'ids' => $slice, 'total' => $total, 'total_pages' => $total_pages, 'paged' => $paged, ); } private function get_current_admin_section() { // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Read-only admin page slug for tab routing. $page = isset( $_GET['page'] ) ? sanitize_key( wp_unslash( $_GET['page'] ) ) : 'offercrisp-manager'; $map = array( 'offercrisp-manager' => 'general', 'offercrisp-products' => 'products', 'offercrisp-schedule' => 'schedule', 'offercrisp-content' => 'content', 'offercrisp-colors' => 'colors', ); return isset( $map[ $page ] ) ? $map[ $page ] : 'general'; } public function render_admin_page() { $s = $this->get_settings(); $state = $this->get_global_state(); $page_id = absint( $s['offer_page_id'] ); $page_url = ( $page_id && get_post( $page_id ) ) ? get_permalink( $page_id ) : home_url( '/offer/' ); $page_title = ( $page_id && get_post( $page_id ) ) ? get_the_title( $page_id ) : 'Offer'; $all_pages = get_pages(); $currency_symbol = function_exists( 'get_woocommerce_currency_symbol' ) ? get_woocommerce_currency_symbol() : '$'; // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Read-only pagination query parameter. $paged = isset( $_GET['of_page'] ) ? max( 1, absint( $_GET['of_page'] ) ) : 1; $tagged_data = $this->get_admin_tagged_products( $paged, 500 ); $ajax_nonce = wp_create_nonce( 'offercrisp_ajax_nonce' ); $now_ts = $this->get_now_local_ts(); $active_sec = $this->get_current_admin_section(); // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Read-only admin page slug for active tab. $current_page_q = isset( $_GET['page'] ) ? sanitize_key( wp_unslash( $_GET['page'] ) ) : 'offercrisp-manager'; ?>
OfferCrisp v

STATUS OVERVIEW

Offer Status
Master Switch
Global Schedule
Tagged Products items
Target Tag

General Configuration

Control the master offer switch, target tag slug, and dedicated website offer page

Activate Offer
Turn ON to enable offer pricing, single product top banner, and the offer page
Apply to All Products
Enable to include every published store product regardless of tag
Displayed on the Single Product Top Banner
Displayed on outside product cards when the offer is active
Add this tag to any product and it will automatically appear in the Offer Page and Table
The selected page will automatically display the Offer Banner and all tagged products

Pricing Mode & Tagged Products ( Products)

Choose how offer prices are calculated and configure individual product prices & time windows

parse_local_dt( $p_start ) : 0; $p_en_ts = '' !== $p_end ? $this->parse_local_dt( $p_end ) : 0; if ( '' === $p_start && '' === $p_end ) { $status_lbl = ( '1' === (string) $s['schedule_enabled'] ) ? 'Global Schedule' : 'Always Active'; $status_color = '#10B981'; } elseif ( $p_en_ts > 0 && $now_ts >= $p_en_ts ) { $status_lbl = 'Ended (Reverted)'; $status_color = '#EF4444'; } elseif ( $p_st_ts > 0 && $now_ts < $p_st_ts ) { $status_lbl = 'Scheduled Next'; $status_color = '#A855F7'; } else { $status_lbl = 'Active Window'; $status_color = '#10B981'; } $thumb_url = get_the_post_thumbnail_url( $pid, 'thumbnail' ); ?> is_type( 'variable' ) ) : ?> get_children(); foreach ( $var_ids as $vid ) : $var_obj = wc_get_product( $vid ); if ( ! ( $var_obj instanceof WC_Product_Variation ) ) { continue; } $raw_reg = $var_obj->get_regular_price( 'edit' ); $raw_sale = $var_obj->get_sale_price( 'edit' ); $base_disp = ( '' !== $raw_sale && floatval( $raw_sale ) > 0 ) ? $raw_sale : $raw_reg; $saved_op = get_post_meta( $vid, self::META_PRICE, true ); $saved_fd = ( '1' === (string) get_post_meta( $vid, self::META_FREE_DELIVERY, true ) ); ?> get_regular_price( 'edit' ); $raw_sale = $prod_obj->get_sale_price( 'edit' ); $base_disp = ( '' !== $raw_sale && floatval( $raw_sale ) > 0 ) ? $raw_sale : $raw_reg; $saved_op = get_post_meta( $pid, self::META_PRICE, true ); $saved_fd = ( '1' === (string) get_post_meta( $pid, self::META_FREE_DELIVERY, true ) ); ?>
Product / Variation Current Price Offer Price Free Delivery Action
get_name() ); ?> # ●
Start: End:
get_name() ) ?: $var_obj->get_name() ); ?> #
Price
Simple Product
Price
No products found with tag . Assign this tag to any WooCommerce product and it will appear here automatically.

Global Campaign Schedule

Turn the master schedule ON when you want timed campaigns, or keep it OFF to run offers anytime

Enable Global Campaign Schedule
When OFF, the offer stays live as long as Activate Offer is ON. Turn ON to use start/end dates below.
Quick Start Live Offer Right Now:

Offer Page Content & Titles

Customize the headlines, status descriptions, and banner texts

Color Theme, Variations & Live Visual Studio

Select one of 5 universal theme presets or customize individual colors and icons with live preview

5 Universal Theme Presets
array( 'label' => 'Classic Slate', 'c1' => '#2563EB', 'c2' => '#111827', 'c3' => '#3B82F6', 'c4' => '#16A34A', 'c5' => '#64748B', 'c6' => '#111827', 'c7' => '#93C5FD', 'c8' => '#1F2937', 'c9' => '#1E293B', 'c10' => '#111827', 'c11' => '#FFFFFF', 'c12' => '#0F172A' ), 'pure_monochrome' => array( 'label' => 'Pure Monochrome', 'c1' => '#374151', 'c2' => '#09090B', 'c3' => '#6B7280', 'c4' => '#16A34A', 'c5' => '#71717A', 'c6' => '#09090B', 'c7' => '#E5E7EB', 'c8' => '#18181B', 'c9' => '#18181B', 'c10' => '#27272A', 'c11' => '#FFFFFF', 'c12' => '#09090B' ), 'commerce_blue' => array( 'label' => 'Commerce Blue', 'c1' => '#2563EB', 'c2' => '#1E3A8A', 'c3' => '#0284C7', 'c4' => '#16A34A', 'c5' => '#6366F1', 'c6' => '#0F172A', 'c7' => '#60A5FA', 'c8' => '#1E293B', 'c9' => '#1D4ED8', 'c10' => '#2563EB', 'c11' => '#FFFFFF', 'c12' => '#172554' ), 'warm_gold' => array( 'label' => 'Warm Gold', 'c1' => '#B45309', 'c2' => '#1C1917', 'c3' => '#D97706', 'c4' => '#16A34A', 'c5' => '#78716C', 'c6' => '#141210', 'c7' => '#FCD34D', 'c8' => '#26221E', 'c9' => '#292524', 'c10' => '#44403C', 'c11' => '#FFFFFF', 'c12' => '#1C1917' ), 'sale_crimson' => array( 'label' => 'Sale Crimson', 'c1' => '#DC2626', 'c2' => '#7F1D1D', 'c3' => '#B91C1C', 'c4' => '#16A34A', 'c5' => '#64748B', 'c6' => '#170B0B', 'c7' => '#FCA5A5', 'c8' => '#261414', 'c9' => '#991B1B', 'c10' => '#B91C1C', 'c11' => '#FFFFFF', 'c12' => '#450A0A' ), ); ?>
$p_data ) : ?>
Live Visual Preview — Check & Match Colors Before Publishing
Preview State:
1. Offer Page Main Hero Banner Preview
LIVE NOW
Steal the Deal
render_slot_icon( $s['icon_hero_sale'], $s['custom_icon_hero_sale'], 20 ), self::allowed_html(), self::allowed_protocols() ); ?> SALE
OFFER ENDS IN
'DAY', '05' => 'HOUR', '28' => 'MIN', '05 ' => 'SEC' ) as $num => $lbl ) : ?>
2. Single Product Top Long Bar Preview
render_slot_icon( $s['icon_sp_box'], $s['custom_icon_sp_box'], 24 ), self::allowed_html(), self::allowed_protocols() ); ?>
render_slot_icon( $s['icon_sp_title'], $s['custom_icon_sp_title'], 16 ), self::allowed_html(), self::allowed_protocols() ); ?>
FLASH SALE ENDS IN
'DAY', '05' => 'HOUR', '28' => 'MIN', '05 ' => 'SEC' ) as $num => $lbl ) : ?>
1. Offer Page Main Hero Banner Colors
2. Single Product Top Long Bar Colors
3. Banner & Badge Icons Customizer
'sp_box', 'title' => 'Single Product Bar — Left Box Icon', 'input_name' => 'icon_sp_box', 'custom_name' => 'custom_icon_sp_box', 'val' => $s['icon_sp_box'], 'custom_val' => $s['custom_icon_sp_box'], ), array( 'slot' => 'sp_title', 'title' => 'Single Product Bar — Title Icon', 'input_name' => 'icon_sp_title', 'custom_name' => 'custom_icon_sp_title', 'val' => $s['icon_sp_title'], 'custom_val' => $s['custom_icon_sp_title'], ), array( 'slot' => 'hero_sale', 'title' => 'Offer Page Hero — Circle SALE Icon', 'input_name' => 'icon_hero_sale', 'custom_name' => 'custom_icon_hero_sale', 'val' => $s['icon_hero_sale'], 'custom_val' => $s['custom_icon_hero_sale'], ), array( 'slot' => 'card_badge', 'title' => 'Outside Product Card Badge Icon', 'input_name' => 'icon_card_badge', 'custom_name' => 'custom_icon_card_badge', 'val' => $s['icon_card_badge'], 'custom_val' => $s['custom_icon_card_badge'], ), ); ?>
$ico_label ) : ?>
Auto-Resized Standard Icon Attached
OfferCrisp v