| 1 |
<?php |
| 2 |
/** |
| 3 |
* Extension Abstract |
| 4 |
* |
| 5 |
* @package NotificationX\Extensions |
| 6 |
*/ |
| 7 |
|
| 8 |
namespace NotificationX\Types; |
| 9 |
|
| 10 |
use NotificationX\Core\Rules; |
| 11 |
use NotificationX\Types\Traits\Conversions as TraitsConversions; |
| 12 |
use NotificationX\Extensions\GlobalFields; |
| 13 |
use NotificationX\GetInstance; |
| 14 |
use NotificationX\Modules; |
| 15 |
use NotificationX\NotificationX; |
| 16 |
|
| 17 |
/** |
| 18 |
* Extension Abstract for all Extension. |
| 19 |
* @method static Conversions get_instance($args = null) |
| 20 |
*/ |
| 21 |
class Conversions extends Types { |
| 22 |
/** |
| 23 |
* Instance of Admin |
| 24 |
* |
| 25 |
* @var Admin |
| 26 |
*/ |
| 27 |
use GetInstance; |
| 28 |
use TraitsConversions; |
| 29 |
|
| 30 |
// colored_themes |
| 31 |
public $priority = 5; |
| 32 |
public $themes = []; |
| 33 |
public $module = [ |
| 34 |
'modules_edd', |
| 35 |
'modules_custom_notification', |
| 36 |
'modules_zapier', |
| 37 |
'modules_bitintegrations', |
| 38 |
'modules_freemius', |
| 39 |
'modules_envato', |
| 40 |
]; |
| 41 |
|
| 42 |
public $conversions_count = array('conversions_conv-theme-seven', 'conversions_conv-theme-eight', 'conversions_conv-theme-nine', 'conversions_conv-theme-fourteen', 'conversions_conv-theme-sixteen', 'woocommerce_sales_conv-theme-seven', 'woocommerce_sales_conv-theme-eight', 'woocommerce_sales_conv-theme-nine', 'woocommerce_sales_conv-theme-fourteen', 'woocommerce_sales_conv-theme-sixteen'); |
| 43 |
public $map_dependency = []; |
| 44 |
|
| 45 |
|
| 46 |
public $default_source = 'woocommerce'; |
| 47 |
public $default_theme = 'conversions_theme-one'; |
| 48 |
public $default_res_theme = 'conversions_res-theme-one'; |
| 49 |
public $link_type = 'product_page'; |
| 50 |
|
| 51 |
/** |
| 52 |
* Initially Invoked when initialized. |
| 53 |
*/ |
| 54 |
public function __construct(){ |
| 55 |
parent::__construct(); |
| 56 |
$this->id = 'conversions'; |
| 57 |
} |
| 58 |
|
| 59 |
public function init() |
| 60 |
{ |
| 61 |
parent::init(); |
| 62 |
$this->title = __('Sales Notification', 'notificationx'); |
| 63 |
// nx_colored_themes |
| 64 |
$common_fields = [ |
| 65 |
'first_param' => 'tag_name', |
| 66 |
'custom_first_param' => __('Someone' , 'notificationx'), |
| 67 |
'second_param' => __('just purchased', 'notificationx'), |
| 68 |
'third_param' => 'tag_product_title', |
| 69 |
'custom_third_param' => __('Anonymous Product', 'notificationx'), |
| 70 |
'fourth_param' => 'tag_time', |
| 71 |
'custom_fourth_param' => __( 'Some time ago', 'notificationx' ), |
| 72 |
]; |
| 73 |
$this->themes = [ |
| 74 |
'theme-one' => [ |
| 75 |
'source' => NOTIFICATIONX_ADMIN_URL . 'images/extensions/themes/nx-conv-theme-2.jpg', |
| 76 |
'image_shape' => 'square', |
| 77 |
'template' => $common_fields, |
| 78 |
], |
| 79 |
// Figma "theme-one" — circular avatar, name row, action+product+time row, |
| 80 |
// green "Verified by NotificationX" badge (branding) + right-aligned "Buy now" link. |
| 81 |
'conv-theme-twelve' => array( |
| 82 |
'source' => NOTIFICATIONX_ADMIN_URL . 'images/extensions/themes/nx-conv-theme-12.png', |
| 83 |
'image_shape' => 'circle', |
| 84 |
'template' => $common_fields, |
| 85 |
'defaults' => [ |
| 86 |
'link_button' => true, |
| 87 |
'link_button_text' => __( 'Buy now', 'notificationx' ), |
| 88 |
], |
| 89 |
), |
| 90 |
// Figma "theme-two" — floating "Buy now" pill above top-right, rounded-square |
| 91 |
// avatar, row 1 = name + right-aligned time, row 2 = "Bought <product>", |
| 92 |
// green "Verified by NotificationX" badge. |
| 93 |
'conv-theme-thirteen' => array( |
| 94 |
'source' => NOTIFICATIONX_ADMIN_URL . 'images/extensions/themes/nx-conv-theme-13.png', |
| 95 |
'image_shape' => 'rounded', |
| 96 |
// Row 2 reads "Bought <product>" per the design (the shared default |
| 97 |
// is "just purchased"), so override the action verb for this theme. |
| 98 |
'template' => array_merge( $common_fields, [ |
| 99 |
'second_param' => __( 'Bought', 'notificationx' ), |
| 100 |
] ), |
| 101 |
'defaults' => [ |
| 102 |
'link_button' => true, |
| 103 |
'link_button_text' => __( 'Buy now', 'notificationx' ), |
| 104 |
], |
| 105 |
), |
| 106 |
// Figma "theme-four" — left lavender image panel with a check badge, floating |
| 107 |
// "Buy now" pill above top-right, row 1 = time (top-right), row 2 = name + |
| 108 |
// action + product, green "Verified by NotificationX" badge. |
| 109 |
'conv-theme-fifteen' => array( |
| 110 |
'source' => NOTIFICATIONX_ADMIN_URL . 'images/extensions/themes/nx-conv-theme-15.png', |
| 111 |
'image_shape' => 'rounded', |
| 112 |
'template' => $common_fields, |
| 113 |
'defaults' => [ |
| 114 |
'link_button' => true, |
| 115 |
'link_button_text' => __( 'Buy now', 'notificationx' ), |
| 116 |
], |
| 117 |
), |
| 118 |
'theme-two' => [ |
| 119 |
'source' => NOTIFICATIONX_ADMIN_URL . 'images/extensions/themes/nx-conv-theme-1.jpg', |
| 120 |
'image_shape' => 'square', |
| 121 |
'template' => $common_fields, |
| 122 |
], |
| 123 |
'theme-three' => [ |
| 124 |
'source' => NOTIFICATIONX_ADMIN_URL . 'images/extensions/themes/nx-conv-theme-3.jpg', |
| 125 |
'image_shape' => 'square', |
| 126 |
'template' => $common_fields, |
| 127 |
], |
| 128 |
'theme-five' => array( |
| 129 |
'source' => NOTIFICATIONX_ADMIN_URL . 'images/extensions/themes/pro/nx-conv-theme-five.png', |
| 130 |
'image_shape' => 'circle', |
| 131 |
'template' => $common_fields, |
| 132 |
), |
| 133 |
'theme-four' => array( |
| 134 |
'is_pro' => true, |
| 135 |
'source' => NOTIFICATIONX_ADMIN_URL . 'images/extensions/themes/pro/nx-conv-theme-four.png', |
| 136 |
'image_shape' => 'circle', |
| 137 |
'template' => $common_fields, |
| 138 |
), |
| 139 |
// @todo pro map theme |
| 140 |
'conv-theme-six' => array( |
| 141 |
'is_pro' => true, |
| 142 |
'source' => NOTIFICATIONX_ADMIN_URL . 'images/extensions/themes/pro/nx-conv-theme-6.jpg', |
| 143 |
'image_shape' => 'circle', |
| 144 |
), |
| 145 |
// @todo pro map theme |
| 146 |
'maps_theme' => array( |
| 147 |
'is_pro' => true, |
| 148 |
'source' => NOTIFICATIONX_ADMIN_URL . 'images/extensions/themes/pro/maps-theme.png', |
| 149 |
'image_shape' => 'square', |
| 150 |
'show_notification_image' => 'maps_image', |
| 151 |
), |
| 152 |
'conv-theme-ten' => array( |
| 153 |
'is_pro' => true, |
| 154 |
'source' => NOTIFICATIONX_ADMIN_URL . 'images/extensions/themes/nx-conv-theme-4.png', |
| 155 |
'image_shape' => 'rounded', |
| 156 |
'defaults' => [ |
| 157 |
'link_button' => true, |
| 158 |
'link_button_text' => __( 'Buy Now','notificationx' ), |
| 159 |
], |
| 160 |
'template' => $common_fields, |
| 161 |
), |
| 162 |
'conv-theme-eleven' => array( |
| 163 |
'is_pro' => true, |
| 164 |
'source' => NOTIFICATIONX_ADMIN_URL . 'images/extensions/themes/nx-conv-theme-5.png', |
| 165 |
'image_shape' => 'rounded', |
| 166 |
'defaults' => [ |
| 167 |
'link_button' => true, |
| 168 |
'link_button_text' => __( 'Buy Now','notificationx' ), |
| 169 |
], |
| 170 |
'template' => $common_fields, |
| 171 |
), |
| 172 |
// Figma "theme-three" — sales-count card (cart icon, "X Buyers purchased / |
| 173 |
// in last N days / Purchase now" + verified badge). Pro: the count is |
| 174 |
// aggregated by SalesFeatures (gated by $sales_count_themes) and the count |
| 175 |
// template is assigned in the Pro Conversions type. |
| 176 |
'conv-theme-fourteen' => array( |
| 177 |
'is_pro' => true, |
| 178 |
'source' => NOTIFICATIONX_ADMIN_URL . 'images/extensions/themes/nx-conv-theme-14.png', |
| 179 |
'image_shape' => 'rounded', |
| 180 |
'defaults' => [ |
| 181 |
'link_button' => true, |
| 182 |
'link_button_text' => __( 'Purchase now', 'notificationx' ), |
| 183 |
], |
| 184 |
), |
| 185 |
// Figma "theme-five" — sales-count card, alternate layout: verified badge |
| 186 |
// pill on top, cart icon (blue box) + "<count> Buyers purchased / In the |
| 187 |
// last N days- Join them now!", floating "Purchase now" pill top-right. |
| 188 |
// Same Pro sales-count engine as conv-theme-fourteen. |
| 189 |
'conv-theme-sixteen' => array( |
| 190 |
'is_pro' => true, |
| 191 |
'source' => NOTIFICATIONX_ADMIN_URL . 'images/extensions/themes/nx-conv-theme-16.png', |
| 192 |
'image_shape' => 'rounded', |
| 193 |
'defaults' => [ |
| 194 |
'link_button' => true, |
| 195 |
'link_button_text' => __( 'Purchase now', 'notificationx' ), |
| 196 |
], |
| 197 |
), |
| 198 |
'conv-theme-seven' => array( |
| 199 |
'is_pro' => true, |
| 200 |
'source' => NOTIFICATIONX_ADMIN_URL . 'images/extensions/themes/pro/nx-conv-theme-7.png', |
| 201 |
'image_shape' => 'rounded', |
| 202 |
), |
| 203 |
'conv-theme-eight' => array( |
| 204 |
'is_pro' => true, |
| 205 |
'source' => NOTIFICATIONX_ADMIN_URL . 'images/extensions/themes/pro/nx-conv-theme-8.png', |
| 206 |
'image_shape' => 'circle', |
| 207 |
|
| 208 |
), |
| 209 |
'conv-theme-nine' => array( |
| 210 |
'is_pro' => true, |
| 211 |
'source' => NOTIFICATIONX_ADMIN_URL . 'images/extensions/themes/pro/nx-conv-theme-9.png', |
| 212 |
'image_shape' => 'rounded', |
| 213 |
), |
| 214 |
]; |
| 215 |
$this->res_themes = [ |
| 216 |
'res-theme-one' => [ |
| 217 |
'source' => NOTIFICATIONX_ADMIN_URL . 'images/extensions/themes/res_conv/nx-conv-res-theme-1.png', |
| 218 |
'_template' => 'woo_template_new', |
| 219 |
'is_pro' => true, |
| 220 |
], |
| 221 |
'res-theme-two' => [ |
| 222 |
'source' => NOTIFICATIONX_ADMIN_URL . 'images/extensions/themes/res_conv/nx-conv-res-theme-2.png', |
| 223 |
'_template' => 'woo_template_new', |
| 224 |
'is_pro' => true, |
| 225 |
], |
| 226 |
'res-theme-three' => [ |
| 227 |
'source' => NOTIFICATIONX_ADMIN_URL . 'images/extensions/themes/res_conv/nx-conv-res-theme-3.png', |
| 228 |
'_template' => 'woo_template_new', |
| 229 |
'is_pro' => true, |
| 230 |
], |
| 231 |
'res-theme-four' => [ |
| 232 |
'source' => NOTIFICATIONX_ADMIN_URL . 'images/extensions/themes/res_conv/nx-conv-res-theme-4.png', |
| 233 |
'_template' => 'woo_template_new', |
| 234 |
'is_pro' => true, |
| 235 |
], |
| 236 |
'res-theme-five' => [ |
| 237 |
'source' => NOTIFICATIONX_ADMIN_URL . 'images/extensions/themes/res_conv/nx-conv-res-theme-5.png', |
| 238 |
'_template' => 'maps_template_new', |
| 239 |
'is_pro' => true, |
| 240 |
], |
| 241 |
'res-theme-six' => [ |
| 242 |
'source' => NOTIFICATIONX_ADMIN_URL . 'images/extensions/themes/res_conv/nx-conv-res-theme-6.png', |
| 243 |
'_template' => 'maps_template_new', |
| 244 |
'is_pro' => true, |
| 245 |
], |
| 246 |
'res-theme-seven' => [ |
| 247 |
'source' => NOTIFICATIONX_ADMIN_URL . 'images/extensions/themes/res_conv/nx-conv-res-theme-7.png', |
| 248 |
'_template' => 'woo_template_new', |
| 249 |
'is_pro' => true, |
| 250 |
], |
| 251 |
'res-theme-eight' => [ |
| 252 |
'source' => NOTIFICATIONX_ADMIN_URL . 'images/extensions/themes/res_conv/nx-conv-res-theme-8.png', |
| 253 |
'_template' => 'woo_template_new', |
| 254 |
'is_pro' => true, |
| 255 |
], |
| 256 |
'res-theme-nine' => [ |
| 257 |
'source' => NOTIFICATIONX_ADMIN_URL . 'images/extensions/themes/res_conv/nx-conv-res-theme-9.png', |
| 258 |
'_template' => 'woo_template_sales_count', |
| 259 |
'is_pro' => true, |
| 260 |
], |
| 261 |
'res-theme-ten' => [ |
| 262 |
'source' => NOTIFICATIONX_ADMIN_URL . 'images/extensions/themes/res_conv/nx-conv-res-theme-10.png', |
| 263 |
'_template' => 'woo_template_sales_count', |
| 264 |
'is_pro' => true, |
| 265 |
], |
| 266 |
'res-theme-eleven' => [ |
| 267 |
'source' => NOTIFICATIONX_ADMIN_URL . 'images/extensions/themes/res_conv/nx-conv-res-theme-11.png', |
| 268 |
'_template' => 'woo_template_sales_count', |
| 269 |
'is_pro' => true, |
| 270 |
], |
| 271 |
]; |
| 272 |
$this->templates = [ |
| 273 |
'woo_template_new' => [ |
| 274 |
'first_param' => GlobalFields::get_instance()->common_name_fields(), |
| 275 |
'third_param' => [ |
| 276 |
'tag_product_title' => __('Product Title', 'notificationx'), |
| 277 |
], |
| 278 |
'fourth_param' => [ |
| 279 |
'tag_time' => __('Definite Time', 'notificationx'), |
| 280 |
], |
| 281 |
'_themes' => [ |
| 282 |
'conversions_theme-one', |
| 283 |
'conversions_theme-two', |
| 284 |
'conversions_theme-three', |
| 285 |
'conversions_theme-four', |
| 286 |
'conversions_theme-five', |
| 287 |
'conversions_conv-theme-ten', |
| 288 |
'conversions_conv-theme-eleven', |
| 289 |
'conversions_conv-theme-twelve', |
| 290 |
'conversions_conv-theme-thirteen', |
| 291 |
'conversions_conv-theme-fifteen', |
| 292 |
'woocommerce_sales_theme-one', |
| 293 |
'woocommerce_sales_theme-two', |
| 294 |
'woocommerce_sales_theme-three', |
| 295 |
'woocommerce_sales_theme-four', |
| 296 |
'woocommerce_sales_theme-five', |
| 297 |
'woocommerce_sales_conv-theme-ten', |
| 298 |
'woocommerce_sales_conv-theme-eleven', |
| 299 |
'woocommerce_sales_conv-theme-twelve', |
| 300 |
'woocommerce_sales_conv-theme-thirteen', |
| 301 |
'woocommerce_sales_conv-theme-fifteen', |
| 302 |
] |
| 303 |
], |
| 304 |
'woo_template_sales_count' => [ |
| 305 |
'first_param' => GlobalFields::get_instance()->common_name_fields(), |
| 306 |
'third_param' => [ |
| 307 |
'tag_product_title' => __('Product Title', 'notificationx'), |
| 308 |
], |
| 309 |
'fourth_param' => [ |
| 310 |
// 'tag_time' => __('Definite Time', 'notificationx'), |
| 311 |
], |
| 312 |
'_themes' => [ |
| 313 |
'conversions_conv-theme-six', |
| 314 |
'conversions_conv-theme-seven', |
| 315 |
'conversions_conv-theme-eight', |
| 316 |
'conversions_conv-theme-nine', |
| 317 |
'conversions_conv-theme-fourteen', |
| 318 |
'conversions_conv-theme-sixteen', |
| 319 |
'woocommerce_sales_conv-theme-six', |
| 320 |
'woocommerce_sales_conv-theme-seven', |
| 321 |
'woocommerce_sales_conv-theme-eight', |
| 322 |
'woocommerce_sales_conv-theme-nine', |
| 323 |
'woocommerce_sales_conv-theme-fourteen', |
| 324 |
'woocommerce_sales_conv-theme-sixteen', |
| 325 |
] |
| 326 |
], |
| 327 |
]; |
| 328 |
} |
| 329 |
|
| 330 |
/** |
| 331 |
* Hooked to nx_before_metabox_load action. |
| 332 |
* |
| 333 |
* @return void |
| 334 |
*/ |
| 335 |
public function init_fields() { |
| 336 |
parent::init_fields(); |
| 337 |
} |
| 338 |
|
| 339 |
/** |
| 340 |
* @todo remove in the future. |
| 341 |
* |
| 342 |
* @param [type] $data |
| 343 |
* @param [type] $settings |
| 344 |
* @return void |
| 345 |
*/ |
| 346 |
public function nx_can_entry($return, $entry, $settings){ |
| 347 |
if(!($this->_excludes_product($entry['data'], $settings) && $this->_show_purchaseof($entry['data'], $settings))){ |
| 348 |
return false; |
| 349 |
} |
| 350 |
|
| 351 |
return $return; |
| 352 |
} |
| 353 |
|
| 354 |
/** |
| 355 |
* @todo remove in the future. |
| 356 |
* |
| 357 |
* @param [type] $data |
| 358 |
* @param [type] $settings |
| 359 |
* @return void |
| 360 |
*/ |
| 361 |
public function show_exclude_product( $data, $settings ){ |
| 362 |
$new_data = []; |
| 363 |
|
| 364 |
if( ! empty( $data ) ) { |
| 365 |
foreach( $data as $key => $product ) { |
| 366 |
if( $this->_excludes_product($product, $settings) && $this->_show_purchaseof($product, $settings) ) { |
| 367 |
$new_data[ $key ] = $product; |
| 368 |
} |
| 369 |
} |
| 370 |
} |
| 371 |
|
| 372 |
return $new_data; |
| 373 |
|
| 374 |
} |
| 375 |
|
| 376 |
public function _excludes_product( $product, $settings ){ |
| 377 |
if( empty( $settings['product_exclude_by'] ) || $settings['product_exclude_by'] === 'none' ) { |
| 378 |
return true; |
| 379 |
} |
| 380 |
|
| 381 |
$product_category_list = []; |
| 382 |
|
| 383 |
$product_id = $product['product_id']; |
| 384 |
if( $settings['product_exclude_by'] == 'product_category' ) { |
| 385 |
$term = 'product_cat'; |
| 386 |
if($settings['source'] == 'edd' || $settings['source'] == 'edd_inline'){ |
| 387 |
$term = 'download_category'; |
| 388 |
} |
| 389 |
$product_categories = get_the_terms( $product_id, $term ); |
| 390 |
if( ! is_wp_error( $product_categories ) ) { |
| 391 |
foreach( $product_categories as $category ) { |
| 392 |
$product_category_list[] = $category->slug; |
| 393 |
} |
| 394 |
} |
| 395 |
|
| 396 |
$product_category_count = count( $product_category_list ); |
| 397 |
$array_diff = array_diff( $product_category_list, $settings['exclude_categories'] ); |
| 398 |
$array_diff_count = count( $array_diff ); |
| 399 |
|
| 400 |
if( ! ( $array_diff_count < $product_category_count ) ) { |
| 401 |
return true; |
| 402 |
} |
| 403 |
$product_category_list = []; |
| 404 |
} |
| 405 |
if( $settings['product_exclude_by'] == 'manual_selection' ) { |
| 406 |
if( isset($settings['exclude_products']) && is_array($settings['exclude_products']) && ! in_array( $product_id, $settings['exclude_products'] ) ) { |
| 407 |
return true; |
| 408 |
} |
| 409 |
} |
| 410 |
|
| 411 |
return false; |
| 412 |
|
| 413 |
} |
| 414 |
|
| 415 |
|
| 416 |
public function _show_purchaseof( $product, $settings ){ |
| 417 |
if( empty( $settings['product_control'] ) || $settings['product_control'] === 'none' ) { |
| 418 |
return true; |
| 419 |
} |
| 420 |
|
| 421 |
$product_category_list = []; |
| 422 |
|
| 423 |
$product_id = $product['product_id']; |
| 424 |
if( $settings['product_control'] == 'product_category' ) { |
| 425 |
$term = 'product_cat'; |
| 426 |
if($settings['source'] == 'edd' || $settings['source'] == 'edd_inline'){ |
| 427 |
$term = 'download_category'; |
| 428 |
} |
| 429 |
$product_categories = get_the_terms( $product_id, $term ); |
| 430 |
if(is_array($product_categories) && ! is_wp_error( $product_categories ) ) { |
| 431 |
foreach( $product_categories as $category ) { |
| 432 |
$product_category_list[] = $category->slug; |
| 433 |
} |
| 434 |
} |
| 435 |
|
| 436 |
$product_category_count = count( $product_category_list ); |
| 437 |
$array_diff = array_diff( $product_category_list, $settings['category_list'] ); |
| 438 |
$array_diff_count = count( $array_diff ); |
| 439 |
|
| 440 |
if( $array_diff_count < $product_category_count ) { |
| 441 |
return true; |
| 442 |
} |
| 443 |
|
| 444 |
} |
| 445 |
if( $settings['product_control'] == 'manual_selection' ) { |
| 446 |
if( in_array( $product_id, $settings['product_list'] ) ) { |
| 447 |
return true; |
| 448 |
} |
| 449 |
} |
| 450 |
|
| 451 |
return false; |
| 452 |
} |
| 453 |
|
| 454 |
} |
| 455 |
|