module_id = self::MODULE_ID; // WooCommerce only. $this->wc_only = true; // Parent construct. parent::__construct(); // Module section. $this->module_section = 'convert-more'; // Module default settings. $this->module_default_settings = array( 'discount_products_only' => true, 'sale_ending_text' => esc_html__( 'Sale ends in', 'merchant' ), 'end_date' => 'evergreen', 'cool_off_period' => 15, 'min_expiration_deadline' => 2, 'max_expiration_deadline' => 26, 'sale_ending_alignment' => 'left', ); // Mount preview url. $preview_url = site_url( '/' ); if ( function_exists( 'wc_get_products' ) ) { $products = wc_get_products( array( 'limit' => 1 ) ); if ( ! empty( $products ) && ! empty( $products[0] ) ) { $preview_url = get_permalink( $products[0]->get_id() ); } } // Module data. $this->module_data = Merchant_Admin_Modules::$modules_data[ self::MODULE_ID ]; $this->module_data['preview_url'] = $preview_url; // Module options path. $this->module_options_path = MERCHANT_DIR . 'inc/modules/' . self::MODULE_ID . '/admin/options.php'; // Is module preview page. if ( is_admin() && parent::is_module_settings_page() ) { self::$is_module_preview = true; // Enqueue admin styles. add_action( 'admin_enqueue_scripts', array( $this, 'admin_enqueue_css' ) ); // Enqueue admin scripts. add_action( 'admin_enqueue_scripts', array( $this, 'admin_enqueue_scripts' ) ); // Localize Script. add_filter( 'merchant_admin_localize_script', array( $this, 'localize_script' ) ); // Admin preview box. add_filter( 'merchant_module_preview', array( $this, 'render_admin_preview' ), 10, 2 ); // Custom CSS. // The custom CSS should be added here as well due to ensure preview box works properly. add_filter( 'merchant_custom_css', array( $this, 'admin_custom_css' ) ); } if ( Merchant_Modules::is_module_active( self::MODULE_ID ) && is_admin() ) { // Init translations. $this->init_translations(); } } /** * Init translations. * * @return void */ public function init_translations() { $settings = $this->get_module_settings(); if ( ! empty( $settings['sale_ending_text'] ) ) { Merchant_Translator::register_string( $settings['sale_ending_text'], esc_html__( 'Countdown Timer: Sale ending message', 'merchant' ) ); } } /** * Admin enqueue CSS. * * @return void */ public function admin_enqueue_css() { if ( $this->is_module_settings_page() ) { wp_enqueue_style( 'merchant-' . self::MODULE_ID, MERCHANT_URI . 'assets/css/modules/' . self::MODULE_ID . '/countdown-timer.min.css', array(), MERCHANT_VERSION ); wp_enqueue_style( 'merchant-admin-' . self::MODULE_ID, MERCHANT_URI . 'assets/css/modules/' . self::MODULE_ID . '/admin/preview.min.css', array(), MERCHANT_VERSION ); } } /** * Admin Enqueue scripts. * * @return void */ public function admin_enqueue_scripts() { wp_enqueue_script( 'merchant-' . self::MODULE_ID, MERCHANT_URI . 'assets/js/modules/' . self::MODULE_ID . '/countdown-timer.min.js', array(), MERCHANT_VERSION, true ); wp_enqueue_script( 'merchant-admin-' . self::MODULE_ID, MERCHANT_URI . 'assets/js/modules/' . self::MODULE_ID . '/admin/preview.min.js', array(), MERCHANT_VERSION, true ); } /** * Localize Script. */ public function localize_script( $data ) { $data['is_admin'] = is_admin(); return $data; } /** * Render admin preview * * @param Merchant_Admin_Preview $preview * @param string $module * * @return Merchant_Admin_Preview */ public function render_admin_preview( $preview, $module ) { if ( self::MODULE_ID === $module ) { ob_start(); self::admin_preview_content(); $content = ob_get_clean(); // HTML. $preview->set_html( $content ); // Font size $preview->set_css( 'digits_font_size', '.merchant-countdown-timer-countdown', '--merchant-digits-font-size', 'px' ); $preview->set_css( 'labels_font_size', '.merchant-countdown-timer-countdown', '--merchant-labels-font-size', 'px' ); // Sale Ending Color $preview->set_css( 'sale_ending_color', '.merchant-countdown-timer-text', '--merchant-sale-ending-color' ); // Digits Color $preview->set_css( 'digits_color', '.merchant-countdown-timer-countdown', '--merchant-digits-color' ); // Digits Background Color $preview->set_css( 'digits_background', '.merchant-countdown-timer-countdown', '--merchant-digits-background' ); // Progress Color $preview->set_css( 'progress_color', '.merchant-countdown-timer-countdown', '--merchant-progress-color' ); // Labels Color $preview->set_css( 'labels_color', '.merchant-countdown-timer-countdown', '--merchant-labels-color' ); // Border Color $preview->set_css( 'digits_border', '.merchant-countdown-timer-countdown', '--merchant-digits-border' ); // Digits width & height $preview->set_css( 'digits_width', '.merchant-countdown-timer-countdown', '--merchant-digits-width', 'px' ); $preview->set_css( 'digits_height', '.merchant-countdown-timer-countdown', '--merchant-digits-height', 'px' ); // Icon Color. $preview->set_css( 'icon_color', '.merchant-countdown-timer svg', '--merchant-icon-color' ); // Sale Ending Text. $preview->set_text( 'sale_ending_text', '.merchant-countdown-timer-text' ); } return $preview; } /** * Admin preview content. * * @return void */ public function admin_preview_content() { $settings = $this->get_module_settings(); ?>