| 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; |
| 12 |
use NotificationX\Types\Traits\Reviews; |
| 13 |
use NotificationX\Extensions\GlobalFields; |
| 14 |
use NotificationX\GetInstance; |
| 15 |
use NotificationX\NotificationX; |
| 16 |
|
| 17 |
/** |
| 18 |
* Extension Abstract for all Extension. |
| 19 |
* @method static WooCommerce get_instance($args = null) |
| 20 |
*/ |
| 21 |
class WooCommerceSales extends Types { |
| 22 |
/** |
| 23 |
* Instance of Admin |
| 24 |
* |
| 25 |
* @var Admin |
| 26 |
*/ |
| 27 |
use GetInstance; |
| 28 |
use Reviews; |
| 29 |
use Conversions; |
| 30 |
|
| 31 |
// colored_themes |
| 32 |
public $priority = 5; |
| 33 |
public $themes = []; |
| 34 |
public $res_themes = []; |
| 35 |
public $module = [ |
| 36 |
'modules_woocommerce', |
| 37 |
'modules_woocommerce_sales_reviews', |
| 38 |
'modules_woocommerce_sales_inline', |
| 39 |
]; |
| 40 |
|
| 41 |
public $map_dependency = []; |
| 42 |
|
| 43 |
public $default_source = 'woocommerce_sales'; |
| 44 |
// public $default_theme = 'woocommerce_theme-one'; |
| 45 |
public $link_type = 'product_page'; |
| 46 |
|
| 47 |
/** |
| 48 |
* Initially Invoked when initialized. |
| 49 |
*/ |
| 50 |
public function __construct(){ |
| 51 |
parent::__construct(); |
| 52 |
$this->id = 'woocommerce_sales'; |
| 53 |
} |
| 54 |
|
| 55 |
public function init() { |
| 56 |
parent::init(); |
| 57 |
$this->title = __('WooCommerce', 'notificationx'); |
| 58 |
|
| 59 |
$is_pro = ! NotificationX::is_pro(); |
| 60 |
// nx_colored_themes |
| 61 |
$common_fields = [ |
| 62 |
'first_param' => 'tag_name', |
| 63 |
'custom_first_param' => __('Someone' , 'notificationx'), |
| 64 |
'second_param' => __('just purchased', 'notificationx'), |
| 65 |
'third_param' => 'tag_product_title', |
| 66 |
'custom_third_param' => __('Anonymous Product', 'notificationx'), |
| 67 |
'fourth_param' => 'tag_time', |
| 68 |
'custom_fourth_param' => __( 'Some time ago', 'notificationx' ), |
| 69 |
]; |
| 70 |
$this->themes = [ |
| 71 |
'theme-one' => [ |
| 72 |
'source' => NOTIFICATIONX_ADMIN_URL . 'images/extensions/themes/nx-conv-theme-2.jpg', |
| 73 |
'image_shape' => 'square', |
| 74 |
'template' => $common_fields, |
| 75 |
], |
| 76 |
'theme-two' => [ |
| 77 |
'source' => NOTIFICATIONX_ADMIN_URL . 'images/extensions/themes/nx-conv-theme-1.jpg', |
| 78 |
'image_shape' => 'square', |
| 79 |
'template' => $common_fields, |
| 80 |
], |
| 81 |
'theme-three' => [ |
| 82 |
'source' => NOTIFICATIONX_ADMIN_URL . 'images/extensions/themes/nx-conv-theme-3.jpg', |
| 83 |
'image_shape' => 'square', |
| 84 |
'template' => $common_fields, |
| 85 |
], |
| 86 |
'theme-five' => array( |
| 87 |
'source' => NOTIFICATIONX_ADMIN_URL . 'images/extensions/themes/pro/nx-conv-theme-five.png', |
| 88 |
'image_shape' => 'circle', |
| 89 |
'template' => $common_fields, |
| 90 |
), |
| 91 |
'theme-four' => array( |
| 92 |
'is_pro' => true, |
| 93 |
'source' => NOTIFICATIONX_ADMIN_URL . 'images/extensions/themes/pro/nx-conv-theme-four.png', |
| 94 |
'image_shape' => 'circle', |
| 95 |
'template' => $common_fields, |
| 96 |
), |
| 97 |
// @todo pro map theme |
| 98 |
'conv-theme-six' => array( |
| 99 |
'is_pro' => true, |
| 100 |
'source' => NOTIFICATIONX_ADMIN_URL . 'images/extensions/themes/pro/nx-conv-theme-6.jpg', |
| 101 |
'image_shape' => 'circle', |
| 102 |
), |
| 103 |
// @todo pro map theme |
| 104 |
'maps_theme' => array( |
| 105 |
'is_pro' => true, |
| 106 |
'source' => NOTIFICATIONX_ADMIN_URL . 'images/extensions/themes/pro/maps-theme.png', |
| 107 |
'image_shape' => 'square', |
| 108 |
'show_notification_image' => 'maps_image', |
| 109 |
), |
| 110 |
'conv-theme-ten' => array( |
| 111 |
'is_pro' => true, |
| 112 |
'source' => NOTIFICATIONX_ADMIN_URL . 'images/extensions/themes/nx-conv-theme-4.png', |
| 113 |
'image_shape' => 'rounded', |
| 114 |
'defaults' => [ |
| 115 |
'link_button' => true, |
| 116 |
], |
| 117 |
'template' => $common_fields, |
| 118 |
), |
| 119 |
'conv-theme-eleven' => array( |
| 120 |
'is_pro' => true, |
| 121 |
'source' => NOTIFICATIONX_ADMIN_URL . 'images/extensions/themes/nx-conv-theme-5.png', |
| 122 |
'image_shape' => 'rounded', |
| 123 |
'defaults' => [ |
| 124 |
'link_button' => true, |
| 125 |
], |
| 126 |
'template' => $common_fields, |
| 127 |
), |
| 128 |
'conv-theme-seven' => array( |
| 129 |
'is_pro' => true, |
| 130 |
'source' => NOTIFICATIONX_ADMIN_URL . 'images/extensions/themes/pro/nx-conv-theme-7.png', |
| 131 |
'image_shape' => 'rounded', |
| 132 |
), |
| 133 |
'conv-theme-eight' => array( |
| 134 |
'is_pro' => true, |
| 135 |
'source' => NOTIFICATIONX_ADMIN_URL . 'images/extensions/themes/pro/nx-conv-theme-8.png', |
| 136 |
'image_shape' => 'circle', |
| 137 |
|
| 138 |
), |
| 139 |
'conv-theme-nine' => array( |
| 140 |
'is_pro' => true, |
| 141 |
'source' => NOTIFICATIONX_ADMIN_URL . 'images/extensions/themes/pro/nx-conv-theme-9.png', |
| 142 |
'image_shape' => 'rounded', |
| 143 |
), |
| 144 |
|
| 145 |
]; |
| 146 |
$this->res_themes = [ |
| 147 |
'res-theme-one' => [ |
| 148 |
'source' => NOTIFICATIONX_ADMIN_URL . 'images/extensions/themes/res_conv/nx-conv-res-theme-1.png', |
| 149 |
'_template' => 'woo_template_new', |
| 150 |
'is_pro' => true, |
| 151 |
], |
| 152 |
'res-theme-two' => [ |
| 153 |
'source' => NOTIFICATIONX_ADMIN_URL . 'images/extensions/themes/res_conv/nx-conv-res-theme-2.png', |
| 154 |
'_template' => 'woo_template_new', |
| 155 |
'is_pro' => true, |
| 156 |
], |
| 157 |
'res-theme-three' => [ |
| 158 |
'source' => NOTIFICATIONX_ADMIN_URL . 'images/extensions/themes/res_conv/nx-conv-res-theme-3.png', |
| 159 |
'_template' => 'woo_template_new', |
| 160 |
'is_pro' => true, |
| 161 |
], |
| 162 |
'res-theme-four' => [ |
| 163 |
'source' => NOTIFICATIONX_ADMIN_URL . 'images/extensions/themes/res_conv/nx-conv-res-theme-4.png', |
| 164 |
'_template' => 'woo_template_new', |
| 165 |
'is_pro' => true, |
| 166 |
], |
| 167 |
'res-theme-five' => [ |
| 168 |
'source' => NOTIFICATIONX_ADMIN_URL . 'images/extensions/themes/res_conv/nx-conv-res-theme-5.png', |
| 169 |
'_template' => 'maps_template_new', |
| 170 |
'is_pro' => true, |
| 171 |
], |
| 172 |
'res-theme-six' => [ |
| 173 |
'source' => NOTIFICATIONX_ADMIN_URL . 'images/extensions/themes/res_conv/nx-conv-res-theme-6.png', |
| 174 |
'_template' => 'maps_template_new', |
| 175 |
'is_pro' => true, |
| 176 |
], |
| 177 |
'res-theme-seven' => [ |
| 178 |
'source' => NOTIFICATIONX_ADMIN_URL . 'images/extensions/themes/res_conv/nx-conv-res-theme-7.png', |
| 179 |
'_template' => 'woo_template_new', |
| 180 |
'is_pro' => true, |
| 181 |
], |
| 182 |
'res-theme-eight' => [ |
| 183 |
'source' => NOTIFICATIONX_ADMIN_URL . 'images/extensions/themes/res_conv/nx-conv-res-theme-8.png', |
| 184 |
'_template' => 'woo_template_new', |
| 185 |
'is_pro' => true, |
| 186 |
], |
| 187 |
'res-theme-nine' => [ |
| 188 |
'source' => NOTIFICATIONX_ADMIN_URL . 'images/extensions/themes/res_conv/nx-conv-res-theme-9.png', |
| 189 |
'_template' => 'woo_template_sales_count', |
| 190 |
'is_pro' => true, |
| 191 |
], |
| 192 |
'res-theme-ten' => [ |
| 193 |
'source' => NOTIFICATIONX_ADMIN_URL . 'images/extensions/themes/res_conv/nx-conv-res-theme-10.png', |
| 194 |
'_template' => 'woo_template_sales_count', |
| 195 |
'is_pro' => true, |
| 196 |
], |
| 197 |
'res-theme-eleven' => [ |
| 198 |
'source' => NOTIFICATIONX_ADMIN_URL . 'images/extensions/themes/res_conv/nx-conv-res-theme-11.png', |
| 199 |
'_template' => 'woo_template_sales_count', |
| 200 |
'is_pro' => true, |
| 201 |
], |
| 202 |
]; |
| 203 |
$this->templates = [ |
| 204 |
'woo_template_new' => [ |
| 205 |
'first_param' => GlobalFields::get_instance()->common_name_fields(), |
| 206 |
'third_param' => [ |
| 207 |
'tag_product_title' => __('Product Title', 'notificationx'), |
| 208 |
], |
| 209 |
'fourth_param' => [ |
| 210 |
'tag_time' => __('Definite Time', 'notificationx'), |
| 211 |
], |
| 212 |
'_themes' => [ |
| 213 |
'woocommerce_sales_theme-one', |
| 214 |
'woocommerce_sales_theme-two', |
| 215 |
'woocommerce_sales_theme-three', |
| 216 |
'woocommerce_sales_theme-four', |
| 217 |
'woocommerce_sales_theme-five', |
| 218 |
'woocommerce_sales_conv-theme-ten', |
| 219 |
'woocommerce_sales_conv-theme-eleven', |
| 220 |
] |
| 221 |
], |
| 222 |
'woo_template_sales_count' => [ |
| 223 |
'first_param' => GlobalFields::get_instance()->common_name_fields(), |
| 224 |
'third_param' => [ |
| 225 |
'tag_product_title' => __('Product Title', 'notificationx'), |
| 226 |
], |
| 227 |
'fourth_param' => [ |
| 228 |
// 'tag_time' => __('Definite Time', 'notificationx'), |
| 229 |
], |
| 230 |
'_themes' => [ |
| 231 |
'woocommerce_sales_conv-theme-six', |
| 232 |
'woocommerce_sales_conv-theme-seven', |
| 233 |
'woocommerce_sales_conv-theme-eight', |
| 234 |
'woocommerce_sales_conv-theme-nine', |
| 235 |
] |
| 236 |
], |
| 237 |
]; |
| 238 |
add_filter("nx_filtered_entry_{$this->id}", array($this, 'conversion_data'), 11, 2); |
| 239 |
} |
| 240 |
|
| 241 |
/** |
| 242 |
* Hooked to nx_before_metabox_load action. |
| 243 |
* |
| 244 |
* @return void |
| 245 |
*/ |
| 246 |
public function init_fields() { |
| 247 |
parent::init_fields(); |
| 248 |
add_filter('nx_notification_template', [$this, 'review_templates'], 7); |
| 249 |
add_filter('nx_content_trim_length_dependency', [$this, 'content_trim_length_dependency']); |
| 250 |
} |
| 251 |
|
| 252 |
|
| 253 |
/** |
| 254 |
* @todo remove in the future. |
| 255 |
* |
| 256 |
* @param [type] $data |
| 257 |
* @param [type] $settings |
| 258 |
* @return void |
| 259 |
*/ |
| 260 |
public function nx_can_entry($return, $entry, $settings){ |
| 261 |
if(!($this->_excludes_product($entry['data'], $settings) && $this->_show_purchaseof($entry['data'], $settings))){ |
| 262 |
return false; |
| 263 |
} |
| 264 |
|
| 265 |
return $return; |
| 266 |
} |
| 267 |
|
| 268 |
/** |
| 269 |
* @todo remove in the future. |
| 270 |
* |
| 271 |
* @param [type] $data |
| 272 |
* @param [type] $settings |
| 273 |
* @return void |
| 274 |
*/ |
| 275 |
public function show_exclude_product( $data, $settings ){ |
| 276 |
$new_data = []; |
| 277 |
|
| 278 |
if( ! empty( $data ) ) { |
| 279 |
foreach( $data as $key => $product ) { |
| 280 |
if( $this->_excludes_product($product, $settings) && $this->_show_purchaseof($product, $settings) ) { |
| 281 |
$new_data[ $key ] = $product; |
| 282 |
} |
| 283 |
} |
| 284 |
} |
| 285 |
|
| 286 |
return $new_data; |
| 287 |
|
| 288 |
} |
| 289 |
|
| 290 |
public function _excludes_product( $product, $settings ){ |
| 291 |
if( empty( $settings['product_exclude_by'] ) || $settings['product_exclude_by'] === 'none' ) { |
| 292 |
return true; |
| 293 |
} |
| 294 |
|
| 295 |
$product_category_list = []; |
| 296 |
|
| 297 |
$product_id = $product['product_id']; |
| 298 |
if( $settings['product_exclude_by'] == 'product_category' ) { |
| 299 |
$term = 'product_cat'; |
| 300 |
if($settings['source'] == 'edd' || $settings['source'] == 'edd_inline'){ |
| 301 |
$term = 'download_category'; |
| 302 |
} |
| 303 |
$product_categories = get_the_terms( $product_id, $term ); |
| 304 |
if( ! is_wp_error( $product_categories ) ) { |
| 305 |
foreach( $product_categories as $category ) { |
| 306 |
$product_category_list[] = $category->slug; |
| 307 |
} |
| 308 |
} |
| 309 |
|
| 310 |
$product_category_count = count( $product_category_list ); |
| 311 |
$array_diff = array_diff( $product_category_list, $settings['exclude_categories'] ); |
| 312 |
$array_diff_count = count( $array_diff ); |
| 313 |
|
| 314 |
if( ! ( $array_diff_count < $product_category_count ) ) { |
| 315 |
return true; |
| 316 |
} |
| 317 |
$product_category_list = []; |
| 318 |
} |
| 319 |
if( $settings['product_exclude_by'] == 'manual_selection' ) { |
| 320 |
if( isset($settings['exclude_products']) && is_array($settings['exclude_products']) && ! in_array( $product_id, $settings['exclude_products'] ) ) { |
| 321 |
return true; |
| 322 |
} |
| 323 |
} |
| 324 |
|
| 325 |
return false; |
| 326 |
|
| 327 |
} |
| 328 |
|
| 329 |
|
| 330 |
public function _show_purchaseof( $product, $settings ){ |
| 331 |
if( empty( $settings['product_control'] ) || $settings['product_control'] === 'none' ) { |
| 332 |
return true; |
| 333 |
} |
| 334 |
|
| 335 |
$product_category_list = []; |
| 336 |
|
| 337 |
$product_id = $product['product_id']; |
| 338 |
if( $settings['product_control'] == 'product_category' ) { |
| 339 |
$term = 'product_cat'; |
| 340 |
if($settings['source'] == 'edd' || $settings['source'] == 'edd_inline'){ |
| 341 |
$term = 'download_category'; |
| 342 |
} |
| 343 |
$product_categories = get_the_terms( $product_id, $term ); |
| 344 |
if(is_array($product_categories) && ! is_wp_error( $product_categories ) ) { |
| 345 |
foreach( $product_categories as $category ) { |
| 346 |
$product_category_list[] = $category->slug; |
| 347 |
} |
| 348 |
} |
| 349 |
|
| 350 |
$product_category_count = count( $product_category_list ); |
| 351 |
$array_diff = array_diff( $product_category_list, $settings['category_list'] ); |
| 352 |
$array_diff_count = count( $array_diff ); |
| 353 |
|
| 354 |
if( $array_diff_count < $product_category_count ) { |
| 355 |
return true; |
| 356 |
} |
| 357 |
|
| 358 |
} |
| 359 |
if( $settings['product_control'] == 'manual_selection' ) { |
| 360 |
if( in_array( $product_id, $settings['product_list'] ) ) { |
| 361 |
return true; |
| 362 |
} |
| 363 |
} |
| 364 |
|
| 365 |
return false; |
| 366 |
} |
| 367 |
|
| 368 |
|
| 369 |
} |
| 370 |
|