PluginProbe
Product Labels, Quick View, Buy Now, Pre-Orders, Frequently Bought Together & More for WooCommerce – Merchant / 1.6
Product Labels, Quick View, Buy Now, Pre-Orders, Frequently Bought Together & More for WooCommerce – Merchant v1.6
2.3.2 2.3.1 2.3.0 2.2.8 2.2.7 trunk 1.10.0 1.10.1 1.10.2 1.10.3 1.10.4 1.10.5 1.11.0 1.11.1 1.11.2 1.6 1.7 1.8 1.8.1 1.8.2 1.8.3 1.9.0 1.9.1 1.9.10 1.9.11 All 60 releases
merchant / inc / modules / wait-list / class-wait-list.php

class-wait-list.php in Product Labels, Quick View, Buy Now, Pre-Orders, Frequently Bought Together & More for WooCommerce – Merchant 1.6, at inc/modules/wait-list/class-wait-list.php

192 lines 6.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 /**
4 * Wait list
5 *
6 * @package Merchant
7 */
8
9 if ( ! defined( 'ABSPATH' ) ) {
10 exit; // Exit if accessed directly
11 }
12
13 /**
14 * Wait list class.
15 *
16 */
17 class Merchant_Wait_List extends Merchant_Add_Module {
18
19 /**
20 * Module ID.
21 *
22 */
23 const MODULE_ID = 'wait-list';
24
25 /**
26 * Module path.
27 */
28 const MODULE_DIR = MERCHANT_DIR . 'inc/modules/' . self::MODULE_ID;
29
30 /**
31 * Is module preview.
32 *
33 */
34 public static $is_module_preview = false;
35
36 /**
37 * Constructor.
38 *
39 */
40 public function __construct() {
41 // Module id.
42 $this->module_id = self::MODULE_ID;
43
44 // WooCommerce only.
45 $this->wc_only = true;
46
47 // Parent construct.
48 parent::__construct();
49
50 // Module section.
51 $this->module_section = 'convert-more';
52
53 // Module default settings.
54 $this->module_default_settings = array(
55 'form_title' => __( 'New stock on its way! Email when stock available', 'merchant' ),
56 'form_email_label' => __( 'Your Email Address', 'merchant' ),
57 'form_button_text' => __( 'Notify Me', 'merchant' ),
58 'form_success_message' => __( 'You have been successfully added to our wait list. As soon as new stock become available, we will notify you via email.', 'merchant' ),
59 'email_new_subscriber' => __( 'Hello subscriber, Thank you for subscribing to {product}. We will email you once product back in stock.', 'merchant' ),
60 'email_update' => __( 'Hello Subscriber, Thanks for your patience and finally the wait is over! Your Subscribed Product {product} is now back in stock! We only have a limited amount of stock, and this email is not a guarantee you\'ll get one, so hurry to be one of the lucky shoppers who do. Add this product {product} directly to your cart.',
61 'merchant' ),
62 'form_nonce_field' => wp_nonce_field( 'merchant_wait_list_action', 'merchant_wait_list_action', true, false )
63 );
64
65 // Mount preview url.
66 $preview_url = site_url( '/' );
67
68 if ( function_exists( 'wc_get_products' ) ) {
69 $products = wc_get_products( array( 'limit' => 1 ) );
70
71 if ( ! empty( $products ) && ! empty( $products[0] ) ) {
72 $preview_url = get_permalink( $products[0]->get_id() );
73 }
74 }
75
76 // Module data.
77 $this->module_data = Merchant_Admin_Modules::$modules_data[ self::MODULE_ID ];
78 $this->module_data['preview_url'] = $preview_url;
79
80 // Module options path.
81 $this->module_options_path = self::MODULE_DIR . '/admin/options.php';
82
83 // Is module preview page.
84 if ( is_admin() && parent::is_module_settings_page() ) {
85 self::$is_module_preview = true;
86
87 // Enqueue admin styles.
88 add_action( 'admin_enqueue_scripts', array( $this, 'admin_enqueue_css' ) );
89
90 // Admin preview box.
91 add_filter( 'merchant_module_preview', array( $this, 'render_admin_preview' ), 10, 2 );
92 }
93 }
94
95 /**
96 * Admin enqueue CSS.
97 *
98 * @return void
99 */
100 public function admin_enqueue_css() {
101 if ( parent::is_module_settings_page() ) {
102 wp_enqueue_style( 'merchant-' . self::MODULE_ID, MERCHANT_URI . 'assets/css/modules/' . self::MODULE_ID . '/wait-list.min.css', [], MERCHANT_VERSION );
103 wp_enqueue_style( 'merchant-admin-' . self::MODULE_ID, MERCHANT_URI . 'assets/css/modules/' . self::MODULE_ID . '/admin/preview.min.css', array(), MERCHANT_VERSION );
104 }
105 }
106
107 /**
108 * Render admin preview
109 *
110 * @param Merchant_Admin_Preview $preview
111 * @param string $module
112 *
113 * @return Merchant_Admin_Preview
114 */
115 public function render_admin_preview( $preview, $module ) {
116 if ( self::MODULE_ID === $module ) {
117 ob_start();
118 self::admin_preview_content();
119 $content = ob_get_clean();
120
121 $preview->set_html( $content );
122
123 $preview->set_text( 'form_title', '.merchant-wait-list-title' );
124 $preview->set_text( 'form_button_text', '.merchant-wait-list-submit' );
125 $preview->set_attribute( 'form_email_label', '#merchant-wait-list-email', 'placeholder' );
126 }
127
128 return $preview;
129 }
130
131 /**
132 * Admin preview content.
133 *
134 * @return void
135 */
136 public function admin_preview_content() {
137 $settings = $this->get_module_settings();
138 ?>
139
140 <div class="mrc-preview-single-product-elements">
141 <div class="mrc-preview-left-column">
142 <div class="mrc-preview-product-image-wrapper">
143 <div class="mrc-preview-product-image"></div>
144 <div class="mrc-preview-product-image-thumbs">
145 <div class="mrc-preview-product-image-thumb"></div>
146 <div class="mrc-preview-product-image-thumb"></div>
147 <div class="mrc-preview-product-image-thumb"></div>
148 </div>
149 </div>
150 </div>
151 <div class="mrc-preview-right-column">
152 <div class="mrc-preview-text-placeholder"></div>
153 <div class="mrc-preview-text-placeholder mrc-mw-70"></div>
154 <div class="mrc-preview-text-placeholder mrc-mw-30"></div>
155 <div class="preview-merchant-wait-list">
156 <?php
157 $preview_html = str_replace( 'required', '', $this->get_html( $settings ) );
158 echo wp_kses( $preview_html, merchant_kses_allowed_tags( array( 'forms', 'nonce' ) ) ); ?>
159 </div>
160 </div>
161 </div>
162
163 <?php
164 }
165
166 /**
167 * Get the module HTML.
168 *
169 * @param array $settings
170 *
171 * @return string
172 */
173 public function get_html( $settings ) {
174 $html = '<form id="merchant-wait-list" class="merchant-wait-list" method="post">';
175 $html .= '<p class="merchant-wait-list-title">' . $settings['form_title'] . '</p>';
176 $html .= '<div class="merchant-wait-list-email">';
177 $html .= '<label for="merchant-wait-list-email">' . $settings['form_email_label'] . ' <abbr class="required" title="required">*</abbr></label>';
178 $html .= '<input type="email" name="merchant-wait-list-email" id="merchant-wait-list-email" value="" autocomplete="email" placeholder="' . $settings['form_email_label'] . '" required="">';
179 $html .= '</div>';
180 $html .= '<button class="merchant-wait-list-submit" type="submit" name="subscribe">' . $settings['form_button_text'] . '</button>';
181 $html .= $settings['form_nonce_field'];
182 $html .= '</form>';
183
184 return $html;
185 }
186 }
187
188 // Initialize the module.
189 add_action( 'init', function () {
190 Merchant_Modules::create_module( new Merchant_Wait_List() );
191 } );
192