<?php if ( ! defined( 'ABSPATH' ) ) exit; class GT_BOGO_Mobile_Drawer { private $id = 'mobile_drawer'; public function __construct() { if ( is_admin() && ! defined('DOING_AJAX') ) return; if ( ! $this->enabled() ) return; add_action( 'wp_footer', [ $this, 'render' ] ); add_action( 'wp_enqueue_scripts', [ $this, 'enqueue' ] ); } private function enabled() { return (bool) get_option( 'gtbogo_sp_' . $this->id . '_enabled', 0 ) && get_option( 'gtbogo_sp_' . $this->id . '_intensity', 'subtle' ) !== 'off'; } private function intensity() { return get_option( 'gtbogo_sp_' . $this->id . '_intensity', 'subtle' ); } public function enqueue() { wp_add_inline_style( 'woocommerce-general', ' @media(min-width:769px){#gtbogo-mobile-drawer{display:none!important}} #gtbogo-mobile-drawer{position:fixed;bottom:0;left:0;right:0;z-index:9997;font-family:inherit;color:inherit;transform:translateY(100%);transition:transform 0.4s cubic-bezier(0.34,1.2,0.64,1)} #gtbogo-mobile-drawer.gtbogo-drawer-open{transform:translateY(0)} .gtbogo-drawer-handle{width:40px;height:4px;border-radius:2px;background:currentColor;opacity:0.25;margin:10px auto 14px;cursor:grab} .gtbogo-drawer-body{padding:0 20px 20px;display:flex;align-items:center;justify-content:space-between;gap:16px;flex-wrap:wrap} .gtbogo-drawer-deal{flex:1;min-width:0} .gtbogo-drawer-title{font-weight:700;font-size:1em;margin:0 0 4px;font-family:inherit} .gtbogo-drawer-sub{font-size:0.8em;opacity:0.65;margin:0} .gtbogo-drawer-cta{display:inline-block;padding:10px 20px;border:1px solid currentColor;border-radius:4px;font-family:inherit;font-weight:600;font-size:0.85em;text-decoration:none;color:inherit;white-space:nowrap} .gtbogo-drawer-close{position:absolute;top:10px;right:16px;background:none;border:none;font-size:18px;cursor:pointer;color:inherit;opacity:0.5;padding:4px;line-height:1} ' ); wp_add_inline_script( 'jquery', ' (function(){ var shown = sessionStorage.getItem("gtbogo_drawer_shown"); if(shown) return; var drawer = document.getElementById("gtbogo-mobile-drawer"); if(!drawer) return; setTimeout(function(){ drawer.classList.add("gtbogo-drawer-open"); sessionStorage.setItem("gtbogo_drawer_shown","1"); }, 2500); var close = drawer.querySelector(".gtbogo-drawer-close"); var handle = drawer.querySelector(".gtbogo-drawer-handle"); function closeDrawer(){ drawer.classList.remove("gtbogo-drawer-open"); } if(close) close.addEventListener("click", closeDrawer); var startY = 0; drawer.addEventListener("touchstart", function(e){ startY = e.touches[0].clientY; }, {passive:true}); drawer.addEventListener("touchend", function(e){ if(e.changedTouches[0].clientY - startY > 60) closeDrawer(); }, {passive:true}); })(); ' ); } public function render() { $settings = get_option( 'gt_bogo_engine_settings', [] ); if ( empty( $settings['enabled'] ) ) return; $buy = intval( $settings['buy_quantity'] ?? 1 ); $get = intval( $settings['get_quantity'] ?? 1 ); $discount = intval( $settings['discount_percent'] ?? 50 ); ?> <div id="gtbogo-mobile-drawer" role="complementary" aria-label="<?php esc_attr_e( 'Active Deal', 'gt-bogo-engine' ); ?>"> <button class="gtbogo-drawer-close" aria-label="<?php esc_attr_e( 'Close', 'gt-bogo-engine' ); ?>">&times;</button> <div class="gtbogo-drawer-handle" aria-hidden="true"></div> <div class="gtbogo-drawer-body"> <div class="gtbogo-drawer-deal"> <p class="gtbogo-drawer-title"> <?php printf( esc_html__( 'Buy %1$d Get %2$d at %3$d%% off', 'gt-bogo-engine' ), esc_html( $buy ), esc_html( $get ), esc_html( $discount ) ); ?> </p> <p class="gtbogo-drawer-sub"><?php esc_html_e( 'Applied automatically — no code needed', 'gt-bogo-engine' ); ?></p> </div> <a href="<?php echo esc_url( wc_get_page_permalink( 'shop' ) ); ?>" class="gtbogo-drawer-cta"> <?php esc_html_e( 'Shop the Deal', 'gt-bogo-engine' ); ?> </a> </div> </div> <?php } }