| 1 |
<?php |
| 2 |
|
| 3 |
/** |
| 4 |
* Wishlist. |
| 5 |
* |
| 6 |
* @package Merchant |
| 7 |
*/ |
| 8 |
|
| 9 |
if ( ! defined( 'ABSPATH' ) ) { |
| 10 |
exit; // Exit if accessed directly |
| 11 |
} |
| 12 |
|
| 13 |
/** |
| 14 |
* Wishlist class. |
| 15 |
* |
| 16 |
*/ |
| 17 |
class Merchant_Wishlist extends Merchant_Add_Module { |
| 18 |
|
| 19 |
/** |
| 20 |
* Module ID. |
| 21 |
* |
| 22 |
*/ |
| 23 |
const MODULE_ID = 'wishlist'; |
| 24 |
|
| 25 |
/** |
| 26 |
* Is module preview. |
| 27 |
* |
| 28 |
*/ |
| 29 |
public static $is_module_preview = false; |
| 30 |
|
| 31 |
/** |
| 32 |
* Module settings. |
| 33 |
* |
| 34 |
*/ |
| 35 |
public static $module_settings = array(); |
| 36 |
|
| 37 |
/** |
| 38 |
* Initialize the module's option group definitions. |
| 39 |
* |
| 40 |
* @return array<int, array<string, mixed>> Array of option group arrays. |
| 41 |
*/ |
| 42 |
protected function init_option_groups() { |
| 43 |
return require MERCHANT_DIR . 'inc/modules/' . self::MODULE_ID . '/admin/options.php'; |
| 44 |
} |
| 45 |
|
| 46 |
/** |
| 47 |
* Constructor. |
| 48 |
* |
| 49 |
*/ |
| 50 |
public function __construct() { |
| 51 |
|
| 52 |
// Module id. |
| 53 |
$this->module_id = self::MODULE_ID; |
| 54 |
|
| 55 |
// WooCommerce only. |
| 56 |
$this->wc_only = true; |
| 57 |
|
| 58 |
// Parent construct. |
| 59 |
parent::__construct(); |
| 60 |
|
| 61 |
// Module section. |
| 62 |
$this->module_section = 'improve-experience'; |
| 63 |
|
| 64 |
// Module default settings. |
| 65 |
$this->module_default_settings = array( |
| 66 |
'display_on_shop_archive' => 1, |
| 67 |
'display_on_single_product' => 1, |
| 68 |
'display_on_cart_page' => false, |
| 69 |
'posts_per_page' => 6, |
| 70 |
'cart_page_title' => esc_html__( 'Your wishlist items', 'merchant' ), |
| 71 |
'cart_page_title_tag' => 'h2', |
| 72 |
'button_icon' => 'heart1', |
| 73 |
'button_position_top' => 8, |
| 74 |
'button_position_left' => 85, |
| 75 |
'tooltip' => 1, |
| 76 |
'tooltip_text' => esc_html__( 'Add To Wishlist', 'merchant' ), |
| 77 |
'tooltip_text_after' => esc_html__( 'Added To Wishlist', 'merchant' ), |
| 78 |
'tooltip_border_radius' => 4, |
| 79 |
'hide_page_title' => 0, |
| 80 |
'enable_sharing' => 1, |
| 81 |
'sharing_links' => array( |
| 82 |
array( |
| 83 |
'layout' => 'social', |
| 84 |
'social_network' => 'facebook', |
| 85 |
), |
| 86 |
array( |
| 87 |
'layout' => 'social', |
| 88 |
'social_network' => 'twitter', |
| 89 |
), |
| 90 |
array( |
| 91 |
'layout' => 'social', |
| 92 |
'social_network' => 'linkedin', |
| 93 |
), |
| 94 |
), |
| 95 |
'display_copy_to_clipboard' => 1, |
| 96 |
); |
| 97 |
|
| 98 |
// Module data. |
| 99 |
$this->module_data = Merchant_Admin_Modules::$modules_data[ self::MODULE_ID ]; |
| 100 |
|
| 101 |
// AI prompt examples. |
| 102 |
$this->ai_examples = array( |
| 103 |
'blurb' => esc_html__( 'See what AI can do for your wishlist, from choosing where the button appears to setting up social sharing.', 'merchant' ), |
| 104 |
'prompts' => array( |
| 105 |
esc_html__( 'Explore the abilities WPVibe gives you access to, then display the wishlist products on the cart page and show 8 items in the grid', 'merchant' ), |
| 106 |
esc_html__( "Check what abilities you have available through WPVibe, then switch the wishlist button to the second heart icon and change the tooltip text to 'Save for later'", 'merchant' ), |
| 107 |
esc_html__( 'Look at your available WPVibe abilities, then turn on wishlist sharing and add Facebook, WhatsApp, and Pinterest links', 'merchant' ), |
| 108 |
esc_html__( 'See what abilities WPVibe exposes, then show the wishlist button only on products in the Accessories category', 'merchant' ), |
| 109 |
), |
| 110 |
); |
| 111 |
|
| 112 |
// Module options path. |
| 113 |
$this->module_options_path = MERCHANT_DIR . 'inc/modules/' . self::MODULE_ID . '/admin/options.php'; |
| 114 |
|
| 115 |
// Store module handled (with defaults) module settings into a static variable. |
| 116 |
self::$module_settings = $this->get_module_settings(); |
| 117 |
|
| 118 |
// Is module preview page. |
| 119 |
if ( is_admin() && parent::is_module_settings_page() ) { |
| 120 |
self::$is_module_preview = true; |
| 121 |
|
| 122 |
// Enqueue admin styles. |
| 123 |
add_action( 'admin_enqueue_scripts', array( $this, 'admin_enqueue_css' ) ); |
| 124 |
|
| 125 |
// Admin preview box. |
| 126 |
add_filter( 'merchant_module_preview', array( $this, 'render_admin_preview' ), 10, 2 ); |
| 127 |
|
| 128 |
// Custom CSS. |
| 129 |
// The custom CSS should be added here as well due to ensure preview box works properly. |
| 130 |
add_filter( 'merchant_custom_css', array( $this, 'admin_custom_css' ) ); |
| 131 |
|
| 132 |
} |
| 133 |
} |
| 134 |
/** |
| 135 |
* Admin enqueue CSS. |
| 136 |
* |
| 137 |
* @return void |
| 138 |
*/ |
| 139 |
public function admin_enqueue_css() { |
| 140 |
if ( parent::is_module_settings_page() ) { |
| 141 |
wp_enqueue_style( 'merchant-' . self::MODULE_ID, MERCHANT_URI . 'assets/css/modules/' . self::MODULE_ID . '/wishlist-button.min.css', array(), MERCHANT_VERSION ); |
| 142 |
wp_enqueue_style( 'merchant-admin-' . self::MODULE_ID, MERCHANT_URI . 'assets/css/modules/' . self::MODULE_ID . '/admin/preview.min.css', array(), MERCHANT_VERSION ); |
| 143 |
} |
| 144 |
} |
| 145 |
|
| 146 |
/** |
| 147 |
* Render admin preview |
| 148 |
* |
| 149 |
* @param Merchant_Admin_Preview $preview |
| 150 |
* @param string $module |
| 151 |
* |
| 152 |
* @return Merchant_Admin_Preview |
| 153 |
*/ |
| 154 |
public function render_admin_preview( $preview, $module ) { |
| 155 |
if ( self::MODULE_ID === $module ) { |
| 156 |
ob_start(); |
| 157 |
$this->admin_preview_content(); |
| 158 |
$content = ob_get_clean(); |
| 159 |
|
| 160 |
// HTML. |
| 161 |
$preview->set_html( $content ); |
| 162 |
|
| 163 |
// Select Icon. |
| 164 |
$preview->set_svg_icon( 'button_icon', '.merchant-wishlist-button' ); |
| 165 |
|
| 166 |
// Dislplay Tooltip. |
| 167 |
$preview->set_class( 'tooltip', '.merchant-wishlist-button', array(), 'merchant-wishlist-button-tooltip' ); |
| 168 |
|
| 169 |
// Tooltip Text. |
| 170 |
$preview->set_attribute( 'tooltip_text', '.merchant-wishlist-button', 'data-merchant-wishlist-tooltip' ); |
| 171 |
|
| 172 |
} |
| 173 |
|
| 174 |
return $preview; |
| 175 |
} |
| 176 |
|
| 177 |
/** |
| 178 |
* Admin preview content. |
| 179 |
* |
| 180 |
* @return void |
| 181 |
*/ |
| 182 |
public function admin_preview_content() { |
| 183 |
$settings = self::$module_settings; |
| 184 |
|
| 185 |
?> |
| 186 |
|
| 187 |
<div class="merchant-wishlist-product-preview"> |
| 188 |
<div class="image-wrapper"> |
| 189 |
<a href="#" class="merchant-wishlist-button<?php echo ( $settings[ 'tooltip' ] ) ? ' merchant-wishlist-button-tooltip' : ''; ?>" data-type="add" data-wishlist-link="#" data-merchant-wishlist-tooltip="<?php echo esc_attr( $settings[ 'tooltip_text' ] ); ?>"> |
| 190 |
<?php echo wp_kses( Merchant_SVG_Icons::get_svg_icon( $settings[ 'button_icon' ] ), merchant_kses_allowed_tags( array(), false ) ); ?> |
| 191 |
</a> |
| 192 |
</div> |
| 193 |
<h3><?php echo esc_html__( 'Product Title', 'merchant' ); ?></h3> |
| 194 |
<p><?php echo esc_html__( 'Product description normally goes here.', 'merchant' ); ?></p> |
| 195 |
</div> |
| 196 |
|
| 197 |
<?php |
| 198 |
} |
| 199 |
|
| 200 |
/** |
| 201 |
* Custom CSS. |
| 202 |
* |
| 203 |
* @return string $css The custom CSS. |
| 204 |
*/ |
| 205 |
public function get_module_custom_css() { |
| 206 |
$css = ''; |
| 207 |
|
| 208 |
/** |
| 209 |
* Add To Wishlist Button Settings |
| 210 |
* |
| 211 |
*/ |
| 212 |
|
| 213 |
// Button position top. |
| 214 |
$css .= Merchant_Custom_CSS::get_variable_css( 'wishlist', 'button_position_top', 20, '.merchant-wishlist-button', '--mrc-wl-button-position-top', 'px' ); |
| 215 |
|
| 216 |
// Button position left. |
| 217 |
$css .= Merchant_Custom_CSS::get_variable_css( 'wishlist', 'button_position_left', 20, '.merchant-wishlist-button', '--mrc-wl-button-position-left', 'px' ); |
| 218 |
|
| 219 |
// Icon stroke color. |
| 220 |
$css .= Merchant_Custom_CSS::get_variable_css( 'wishlist', 'icon_stroke_color', '#212121', '.merchant-wishlist-button', '--mrc-wl-button-icon-stroke-color' ); |
| 221 |
$css .= Merchant_Custom_CSS::get_variable_css( 'wishlist', 'icon_stroke_color_hover', '#212121', '.merchant-wishlist-button', '--mrc-wl-button-icon-stroke-color-hover' ); |
| 222 |
|
| 223 |
// Icon fill color. |
| 224 |
$css .= Merchant_Custom_CSS::get_variable_css( 'wishlist', 'icon_fill_color', 'transparent', '.merchant-wishlist-button', '--mrc-wl-button-icon-fill-color' ); |
| 225 |
$css .= Merchant_Custom_CSS::get_variable_css( 'wishlist', 'icon_fill_color_hover', '#f04c4c', '.merchant-wishlist-button', '--mrc-wl-button-icon-fill-color-hover' ); |
| 226 |
|
| 227 |
// Tooltip text color. |
| 228 |
$css .= Merchant_Custom_CSS::get_variable_css( 'wishlist', 'tooltip_text_color', '#FFF', '.merchant-wishlist-button', '--mrc-wl-button-tooltip-text-color' ); |
| 229 |
|
| 230 |
// Tooltip background color. |
| 231 |
$css .= Merchant_Custom_CSS::get_variable_css( 'wishlist', 'tooltip_background_color', '#212121', '.merchant-wishlist-button', '--mrc-wl-button-tooltip-background-color' ); |
| 232 |
|
| 233 |
// Tooltip border radius. |
| 234 |
$css .= Merchant_Custom_CSS::get_variable_css( 'wishlist', 'tooltip_border_radius', 4, '.merchant-wishlist-button', '--mrc-wl-button-tooltip-border-radius', 'px' ); |
| 235 |
|
| 236 |
/** |
| 237 |
* Wishlist Page Template Settings |
| 238 |
* |
| 239 |
*/ |
| 240 |
|
| 241 |
// Table heading background color. |
| 242 |
$css .= Merchant_Custom_CSS::get_variable_css( 'wishlist', 'table_heading_background_color', '#f8f8f8', '.is-merchant-wishlist-page', '--mrc-wl-table-heading-background-color' ); |
| 243 |
|
| 244 |
// Table body background color. |
| 245 |
$css .= Merchant_Custom_CSS::get_variable_css( 'wishlist', 'table_body_background_color', '#fdfdfd', '.is-merchant-wishlist-page', '--mrc-wl-table-body-background-color' ); |
| 246 |
|
| 247 |
// Table text color. |
| 248 |
$css .= Merchant_Custom_CSS::get_variable_css( 'wishlist', 'table_text_color', '#777', '.is-merchant-wishlist-page', '--mrc-wl-table-text-color' ); |
| 249 |
|
| 250 |
// Table links color. |
| 251 |
$css .= Merchant_Custom_CSS::get_variable_css( 'wishlist', 'table_links_color', '#212121', '.is-merchant-wishlist-page', '--mrc-wl-table-links-color' ); |
| 252 |
|
| 253 |
// Table links color (hover). |
| 254 |
$css .= Merchant_Custom_CSS::get_variable_css( 'wishlist', 'table_links_color_hover', '#757575', '.is-merchant-wishlist-page', '--mrc-wl-table-links-color-hover' ); |
| 255 |
|
| 256 |
// Buttons color. |
| 257 |
$css .= Merchant_Custom_CSS::get_variable_css( 'wishlist', 'buttons_color', '#FFF', '.is-merchant-wishlist-page', '--mrc-wl-buttons-color' ); |
| 258 |
|
| 259 |
// Buttons color (hover). |
| 260 |
$css .= Merchant_Custom_CSS::get_variable_css( 'wishlist', 'buttons_color_hover', '#FFF', '.is-merchant-wishlist-page', '--mrc-wl-buttons-color-hover' ); |
| 261 |
|
| 262 |
// Buttons background color. |
| 263 |
$css .= Merchant_Custom_CSS::get_variable_css( 'wishlist', 'buttons_background_color', '#212121', '.is-merchant-wishlist-page', '--mrc-wl-buttons-bg-color' ); |
| 264 |
|
| 265 |
// Buttons color (hover). |
| 266 |
$css .= Merchant_Custom_CSS::get_variable_css( 'wishlist', 'buttons_background_color_hover', '#757575', '.is-merchant-wishlist-page', '--mrc-wl-buttons-bg-color-hover' ); |
| 267 |
|
| 268 |
return $css; |
| 269 |
} |
| 270 |
|
| 271 |
/** |
| 272 |
* Admin custom CSS. |
| 273 |
* |
| 274 |
* @param string $css The custom CSS. |
| 275 |
* @return string $css The custom CSS. |
| 276 |
*/ |
| 277 |
public function admin_custom_css( $css ) { |
| 278 |
$css .= $this->get_module_custom_css(); |
| 279 |
|
| 280 |
return $css; |
| 281 |
} |
| 282 |
} |
| 283 |
|
| 284 |
// Initialize the module. |
| 285 |
add_action( 'init', function() { |
| 286 |
Merchant_Modules::create_module(new Merchant_Wishlist()); |
| 287 |
} ); |