| 1 |
<?php |
| 2 |
/** |
| 3 |
* WooCommerce Extension |
| 4 |
* |
| 5 |
* @package NotificationX\Extensions |
| 6 |
*/ |
| 7 |
|
| 8 |
namespace NotificationX\Extensions\WooCommerce; |
| 9 |
|
| 10 |
use NotificationX\Core\PostType; |
| 11 |
use NotificationX\Core\Rules; |
| 12 |
use NotificationX\GetInstance; |
| 13 |
use NotificationX\Extensions\Extension; |
| 14 |
use NotificationX\Extensions\GlobalFields; |
| 15 |
|
| 16 |
/** |
| 17 |
* WooCommerce Extension Class |
| 18 |
*/ |
| 19 |
class WooInline extends WooCommerce { |
| 20 |
/** |
| 21 |
* Instance of WooInline |
| 22 |
* |
| 23 |
* @var WooInline |
| 24 |
*/ |
| 25 |
protected static $instance = null; |
| 26 |
public $priority = 5; |
| 27 |
public $id = 'woo_inline'; |
| 28 |
public $img = NOTIFICATIONX_ADMIN_URL . 'images/extensions/sources/woocommerce.png'; |
| 29 |
public $doc_link = 'https://notificationx.com/docs/woocommerce-sales-notifications/'; |
| 30 |
public $types = 'inline'; |
| 31 |
public $module = 'modules_woocommerce'; |
| 32 |
public $module_priority = 3; |
| 33 |
public $class = '\WooCommerce'; |
| 34 |
public $is_pro = true; |
| 35 |
|
| 36 |
/** |
| 37 |
* Get the instance of called class. |
| 38 |
* |
| 39 |
* @return WooInline |
| 40 |
*/ |
| 41 |
public static function get_instance($args = null){ |
| 42 |
if ( is_null( static::$instance ) || ! static::$instance instanceof self ) { |
| 43 |
$class = __CLASS__; |
| 44 |
if(strpos($class, "NotificationX\\") === 0){ |
| 45 |
$pro_class = str_replace("NotificationX\\", "NotificationXPro\\", $class); |
| 46 |
if(class_exists($pro_class)){ |
| 47 |
$class = $pro_class; |
| 48 |
} |
| 49 |
} |
| 50 |
|
| 51 |
if(!empty($args)){ |
| 52 |
static::$instance = new $class($args); |
| 53 |
} |
| 54 |
else{ |
| 55 |
static::$instance = new $class; |
| 56 |
} |
| 57 |
} |
| 58 |
return static::$instance; |
| 59 |
} |
| 60 |
|
| 61 |
/** |
| 62 |
* Initially Invoked when initialized. |
| 63 |
*/ |
| 64 |
public function __construct(){ |
| 65 |
parent::__construct(); |
| 66 |
add_filter( 'nx_show_on_exclude', array( $this, 'show_on_exclude' ), 10, 4 ); |
| 67 |
} |
| 68 |
|
| 69 |
public function init_extension() |
| 70 |
{ |
| 71 |
|
| 72 |
$this->themes = [ |
| 73 |
'conv-theme-seven' => array( |
| 74 |
'is_pro' => true, |
| 75 |
'source' => NOTIFICATIONX_ADMIN_URL . 'images/extensions/themes/pro/woo-inline.jpg', |
| 76 |
'image_shape' => 'rounded', |
| 77 |
'inline_location' => [ 'woocommerce_before_add_to_cart_form' ], |
| 78 |
'template' => [ |
| 79 |
'first_param' => 'tag_sales_count', |
| 80 |
'custom_first_param' => __( '99', 'notificationx' ), |
| 81 |
'second_param' => __( 'people purchased', 'notificationx' ), |
| 82 |
'third_param' => 'tag_product_title', |
| 83 |
'custom_third_param' => ' ', |
| 84 |
'fourth_param' => 'tag_7days', |
| 85 |
'custom_fourth_param' => __( 'in last {{day:7}}', 'notificationx' ), |
| 86 |
], |
| 87 |
), |
| 88 |
'stock-theme-one' => array( |
| 89 |
'is_pro' => true, |
| 90 |
'source' => NOTIFICATIONX_ADMIN_URL . 'images/extensions/themes/pro/woo-inline-2.jpg', |
| 91 |
'image_shape' => 'rounded', |
| 92 |
'inline_location' => [ 'woocommerce_before_add_to_cart_form' ], |
| 93 |
'template' => [ |
| 94 |
// 'first_param' => 'tag_sales_count', |
| 95 |
// 'custom_first_param' => __( 'Someone', 'notificationx' ), |
| 96 |
'second_param' => __( 'Only', 'notificationx' ), |
| 97 |
'third_param' => 'tag_stock_count', |
| 98 |
'custom_third_param' => 10, |
| 99 |
'fourth_param' => 'tag_left_in_stock', |
| 100 |
'custom_fourth_param' => __( 'left in stock', 'notificationx' ), |
| 101 |
'fifth_param' => 'tag_order_soon', |
| 102 |
'custom_fifth_param' => __( '- order soon.', 'notificationx' ), |
| 103 |
], |
| 104 |
), |
| 105 |
'stock-theme-two' => array( |
| 106 |
'is_pro' => true, |
| 107 |
'source' => NOTIFICATIONX_ADMIN_URL . 'images/extensions/themes/pro/woo-inline-3.jpg', |
| 108 |
'image_shape' => 'rounded', |
| 109 |
'inline_location' => [ 'woocommerce_after_cart_item_name' ], |
| 110 |
'template' => [ |
| 111 |
// 'first_param' => 'tag_sales_count', |
| 112 |
// 'custom_first_param' => __( 'Someone', 'notificationx' ), |
| 113 |
'second_param' => __( 'In high demand - only', 'notificationx' ), |
| 114 |
'third_param' => 'tag_stock_count', |
| 115 |
'custom_third_param' => 10, |
| 116 |
'fourth_param' => 'tag_left', |
| 117 |
'custom_fourth_param' => __( 'left', 'notificationx' ), |
| 118 |
'fifth_param' => 'tag_on_our_site', |
| 119 |
'custom_fifth_param' => __( 'on our site!', 'notificationx' ), |
| 120 |
], |
| 121 |
), |
| 122 |
]; |
| 123 |
$this->templates = [ |
| 124 |
'woo_template_sales_count' => [ |
| 125 |
'first_param' => [ |
| 126 |
'tag_sales_count' => __( 'Sales Count', 'notificationx' ), |
| 127 |
], |
| 128 |
'third_param' => [ |
| 129 |
'tag_product_title' => __( 'Product Title', 'notificationx' ), |
| 130 |
], |
| 131 |
'fourth_param' => [ |
| 132 |
'tag_1day' => __( 'In last 1 day', 'notificationx' ), |
| 133 |
'tag_7days' => __( 'In last 7 days', 'notificationx' ), |
| 134 |
'tag_30days' => __( 'In last 30 days', 'notificationx' ), |
| 135 |
], |
| 136 |
'_themes' => [ |
| 137 |
"{$this->id}_conv-theme-seven", |
| 138 |
], |
| 139 |
], |
| 140 |
'inline_stock_template' => [ |
| 141 |
'third_param' => [ |
| 142 |
'tag_stock_count' => __( 'Stock Count', 'notificationx' ), |
| 143 |
], |
| 144 |
'fourth_param' => [ |
| 145 |
'tag_left_in_stock' => __( 'left in stock', 'notificationx' ), |
| 146 |
'tag_left' => __( 'left', 'notificationx' ), |
| 147 |
], |
| 148 |
'fifth_param' => [ |
| 149 |
'tag_order_soon' => __( 'order soon.', 'notificationx' ), |
| 150 |
'tag_on_our_site' => __( 'on our site!', 'notificationx' ), |
| 151 |
], |
| 152 |
'_themes' => [ |
| 153 |
"{$this->id}_stock-theme-one", |
| 154 |
"{$this->id}_stock-theme-two", |
| 155 |
], |
| 156 |
], |
| 157 |
]; |
| 158 |
} |
| 159 |
|
| 160 |
/** |
| 161 |
* @todo Something |
| 162 |
* |
| 163 |
* @param [type] $exclude |
| 164 |
* @param [type] $settings |
| 165 |
* @return void |
| 166 |
*/ |
| 167 |
public function show_on_exclude( $exclude, $settings ) { |
| 168 |
if ( $settings['source'] === $this->id ) { |
| 169 |
$woo_location = $settings['inline_location']; |
| 170 |
$hooks = ['woocommerce_before_add_to_cart_form', 'woocommerce_after_shop_loop_item_title', 'woocommerce_after_shop_loop_item', 'woocommerce_after_cart_item_name']; |
| 171 |
$diff = array_diff( $hooks, $woo_location ); |
| 172 |
if ( count( $diff ) <= count( $hooks ) ) { |
| 173 |
return true; |
| 174 |
} |
| 175 |
} |
| 176 |
return $exclude; |
| 177 |
} |
| 178 |
|
| 179 |
public function content_fields($fields){ |
| 180 |
return $fields; |
| 181 |
} |
| 182 |
|
| 183 |
} |
| 184 |
|