PluginProbe
Product Labels, Quick View, Buy Now, Pre-Orders, Frequently Bought Together & More for WooCommerce – Merchant / 2.2.8
Product Labels, Quick View, Buy Now, Pre-Orders, Frequently Bought Together & More for WooCommerce – Merchant v2.2.8
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 2.2.8, at inc/modules/wait-list/class-wait-list.php

252 lines 9.0 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 * Set the module as having analytics.
38 *
39 * @var bool
40 */
41 protected $has_analytics = true;
42
43 /**
44 * Constructor.
45 *
46 */
47 public function __construct() {
48 // Module id.
49 $this->module_id = self::MODULE_ID;
50
51 // WooCommerce only.
52 $this->wc_only = true;
53
54 // Parent construct.
55 parent::__construct();
56
57 // Module section.
58 $this->module_section = 'boost-revenue';
59
60 // Module default settings.
61 $this->module_default_settings = array(
62 'form_title' => __( 'Email me when this item is back in stock.', 'merchant' ),
63 'form_email_label' => __( 'Your Email Address', 'merchant' ),
64 'form_button_text' => __( 'Notify Me', 'merchant' ),
65 'form_success_message' => __( 'You have been successfully added to our stock waitlist. As soon as new stock becomes available, we will notify you via email.',
66 'merchant' ),
67 'email_new_subscriber' => __( 'Hello, thank you for joining the stock notification list for {product}. We will email you when the product is back in stock.',
68 'merchant' ),
69 'form_unsubscribe_message' => __( 'You have been successfully unsubscribed from our stock waitlist for this product.', 'merchant' ),
70 'email_update' => __( 'Hello, thanks for your patience and finally the wait is over! Your {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. Add this {product} directly to your cart.',
71 'merchant' ),
72 'form_nonce_field' => wp_nonce_field( 'merchant_wait_list_action', 'merchant_wait_list_action', true, false ),
73 );
74
75 // Module data.
76 $this->module_data = Merchant_Admin_Modules::$modules_data[ self::MODULE_ID ];
77
78 // Module options path.
79 $this->module_options_path = self::MODULE_DIR . '/admin/options.php';
80
81 // Is module preview page.
82 if ( is_admin() && parent::is_module_settings_page() ) {
83 self::$is_module_preview = true;
84
85 // Enqueue admin styles.
86 add_action( 'admin_enqueue_scripts', array( $this, 'admin_enqueue_css' ) );
87
88 // Admin preview box.
89 add_filter( 'merchant_module_preview', array( $this, 'render_admin_preview' ), 10, 2 );
90 }
91
92 if ( Merchant_Modules::is_module_active( self::MODULE_ID ) && is_admin() ) {
93 // Init translations.
94 $this->init_translations();
95 }
96 }
97
98 /**
99 * Get all analytics metrics and allow modules to filter them.
100 *
101 * @return array List of available metrics.
102 */
103 public function analytics_metrics() {
104 $metrics = $this->default_analytics_metrics();
105 $metrics['campaigns'] = false;
106
107 /**
108 * Hook: merchant_analytics_module_metrics
109 *
110 * @param array $metrics List of available metrics.
111 * @param string $module_id Module ID.
112 *
113 * @since 2.0
114 */
115 return apply_filters( 'merchant_analytics_module_metrics', $metrics, $this->module_id, $this );
116 }
117
118 /**
119 * Init translations.
120 *
121 * @return void
122 */
123 public function init_translations() {
124 $settings = $this->get_module_settings();
125
126 if ( ! empty( $settings['form_title'] ) ) {
127 Merchant_Translator::register_string( $settings['form_title'], esc_html__( 'Wait list: Form title', 'merchant' ) );
128 }
129 if ( ! empty( $settings['form_email_label'] ) ) {
130 Merchant_Translator::register_string( $settings['form_email_label'], esc_html__( 'Wait list: Form email label', 'merchant' ) );
131 }
132 if ( ! empty( $settings['form_button_text'] ) ) {
133 Merchant_Translator::register_string( $settings['form_button_text'], esc_html__( 'Wait list: Form button text', 'merchant' ) );
134 }
135 if ( ! empty( $settings['form_success_message'] ) ) {
136 Merchant_Translator::register_string( $settings['form_success_message'], esc_html__( 'Wait list: Form success message', 'merchant' ) );
137 }
138 if ( ! empty( $settings['email_new_subscriber'] ) ) {
139 Merchant_Translator::register_string( $settings['email_new_subscriber'], esc_html__( 'Wait list: Email new subscriber', 'merchant' ) );
140 }
141 if ( ! empty( $settings['email_update'] ) ) {
142 Merchant_Translator::register_string( $settings['email_update'], esc_html__( 'Wait list: Email update', 'merchant' ) );
143 }
144 }
145
146 /**
147 * Admin enqueue CSS.
148 *
149 * @return void
150 */
151 public function admin_enqueue_css() {
152 if ( parent::is_module_settings_page() ) {
153 wp_enqueue_style( 'merchant-' . self::MODULE_ID, MERCHANT_URI . 'assets/css/modules/' . self::MODULE_ID . '/wait-list.min.css', array(), MERCHANT_VERSION );
154 wp_enqueue_style( 'merchant-admin-' . self::MODULE_ID, MERCHANT_URI . 'assets/css/modules/' . self::MODULE_ID . '/admin/preview.min.css', array(), MERCHANT_VERSION );
155 }
156 }
157
158 /**
159 * Render admin preview
160 *
161 * @param Merchant_Admin_Preview $preview
162 * @param string $module
163 *
164 * @return Merchant_Admin_Preview
165 */
166 public function render_admin_preview( $preview, $module ) {
167 if ( self::MODULE_ID === $module ) {
168 ob_start();
169 self::admin_preview_content();
170 $content = ob_get_clean();
171
172 $preview->set_html( $content );
173
174 $preview->set_text( 'form_title', '.merchant-wait-list-title' );
175 $preview->set_text( 'form_button_text', '.merchant-wait-list-submit' );
176 $preview->set_attribute( 'form_email_label', '#merchant-wait-list-email', 'placeholder' );
177 }
178
179 return $preview;
180 }
181
182 /**
183 * Admin preview content.
184 *
185 * @return void
186 */
187 public function admin_preview_content() {
188 $settings = $this->get_module_settings();
189 ?>
190
191 <div class="mrc-preview-single-product-elements">
192 <div class="mrc-preview-left-column">
193 <div class="mrc-preview-product-image-wrapper">
194 <div class="mrc-preview-product-image"></div>
195 <div class="mrc-preview-product-image-thumbs">
196 <div class="mrc-preview-product-image-thumb"></div>
197 <div class="mrc-preview-product-image-thumb"></div>
198 <div class="mrc-preview-product-image-thumb"></div>
199 </div>
200 </div>
201 </div>
202 <div class="mrc-preview-right-column">
203 <div class="mrc-preview-text-placeholder"></div>
204 <div class="mrc-preview-text-placeholder mrc-mw-70"></div>
205 <div class="mrc-preview-text-placeholder mrc-mw-30"></div>
206 <div class="preview-merchant-wait-list">
207 <?php
208 $preview_html = str_replace( 'required', '', $this->get_html( $settings ) );
209 echo wp_kses( $preview_html, merchant_kses_allowed_tags( array( 'forms', 'nonce' ) ) ); ?>
210 </div>
211 </div>
212 </div>
213
214 <?php
215 }
216
217 /**
218 * Get the module HTML.
219 *
220 * @param array $settings
221 *
222 * @return string
223 */
224 public function get_html( $settings ) {
225 $product_id = isset( $settings[ 'product_id' ] ) ? absint( $settings[ 'product_id' ] ) : 0;
226 $html = '<div class="merchant-wait-list-container">';
227 $html .= '<div class="merchant-cover">';
228 $html .= '<div class="merchant-wait-list-loader">';
229 $html .= '<svg fill="none" height="24" viewBox="0 0 24 24" width="24" xmlns="http://www.w3.org/2000/svg"><path clip-rule="evenodd" d="M12 19C15.866 19 19 15.866 19 12C19 8.13401 15.866 5 12 5C8.13401 5 5 8.13401 5 12C5 15.866 8.13401 19 12 19ZM12 22C17.5228 22 22 17.5228 22 12C22 6.47715 17.5228 2 12 2C6.47715 2 2 6.47715 2 12C2 17.5228 6.47715 22 12 22Z" fill="currentColor" fill-rule="evenodd" opacity="0.2"/><path d="M2 12C2 6.47715 6.47715 2 12 2V5C8.13401 5 5 8.13401 5 12H2Z" fill="currentColor"/></svg>';
230 $html .= '</div>';
231 $html .= '</div>';
232 $html .= '<form id="merchant-wait-list" class="merchant-wait-list" method="post">';
233 $html .= '<p class="merchant-wait-list-title">' . Merchant_Translator::translate( $settings[ 'form_title' ] ) . '</p>';
234 $html .= '<div class="merchant-wait-list-email">';
235 $html .= '<label for="merchant-wait-list-email">' . Merchant_Translator::translate( $settings[ 'form_email_label' ] ) . ' <abbr class="required" title="required">*</abbr></label>';
236 $html .= '<input type="email" name="merchant-wait-list-email" id="merchant-wait-list-email" value="" autocomplete="email" placeholder="' . Merchant_Translator::translate( $settings[ 'form_email_label' ] ) . '" required="">';
237 $html .= '</div>';
238 $html .= '<button class="merchant-wait-list-submit" type="submit" name="subscribe">' . Merchant_Translator::translate( $settings[ 'form_button_text' ] ) . '</button>';
239 $html .= $settings['form_nonce_field'];
240 $html .= '<input type="hidden" name="merchant-wait-list-product-id" id="merchant-wait-list-product-id" value="' . $product_id . '" >';
241 $html .= '</form>';
242 $html .= '</div>';
243
244 return $html;
245 }
246 }
247
248 // Initialize the module.
249 add_action( 'init', function () {
250 Merchant_Modules::create_module( new Merchant_Wait_List() );
251 } );
252