| 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 |
* Initialize the module's option group definitions. |
| 45 |
* |
| 46 |
* @return array<int, array<string, mixed>> Array of option group arrays. |
| 47 |
*/ |
| 48 |
protected function init_option_groups() { |
| 49 |
return require MERCHANT_DIR . 'inc/modules/' . self::MODULE_ID . '/admin/options.php'; |
| 50 |
} |
| 51 |
|
| 52 |
/** |
| 53 |
* Constructor. |
| 54 |
* |
| 55 |
*/ |
| 56 |
public function __construct() { |
| 57 |
// Module id. |
| 58 |
$this->module_id = self::MODULE_ID; |
| 59 |
|
| 60 |
// WooCommerce only. |
| 61 |
$this->wc_only = true; |
| 62 |
|
| 63 |
// Parent construct. |
| 64 |
parent::__construct(); |
| 65 |
|
| 66 |
// Module section. |
| 67 |
$this->module_section = 'boost-revenue'; |
| 68 |
|
| 69 |
// Module default settings. |
| 70 |
$this->module_default_settings = array( |
| 71 |
'form_title' => __( 'Email me when this item is back in stock.', 'merchant' ), |
| 72 |
'form_email_label' => __( 'Your Email Address', 'merchant' ), |
| 73 |
'form_button_text' => __( 'Notify Me', 'merchant' ), |
| 74 |
'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.', |
| 75 |
'merchant' ), |
| 76 |
'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.', |
| 77 |
'merchant' ), |
| 78 |
'form_unsubscribe_message' => __( 'You have been successfully unsubscribed from our stock waitlist for this product.', 'merchant' ), |
| 79 |
'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.', |
| 80 |
'merchant' ), |
| 81 |
'form_nonce_field' => wp_nonce_field( 'merchant_wait_list_action', 'merchant_wait_list_action', true, false ), |
| 82 |
); |
| 83 |
|
| 84 |
// Module data. |
| 85 |
$this->module_data = Merchant_Admin_Modules::$modules_data[ self::MODULE_ID ]; |
| 86 |
|
| 87 |
// AI prompt examples. |
| 88 |
$this->ai_examples = array( |
| 89 |
'blurb' => esc_html__( 'See what AI can do for your waitlist, from wording the sign-up form and restock emails to reviewing and pruning the list of subscribers.', 'merchant' ), |
| 90 |
'prompts' => array( |
| 91 |
esc_html__( 'Explore the abilities WPVibe gives you access to, then show me everyone currently on the waitlist for the Midnight Runner Sneakers', 'merchant' ), |
| 92 |
esc_html__( "Check what abilities you have available through WPVibe, then reword the back-in-stock email to open with 'Good news, your {product} is available again'", 'merchant' ), |
| 93 |
esc_html__( 'Look at your available WPVibe abilities, then turn on automatic restock emails so subscribers are notified the moment an item is back in stock', 'merchant' ), |
| 94 |
esc_html__( 'See what abilities WPVibe exposes, then clear out everyone who already unsubscribed from the Midnight Runner Sneakers waitlist', 'merchant' ), |
| 95 |
), |
| 96 |
); |
| 97 |
|
| 98 |
// Module options path. |
| 99 |
$this->module_options_path = self::MODULE_DIR . '/admin/options.php'; |
| 100 |
|
| 101 |
// Is module preview page. |
| 102 |
if ( is_admin() && parent::is_module_settings_page() ) { |
| 103 |
self::$is_module_preview = true; |
| 104 |
|
| 105 |
// Enqueue admin styles. |
| 106 |
add_action( 'admin_enqueue_scripts', array( $this, 'admin_enqueue_css' ) ); |
| 107 |
|
| 108 |
// Admin preview box. |
| 109 |
add_filter( 'merchant_module_preview', array( $this, 'render_admin_preview' ), 10, 2 ); |
| 110 |
} |
| 111 |
|
| 112 |
if ( Merchant_Modules::is_module_active( self::MODULE_ID ) && is_admin() ) { |
| 113 |
// Init translations. |
| 114 |
$this->init_translations(); |
| 115 |
} |
| 116 |
} |
| 117 |
|
| 118 |
/** |
| 119 |
* Get all analytics metrics and allow modules to filter them. |
| 120 |
* |
| 121 |
* @return array List of available metrics. |
| 122 |
*/ |
| 123 |
public function analytics_metrics() { |
| 124 |
$metrics = $this->default_analytics_metrics(); |
| 125 |
$metrics['campaigns'] = false; |
| 126 |
|
| 127 |
/** |
| 128 |
* Hook: merchant_analytics_module_metrics |
| 129 |
* |
| 130 |
* @param array $metrics List of available metrics. |
| 131 |
* @param string $module_id Module ID. |
| 132 |
* |
| 133 |
* @since 2.0 |
| 134 |
*/ |
| 135 |
return apply_filters( 'merchant_analytics_module_metrics', $metrics, $this->module_id, $this ); |
| 136 |
} |
| 137 |
|
| 138 |
/** |
| 139 |
* Init translations. |
| 140 |
* |
| 141 |
* @return void |
| 142 |
*/ |
| 143 |
public function init_translations() { |
| 144 |
$settings = $this->get_module_settings(); |
| 145 |
|
| 146 |
if ( ! empty( $settings['form_title'] ) ) { |
| 147 |
Merchant_Translator::register_string( $settings['form_title'], esc_html__( 'Wait list: Form title', 'merchant' ) ); |
| 148 |
} |
| 149 |
if ( ! empty( $settings['form_email_label'] ) ) { |
| 150 |
Merchant_Translator::register_string( $settings['form_email_label'], esc_html__( 'Wait list: Form email label', 'merchant' ) ); |
| 151 |
} |
| 152 |
if ( ! empty( $settings['form_button_text'] ) ) { |
| 153 |
Merchant_Translator::register_string( $settings['form_button_text'], esc_html__( 'Wait list: Form button text', 'merchant' ) ); |
| 154 |
} |
| 155 |
if ( ! empty( $settings['form_success_message'] ) ) { |
| 156 |
Merchant_Translator::register_string( $settings['form_success_message'], esc_html__( 'Wait list: Form success message', 'merchant' ) ); |
| 157 |
} |
| 158 |
if ( ! empty( $settings['email_new_subscriber'] ) ) { |
| 159 |
Merchant_Translator::register_string( $settings['email_new_subscriber'], esc_html__( 'Wait list: Email new subscriber', 'merchant' ) ); |
| 160 |
} |
| 161 |
if ( ! empty( $settings['email_update'] ) ) { |
| 162 |
Merchant_Translator::register_string( $settings['email_update'], esc_html__( 'Wait list: Email update', 'merchant' ) ); |
| 163 |
} |
| 164 |
} |
| 165 |
|
| 166 |
/** |
| 167 |
* Admin enqueue CSS. |
| 168 |
* |
| 169 |
* @return void |
| 170 |
*/ |
| 171 |
public function admin_enqueue_css() { |
| 172 |
if ( parent::is_module_settings_page() ) { |
| 173 |
wp_enqueue_style( 'merchant-' . self::MODULE_ID, MERCHANT_URI . 'assets/css/modules/' . self::MODULE_ID . '/wait-list.min.css', array(), MERCHANT_VERSION ); |
| 174 |
wp_enqueue_style( 'merchant-admin-' . self::MODULE_ID, MERCHANT_URI . 'assets/css/modules/' . self::MODULE_ID . '/admin/preview.min.css', array(), MERCHANT_VERSION ); |
| 175 |
} |
| 176 |
} |
| 177 |
|
| 178 |
/** |
| 179 |
* Render admin preview |
| 180 |
* |
| 181 |
* @param Merchant_Admin_Preview $preview |
| 182 |
* @param string $module |
| 183 |
* |
| 184 |
* @return Merchant_Admin_Preview |
| 185 |
*/ |
| 186 |
public function render_admin_preview( $preview, $module ) { |
| 187 |
if ( self::MODULE_ID === $module ) { |
| 188 |
ob_start(); |
| 189 |
self::admin_preview_content(); |
| 190 |
$content = ob_get_clean(); |
| 191 |
|
| 192 |
$preview->set_html( $content ); |
| 193 |
|
| 194 |
$preview->set_text( 'form_title', '.merchant-wait-list-title' ); |
| 195 |
$preview->set_text( 'form_button_text', '.merchant-wait-list-submit' ); |
| 196 |
$preview->set_attribute( 'form_email_label', '#merchant-wait-list-email', 'placeholder' ); |
| 197 |
} |
| 198 |
|
| 199 |
return $preview; |
| 200 |
} |
| 201 |
|
| 202 |
/** |
| 203 |
* Admin preview content. |
| 204 |
* |
| 205 |
* @return void |
| 206 |
*/ |
| 207 |
public function admin_preview_content() { |
| 208 |
$settings = $this->get_module_settings(); |
| 209 |
?> |
| 210 |
|
| 211 |
<div class="mrc-preview-single-product-elements"> |
| 212 |
<div class="mrc-preview-left-column"> |
| 213 |
<div class="mrc-preview-product-image-wrapper"> |
| 214 |
<div class="mrc-preview-product-image"></div> |
| 215 |
<div class="mrc-preview-product-image-thumbs"> |
| 216 |
<div class="mrc-preview-product-image-thumb"></div> |
| 217 |
<div class="mrc-preview-product-image-thumb"></div> |
| 218 |
<div class="mrc-preview-product-image-thumb"></div> |
| 219 |
</div> |
| 220 |
</div> |
| 221 |
</div> |
| 222 |
<div class="mrc-preview-right-column"> |
| 223 |
<div class="mrc-preview-text-placeholder"></div> |
| 224 |
<div class="mrc-preview-text-placeholder mrc-mw-70"></div> |
| 225 |
<div class="mrc-preview-text-placeholder mrc-mw-30"></div> |
| 226 |
<div class="preview-merchant-wait-list"> |
| 227 |
<?php |
| 228 |
$preview_html = str_replace( 'required', '', $this->get_html( $settings ) ); |
| 229 |
echo wp_kses( $preview_html, merchant_kses_allowed_tags( array( 'forms', 'nonce' ) ) ); ?> |
| 230 |
</div> |
| 231 |
</div> |
| 232 |
</div> |
| 233 |
|
| 234 |
<?php |
| 235 |
} |
| 236 |
|
| 237 |
/** |
| 238 |
* Get the module HTML. |
| 239 |
* |
| 240 |
* @param array $settings |
| 241 |
* |
| 242 |
* @return string |
| 243 |
*/ |
| 244 |
public function get_html( $settings ) { |
| 245 |
$product_id = isset( $settings[ 'product_id' ] ) ? absint( $settings[ 'product_id' ] ) : 0; |
| 246 |
$html = '<div class="merchant-wait-list-container">'; |
| 247 |
$html .= '<div class="merchant-cover">'; |
| 248 |
$html .= '<div class="merchant-wait-list-loader">'; |
| 249 |
$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>'; |
| 250 |
$html .= '</div>'; |
| 251 |
$html .= '</div>'; |
| 252 |
$html .= '<form id="merchant-wait-list" class="merchant-wait-list" method="post">'; |
| 253 |
$html .= '<p class="merchant-wait-list-title">' . Merchant_Translator::translate( $settings[ 'form_title' ] ) . '</p>'; |
| 254 |
$html .= '<div class="merchant-wait-list-email">'; |
| 255 |
$html .= '<label for="merchant-wait-list-email">' . Merchant_Translator::translate( $settings[ 'form_email_label' ] ) . ' <abbr class="required" title="required">*</abbr></label>'; |
| 256 |
$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="">'; |
| 257 |
$html .= '</div>'; |
| 258 |
$html .= '<button class="merchant-wait-list-submit" type="submit" name="subscribe">' . Merchant_Translator::translate( $settings[ 'form_button_text' ] ) . '</button>'; |
| 259 |
$html .= $settings['form_nonce_field']; |
| 260 |
$html .= '<input type="hidden" name="merchant-wait-list-product-id" id="merchant-wait-list-product-id" value="' . $product_id . '" >'; |
| 261 |
$html .= '</form>'; |
| 262 |
$html .= '</div>'; |
| 263 |
|
| 264 |
return $html; |
| 265 |
} |
| 266 |
} |
| 267 |
|
| 268 |
// Initialize the module. |
| 269 |
add_action( 'init', function () { |
| 270 |
Merchant_Modules::create_module( new Merchant_Wait_List() ); |
| 271 |
} ); |
| 272 |
|