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' ) ); // 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' ) ); } } /** * 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', [], 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 ); } /** * 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 ); // 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' ); // 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(); ?>
get_module_custom_css(); return $css; } } // Initialize the module. add_action( 'init', function () { Merchant_Modules::create_module( new Merchant_Countdown_Timer() ); } );