WJECF_Admin

The WooCommerce Extended Coupon Features WJECF Admin class.

Defined (1)

The class is defined in the following location(s).

/includes/admin/wjecf-admin.php  
  1. class WJECF_Admin extends Abstract_WJECF_Plugin { 
  2.  
  3. public function __construct() {  
  4. $this->set_plugin_data( array( 
  5. 'description' => __( 'Admin interface of WooCommerce Extended Coupon Features.', 'woocommerce-jos-autocoupon' ),  
  6. 'dependencies' => array(),  
  7. 'can_be_disabled' => false 
  8. ) ); 
  9.  
  10. public function init_admin_hook() { 
  11. add_action( 'admin_notices', array( $this, 'admin_notices')); 
  12.  
  13. if ( ! WJECF_WC()->check_woocommerce_version('2.3.0') ) { 
  14. $this->enqueue_notice( '<p>' .  
  15. __( '<strong>WooCommerce Extended Coupon Features:</strong> You are using an old version of WooCommerce. Updating of WooCommerce is recommended as using an outdated version might cause unexpected behaviour in combination with modern plugins.' )  
  16. . '</p>', 'notice-warning' ); 
  17. //Admin hooks 
  18. add_filter( 'plugin_row_meta', array( $this, 'wjecf_plugin_meta' ), 10, 2 ); 
  19. add_action( 'admin_head', array( $this, 'on_admin_head')); 
  20.  
  21. add_filter( 'woocommerce_coupon_data_tabs', array( $this, 'admin_coupon_options_tabs' ), 10, 1); 
  22. add_action( 'woocommerce_coupon_data_panels', array( $this, 'admin_coupon_options_panels' ), 10, 0 ); 
  23. add_action( 'woocommerce_process_shop_coupon_meta', array( $this, 'process_shop_coupon_meta' ), 10, 2 );  
  24.  
  25. add_action( 'wjecf_coupon_metabox_products', array( $this, 'admin_coupon_metabox_products' ), 10, 2 ); 
  26. add_action( 'wjecf_coupon_metabox_checkout', array( $this, 'admin_coupon_metabox_checkout' ), 10, 2 ); 
  27. add_action( 'wjecf_coupon_metabox_customer', array( $this, 'admin_coupon_metabox_customer' ), 10, 2 ); 
  28. add_action( 'wjecf_coupon_metabox_misc', array( $this, 'admin_coupon_metabox_misc' ), 10, 2 ); 
  29.  
  30. WJECF_ADMIN()->add_inline_style( ' 
  31. #woocommerce-coupon-data .wjecf-not-wide { width:50% } 
  32. ');  
  33.  
  34. //WORK IN PROGRESS: add_action( 'admin_menu', array( $this, 'action_admin_menu' ) ); 
  35. }  
  36.  
  37. // =========================================================================== 
  38. // START - ADMIN NOTICES 
  39. // Allows notices to be displayed on the admin pages 
  40. // =========================================================================== 
  41.  
  42. private $notices = array(); 
  43.  
  44. /** 
  45. * Enqueue a notice to display on the admin page 
  46. * @param stirng $html Please embed in <p> tags 
  47. * @param string $class  
  48. */ 
  49. public function enqueue_notice( $html, $class = 'notice-info' ) { 
  50. $this->notices[] = array( 'class' => $class, 'html' => $html ); 
  51.  
  52. public function admin_notices() { 
  53. foreach( $this->notices as $notice ) { 
  54. echo '<div class="notice ' . $notice['class'] . '">'; 
  55. echo $notice['html']; 
  56. echo '</div>'; 
  57. }  
  58.  
  59. // =========================================================================== 
  60. // END - ADMIN NOTICES 
  61. // =========================================================================== 
  62.  
  63. public function action_admin_menu() { 
  64. add_options_page( __( 'WooCommerce Extended Coupon Features', 'soft79-wc-pricing-rules' ), __( 'WooCommerce Extended Coupon Features', 'soft79-wc-pricing-rules' ), 'manage_options', 'wjecf_settings', array( &$this, 'action_admin_config_page' ) );  
  65.  
  66. public function action_admin_config_page() { 
  67. ?> 
  68. <h2><?php _e( 'WooCommerce Extended Coupon Features', 'soft79-wc-pricing-rules' ); ?></h2> 
  69. <form method="post" action="options.php">  
  70. <?php  
  71. settings_fields( 'wjecf_settings' ); 
  72. do_settings_sections( 'wjecf_settings' ); 
  73. ?> 
  74. <?php submit_button(); ?> 
  75. </form> 
  76. <h3><?php _e( 'Plugins', 'soft79-wc-pricing-rules' ); ?></h3> 
  77. <ul> 
  78. <?php 
  79. foreach ( WJECF()->get_plugins() as $name => $plugin ) { 
  80. echo "<li><h3>" . $plugin->get_plugin_class_name() . "</h3>\n"; 
  81. echo "<p>" . $plugin->get_plugin_description() . "</p>\n"; 
  82. echo "</li>\n"; 
  83. ?> 
  84. </ul> 
  85. <?php 
  86.  
  87. }  
  88.  
  89. //2.3.6 Inline css 
  90. private $admin_css = ''; 
  91.  
  92. /** 
  93. * 2.3.6 
  94. * @return void 
  95. */ 
  96. function on_admin_head() { 
  97. //Output inline style for the admin pages 
  98. if ( ! empty( $this->admin_css ) ) { 
  99. echo '<style type="text/css">' . $this->admin_css . '</style>'; 
  100. $this->admin_css = ''; 
  101.  
  102. //Enqueue scripts 
  103. wp_enqueue_script( "wjecf-admin", WJECF()->plugin_url . "assets/js/wjecf-admin.js", array( 'jquery' ), WJECF()->version ); 
  104. wp_localize_script( 'wjecf-admin', 'wjecf_admin_i18n', array( 
  105. 'label_and' => __( '(AND)', 'woocommerce-jos-autocoupon' ),  
  106. 'label_or' => __( '(OR)', 'woocommerce-jos-autocoupon' ) 
  107. ) ); 
  108.  
  109.  
  110.  
  111. //Add tabs to the coupon option page 
  112. public function admin_coupon_options_tabs( $tabs ) { 
  113.  
  114. $tabs['extended_features_products'] = array( 
  115. 'label' => __( 'Products', 'woocommerce-jos-autocoupon' ),  
  116. 'target' => 'wjecf_coupondata_products',  
  117. 'class' => 'wjecf_coupondata_products',  
  118. ); 
  119.  
  120. $tabs['extended_features_checkout'] = array( 
  121. 'label' => __( 'Checkout', 'woocommerce-jos-autocoupon' ),  
  122. 'target' => 'wjecf_coupondata_checkout',  
  123. 'class' => 'wjecf_coupondata_checkout',  
  124. ); 
  125.  
  126. $tabs['extended_features_misc'] = array( 
  127. 'label' => __( 'Miscellaneous', 'woocommerce-jos-autocoupon' ),  
  128. 'target' => 'wjecf_coupondata_misc',  
  129. 'class' => 'wjecf_coupondata_misc',  
  130. ); 
  131.  
  132. return $tabs; 
  133. }  
  134.  
  135. //Add panels to the coupon option page 
  136. public function admin_coupon_options_panels() { 
  137. global $thepostid, $post; 
  138. $thepostid = empty( $thepostid ) ? $post->ID : $thepostid; 
  139. ?> 
  140. <div id="wjecf_coupondata_products" class="panel woocommerce_options_panel"> 
  141. <?php 
  142. //Feed the panel with options 
  143. do_action( 'wjecf_coupon_metabox_products', $thepostid, $post ); 
  144. $this->admin_coupon_data_footer(); 
  145. ?> 
  146. </div> 
  147. <div id="wjecf_coupondata_checkout" class="panel woocommerce_options_panel"> 
  148. <?php 
  149. do_action( 'wjecf_coupon_metabox_checkout', $thepostid, $post ); 
  150. do_action( 'wjecf_coupon_metabox_customer', $thepostid, $post ); 
  151. $this->admin_coupon_data_footer(); 
  152. ?> 
  153. </div> 
  154. <div id="wjecf_coupondata_misc" class="panel woocommerce_options_panel"> 
  155. <?php 
  156. //Allow other classes to inject options 
  157. do_action( 'wjecf_woocommerce_coupon_options_extended_features', $thepostid, $post ); 
  158. do_action( 'wjecf_coupon_metabox_misc', $thepostid, $post ); 
  159. $this->admin_coupon_data_footer(); 
  160. ?> 
  161. </div> 
  162. <?php  
  163.  
  164. public function admin_coupon_data_footer() { 
  165. $documentation_url = plugins_url( 'docs/index.html', dirname( __FILE__ ) ); 
  166. if ( ! WJECF()->is_pro() ) { 
  167. $documentation_url = 'http://www.soft79.nl/documentation/wjecf'; 
  168. ?>  
  169. <h3><?php _e( 'Do you find WooCommerce Extended Coupon Features useful?', 'woocommerce-jos-autocoupon'); ?></h3> 
  170. <p class="form-field"><label for="wjecf_donate_button"><?php 
  171. echo esc_html( __('Express your gratitude', 'woocommerce-jos-autocoupon' ) );  
  172. ?></label> 
  173. <a id="wjecf_donate_button" href="<?php echo $this->get_donate_url(); ?>" target="_blank" class="button button-primary"> 
  174. <?php 
  175. echo esc_html( __('Donate to the developer', 'woocommerce-jos-autocoupon' ) );  
  176. ?></a><br> 
  177. Or get the PRO version at <a href="http://www.soft79.nl" target="_blank">www.soft79.nl</a>. 
  178. </p> 
  179. <?php 
  180. //Documentation link 
  181. echo '<h3>' . __( 'Documentation', 'woocommerce-jos-autocoupon' ) . '</h3>'; 
  182. echo '<p><a href="' . $documentation_url . '" target="_blank">' .  
  183. __( 'WooCommerce Extended Coupon Features Documentation', 'woocommerce-jos-autocoupon' ) . '</a></p>'; 
  184.  
  185.  
  186. //Tab 'extended features' 
  187. public function admin_coupon_metabox_products( $thepostid, $post ) { 
  188. //See WooCommerce class-wc-meta-box-coupon-data.php function ouput 
  189.  
  190. echo "<h3>" . esc_html( __( 'Matching products', 'woocommerce-jos-autocoupon' ) ). "</h3>\n"; 
  191. //============================= 
  192. // AND instead of OR the products 
  193. $this->render_select_with_default( array( 
  194. 'id' => '_wjecf_products_and',  
  195. 'label' => __( 'Products Operator', 'woocommerce-jos-autocoupon' ),  
  196. 'options' => array( 'no' => __( 'OR', 'woocommerce-jos-autocoupon' ), 'yes' => __( 'AND', 'woocommerce-jos-autocoupon' ) ),  
  197. 'default_value' => 'no',  
  198. 'class' => 'wjecf-not-wide',  
  199. /** translators: OLD TEXT: 'Check this box if ALL of the products (see tab \'usage restriction\') must be in the cart to use this coupon (instead of only one of the products).' */ 
  200. 'description' => __( 'Use AND if ALL of the products must be in the cart to use this coupon (instead of only one of the products).', 'woocommerce-jos-autocoupon' ),  
  201. 'desc_tip' => true 
  202. ) );  
  203.  
  204. //============================= 
  205. // 2.2.3.1 AND instead of OR the categories 
  206. $this->render_select_with_default( array( 
  207. 'id' => '_wjecf_categories_and',  
  208. 'label' => __( 'Categories Operator', 'woocommerce-jos-autocoupon' ),  
  209. 'options' => array( 'no' => __( 'OR', 'woocommerce-jos-autocoupon' ), 'yes' => __( 'AND', 'woocommerce-jos-autocoupon' ) ),  
  210. 'default_value' => 'no',  
  211. 'class' => 'wjecf-not-wide',  
  212. /** translators: OLD TEXT: 'Check this box if products from ALL of the categories (see tab \'usage restriction\') must be in the cart to use this coupon (instead of only one from one of the categories).' */ 
  213. 'description' => __( 'Use AND if products from ALL of the categories must be in the cart to use this coupon (instead of only one from one of the categories).', 'woocommerce-jos-autocoupon' ),  
  214. 'desc_tip' => true 
  215. ) );  
  216.  
  217.  
  218.  
  219. // Minimum quantity of matching products (product/category) 
  220. woocommerce_wp_text_input( array(  
  221. 'id' => '_wjecf_min_matching_product_qty',  
  222. 'label' => __( 'Minimum quantity of matching products', 'woocommerce-jos-autocoupon' ),  
  223. 'placeholder' => __( 'No minimum', 'woocommerce' ),  
  224. 'description' => __( 'Minimum quantity of the products that match the given product or category restrictions (see tab \'usage restriction\'). If no product or category restrictions are specified, the total number of products is used.', 'woocommerce-jos-autocoupon' ),  
  225. 'data_type' => 'decimal',  
  226. 'desc_tip' => true 
  227. ) ); 
  228.  
  229. // Maximum quantity of matching products (product/category) 
  230. woocommerce_wp_text_input( array(  
  231. 'id' => '_wjecf_max_matching_product_qty',  
  232. 'label' => __( 'Maximum quantity of matching products', 'woocommerce-jos-autocoupon' ),  
  233. 'placeholder' => __( 'No maximum', 'woocommerce' ),  
  234. 'description' => __( 'Maximum quantity of the products that match the given product or category restrictions (see tab \'usage restriction\'). If no product or category restrictions are specified, the total number of products is used.', 'woocommerce-jos-autocoupon' ),  
  235. 'data_type' => 'decimal',  
  236. 'desc_tip' => true 
  237. ) );  
  238.  
  239. // Minimum subtotal of matching products (product/category) 
  240. woocommerce_wp_text_input( array(  
  241. 'id' => '_wjecf_min_matching_product_subtotal',  
  242. 'label' => __( 'Minimum subtotal of matching products', 'woocommerce-jos-autocoupon' ),  
  243. 'placeholder' => __( 'No minimum', 'woocommerce' ),  
  244. 'description' => __( 'Minimum price subtotal of the products that match the given product or category restrictions (see tab \'usage restriction\').', 'woocommerce-jos-autocoupon' ),  
  245. 'data_type' => 'price',  
  246. 'desc_tip' => true 
  247. ) ); 
  248.  
  249. // Maximum subtotal of matching products (product/category) 
  250. woocommerce_wp_text_input( array(  
  251. 'id' => '_wjecf_max_matching_product_subtotal',  
  252. 'label' => __( 'Maximum subtotal of matching products', 'woocommerce-jos-autocoupon' ),  
  253. 'placeholder' => __( 'No maximum', 'woocommerce' ),  
  254. 'description' => __( 'Maximum price subtotal of the products that match the given product or category restrictions (see tab \'usage restriction\').', 'woocommerce-jos-autocoupon' ),  
  255. 'data_type' => 'price',  
  256. 'desc_tip' => true 
  257. ) ); 
  258.  
  259. public function admin_coupon_metabox_checkout( $thepostid, $post ) { 
  260.  
  261. echo "<h3>" . esc_html( __( 'Checkout', 'woocommerce-jos-autocoupon' ) ). "</h3>\n"; 
  262.  
  263. //============================= 
  264. // Shipping methods 
  265. ?> 
  266. <p class="form-field"><label for="wjecf_shipping_methods"><?php _e( 'Shipping methods', 'woocommerce-jos-autocoupon' ); ?></label> 
  267. <select id="wjecf_shipping_methods" name="wjecf_shipping_methods[]" style="width: 50%;" class="wc-enhanced-select" multiple="multiple" data-placeholder="<?php _e( 'Any shipping method', 'woocommerce-jos-autocoupon' ); ?>"> 
  268. <?php 
  269. $coupon_shipping_method_ids = WJECF()->get_coupon_shipping_method_ids( $thepostid ); 
  270. $shipping_methods = WC()->shipping->load_shipping_methods(); 
  271.  
  272. if ( $shipping_methods ) foreach ( $shipping_methods as $shipping_method ) { 
  273. echo '<option value="' . esc_attr( $shipping_method->id ) . '"' . selected( in_array( $shipping_method->id, $coupon_shipping_method_ids ), true, false ) . '>' . esc_html( $shipping_method->method_title ) . '</option>'; 
  274. ?> 
  275. </select><?php echo WJECF_WC()->wc_help_tip( __( 'One of these shipping methods must be selected in order for this coupon to be valid.', 'woocommerce-jos-autocoupon' ) ); ?> 
  276. </p> 
  277. <?php  
  278.  
  279. //============================= 
  280. // Payment methods 
  281. ?> 
  282. <p class="form-field"><label for="wjecf_payment_methods"><?php _e( 'Payment methods', 'woocommerce-jos-autocoupon' ); ?></label> 
  283. <select id="wjecf_payment_methods" name="wjecf_payment_methods[]" style="width: 50%;" class="wc-enhanced-select" multiple="multiple" data-placeholder="<?php _e( 'Any payment method', 'woocommerce-jos-autocoupon' ); ?>"> 
  284. <?php 
  285. $coupon_payment_method_ids = WJECF()->get_coupon_payment_method_ids( $thepostid ); 
  286. //DONT USE WC()->payment_gateways->available_payment_gateways() AS IT CAN CRASH IN UNKNOWN OCCASIONS 
  287. $payment_methods = WC()->payment_gateways->payment_gateways(); 
  288. if ( $payment_methods ) foreach ( $payment_methods as $payment_method ) { 
  289. if ('yes' === $payment_method->enabled) { 
  290. echo '<option value="' . esc_attr( $payment_method->id ) . '"' . selected( in_array( $payment_method->id, $coupon_payment_method_ids ), true, false ) . '>' . esc_html( $payment_method->title ) . '</option>'; 
  291. ?> 
  292. </select><?php echo WJECF_WC()->wc_help_tip( __( 'One of these payment methods must be selected in order for this coupon to be valid.', 'woocommerce-jos-autocoupon' ) ); ?> 
  293. </p> 
  294. <?php  
  295.  
  296. public function admin_coupon_metabox_customer( $thepostid, $post ) { 
  297.  
  298. //============================= 
  299. //Title: "CUSTOMER RESTRICTIONS" 
  300. echo "<h3>" . esc_html( __( 'Customer restrictions', 'woocommerce-jos-autocoupon' ) ). "</h3>\n"; 
  301. echo "<p><span class='description'>" . __( 'If both a customer and a role restriction are supplied, matching either one of them will suffice.' , 'woocommerce-jos-autocoupon' ) . "</span></p>\n"; 
  302.  
  303. //============================= 
  304. // User ids 
  305. ?> 
  306. <p class="form-field"><label><?php _e( 'Allowed Customers', 'woocommerce-jos-autocoupon' ); ?></label> 
  307. <?php 
  308. $coupon_customer_ids = WJECF()->get_coupon_customer_ids( $thepostid ); 
  309. WJECF_WC()->render_admin_customer_selector( 'wjecf_customer_ids', 'wjecf_customer_ids', $coupon_customer_ids ); 
  310. echo WJECF_WC()->wc_help_tip( __( 'Only these customers may use this coupon.', 'woocommerce-jos-autocoupon' ) ); 
  311. ?> 
  312. </p> 
  313. <?php 
  314.  
  315. //============================= 
  316. // User roles 
  317. ?> 
  318. <p class="form-field"><label for="wjecf_customer_roles"><?php _e( 'Allowed User Roles', 'woocommerce-jos-autocoupon' ); ?></label> 
  319. <select id="wjecf_customer_roles" name="wjecf_customer_roles[]" style="width: 50%;" class="wc-enhanced-select" multiple="multiple" data-placeholder="<?php _e( 'Any role', 'woocommerce-jos-autocoupon' ); ?>"> 
  320. <?php  
  321. $coupon_customer_roles = WJECF()->get_coupon_customer_roles( $thepostid ); 
  322.  
  323. $available_customer_roles = array_reverse( get_editable_roles() ); 
  324. foreach ( $available_customer_roles as $role_id => $role ) { 
  325. $role_name = translate_user_role($role['name'] ); 
  326.  
  327. echo '<option value="' . esc_attr( $role_id ) . '"' 
  328. . selected( in_array( $role_id, $coupon_customer_roles ), true, false ) . '>' 
  329. . esc_html( $role_name ) . '</option>'; 
  330. ?> 
  331. </select> 
  332. <?php echo WJECF_WC()->wc_help_tip( __( 'Only these User Roles may use this coupon.', 'woocommerce-jos-autocoupon' ) ); ?> 
  333. </p> 
  334. <?php  
  335.  
  336. //============================= 
  337. // Excluded user roles 
  338. ?> 
  339. <p class="form-field"><label for="wjecf_excluded_customer_roles"><?php _e( 'Disallowed User Roles', 'woocommerce-jos-autocoupon' ); ?></label> 
  340. <select id="wjecf_customer_roles" name="wjecf_excluded_customer_roles[]" style="width: 50%;" class="wc-enhanced-select" multiple="multiple" data-placeholder="<?php _e( 'Any role', 'woocommerce-jos-autocoupon' ); ?>"> 
  341. <?php  
  342. $coupon_excluded_customer_roles = WJECF()->get_coupon_excluded_customer_roles( $thepostid ); 
  343.  
  344. foreach ( $available_customer_roles as $role_id => $role ) { 
  345. $role_name = translate_user_role($role['name'] ); 
  346.  
  347. echo '<option value="' . esc_attr( $role_id ) . '"' 
  348. . selected( in_array( $role_id, $coupon_excluded_customer_roles ), true, false ) . '>' 
  349. . esc_html( $role_name ) . '</option>'; 
  350. ?> 
  351. </select> 
  352. <?php echo WJECF_WC()->wc_help_tip( __( 'These User Roles will be specifically excluded from using this coupon.', 'woocommerce-jos-autocoupon' ) ); ?> 
  353. </p> 
  354. <?php  
  355.  
  356. public function admin_coupon_metabox_misc( $thepostid, $post ) { 
  357. echo "<h3>" . esc_html( __( 'Miscellaneous', 'woocommerce-jos-autocoupon' ) ). "</h3>\n"; 
  358. //============================= 
  359. //2.2.2 Allow if minimum spend not met 
  360. woocommerce_wp_checkbox( array( 
  361. 'id' => '_wjecf_allow_below_minimum_spend',  
  362. 'label' => __( 'Allow when minimum spend not reached', 'woocommerce-jos-autocoupon' ),  
  363. 'description' => '<b>' . __( 'EXPERIMENTAL: ', 'woocommerce-jos-autocoupon' ) . '</b>' . __( 'Check this box to allow the coupon to be in the cart even when minimum spend (see tab \'usage restriction\') is not reached. Value of the discount will be 0 until minimum spend is reached.', 'woocommerce-jos-autocoupon' ),  
  364. ) ); 
  365.  
  366. public function process_shop_coupon_meta( $post_id, $post ) { 
  367. $wrap_coupon = WJECF_Wrap( $post_id ); 
  368.  
  369. $wjecf_min_matching_product_qty = isset( $_POST['_wjecf_min_matching_product_qty'] ) ? $_POST['_wjecf_min_matching_product_qty'] : ''; 
  370. $wrap_coupon->set_meta( '_wjecf_min_matching_product_qty', $wjecf_min_matching_product_qty ); 
  371.  
  372. $wjecf_max_matching_product_qty = isset( $_POST['_wjecf_max_matching_product_qty'] ) ? $_POST['_wjecf_max_matching_product_qty'] : ''; 
  373. $wrap_coupon->set_meta( '_wjecf_max_matching_product_qty', $wjecf_max_matching_product_qty ); 
  374.  
  375. //2.2.2 
  376. $wjecf_min_matching_product_subtotal = isset( $_POST['_wjecf_min_matching_product_subtotal'] ) ? $_POST['_wjecf_min_matching_product_subtotal'] : ''; 
  377. $wrap_coupon->set_meta( '_wjecf_min_matching_product_subtotal', $wjecf_min_matching_product_subtotal ); 
  378.  
  379. $wjecf_max_matching_product_subtotal = isset( $_POST['_wjecf_max_matching_product_subtotal'] ) ? $_POST['_wjecf_max_matching_product_subtotal'] : ''; 
  380. $wrap_coupon->set_meta( '_wjecf_max_matching_product_subtotal', $wjecf_max_matching_product_subtotal ); 
  381.  
  382. $wjecf_products_and = $_POST['_wjecf_products_and'] == 'yes' ? 'yes' : 'no'; 
  383. $wrap_coupon->set_meta( '_wjecf_products_and', $wjecf_products_and ); 
  384.  
  385. //2.2.3.1 
  386. $wjecf_categories_and = $_POST['_wjecf_categories_and'] == 'yes' ? 'yes' : 'no'; 
  387. $wrap_coupon->set_meta( '_wjecf_categories_and', $wjecf_categories_and ); 
  388.  
  389. //2.2.2 
  390. $wjecf_allow_below_minimum_spend = isset( $_POST['_wjecf_allow_below_minimum_spend'] ) ? 'yes' : 'no'; 
  391. $wrap_coupon->set_meta( '_wjecf_allow_below_minimum_spend', $wjecf_allow_below_minimum_spend ); 
  392.  
  393. $wjecf_shipping_methods = isset( $_POST['wjecf_shipping_methods'] ) ? $_POST['wjecf_shipping_methods'] : ''; 
  394. $wrap_coupon->set_meta( '_wjecf_shipping_methods', $wjecf_shipping_methods );  
  395.  
  396. $wjecf_payment_methods = isset( $_POST['wjecf_payment_methods'] ) ? $_POST['wjecf_payment_methods'] : ''; 
  397. $wrap_coupon->set_meta( '_wjecf_payment_methods', $wjecf_payment_methods );  
  398.  
  399. $wjecf_customer_ids = $this->comma_separated_int_array( $_POST['wjecf_customer_ids'] ); 
  400. $wrap_coupon->set_meta( '_wjecf_customer_ids', $wjecf_customer_ids ); 
  401.  
  402. $wjecf_customer_roles = isset( $_POST['wjecf_customer_roles'] ) ? $_POST['wjecf_customer_roles'] : ''; 
  403. $wrap_coupon->set_meta( '_wjecf_customer_roles', $wjecf_customer_roles );  
  404.  
  405. $wjecf_excluded_customer_roles = isset( $_POST['wjecf_excluded_customer_roles'] ) ? $_POST['wjecf_excluded_customer_roles'] : ''; 
  406. $wrap_coupon->set_meta( '_wjecf_excluded_customer_roles', $wjecf_excluded_customer_roles );  
  407.  
  408. $wrap_coupon->save(); 
  409.  
  410. /** 
  411. * 2.3.6 
  412. * Add inline style (css) to the admin page. Must be called BEFORE admin_head ! 
  413. * @param string $css  
  414. * @return void 
  415. */ 
  416. public function add_inline_style( $css ) { 
  417. $this->admin_css .= $css; 
  418.  
  419.  
  420. /** 
  421. * 2.3.4 
  422. * Parse an array or comma separated string; make sure they are valid ints and return as comma separated string 
  423. * @param array|string $int_array  
  424. * @return string comma separated int array 
  425. */ 
  426. public function comma_separated_int_array( $int_array ) { 
  427. //Source can be a comma separated string (select2) , or an int array (chosen) 
  428. if ( ! is_array( $int_array) ) { 
  429. $int_array = explode( ', ', $int_array ); 
  430. return implode( ', ', array_filter( array_map( 'intval', $int_array ) ) ); 
  431.  
  432. /** 
  433. * 2.3.6 
  434. * Renders a <SELECT> that has a default value. Relies on woocommerce_wp_select 
  435. *  
  436. * field['default_value']: The default value (if omitted the first option will be default) 
  437. * field['append_default_label']: If true or omitted the text '(DEFAULT)' will be appended to the default option caption 
  438. *  
  439. * @param array $field see wc-meta-box-functions.php:woocommerce_wp_select 
  440. * @return void 
  441. */ 
  442. public function render_select_with_default( $field ) { 
  443. global $thepostid, $post; 
  444. $thepostid = empty( $thepostid ) ? $post->ID : $thepostid; 
  445.  
  446. reset( $field['options'] ); //move to first for key() 
  447. $default_value = isset( $field['default_value'] ) ? $field['default_value'] : key( $field['options'] ); 
  448. $append_default_label = isset( $field['append_default_label'] ) ? $field['append_default_label'] : true; 
  449.  
  450. if ( $append_default_label ) { 
  451. $field['options'][$default_value] = sprintf( __( '%s (Default)', 'woocommerce-jos-autocoupon' ), $field['options'][$default_value] ); 
  452.  
  453. if ( ! isset( $field['value'] ) ) { 
  454. $field['value'] = get_post_meta( $thepostid, $field['id'], true ); 
  455. if ( empty( $field['value'] ) ) { 
  456. $field['value'] = $default_value; 
  457.  
  458. woocommerce_wp_select( $field ); 
  459.  
  460. public function render_admin_cat_selector( $dom_id, $field_name, $selected_ids, $placeholder = null ) { 
  461. if ( $placeholder === null ) $placeholder = __( 'Search for a product*', 'woocommerce' ); 
  462.  
  463. // Categories 
  464. ?>  
  465. <select id="<?php esc_attr_e( $dom_id ) ?>" name="<?php esc_attr_e( $field_name ) ?>[]" style="width: 50%;" class="wc-enhanced-select" multiple="multiple" data-placeholder="<?php esc_attr_e( $placeholder ); ?>"> 
  466. <?php 
  467. $categories = get_terms( 'product_cat', 'orderby=name&hide_empty=0' ); 
  468.  
  469. if ( $categories ) foreach ( $categories as $cat ) { 
  470. echo '<option value="' . esc_attr( $cat->term_id ) . '"' . selected( in_array( $cat->term_id, $selected_ids ), true, false ) . '>' . esc_html( $cat->name ) . '</option>'; 
  471. ?> 
  472. </select> 
  473. <?php  
  474.  
  475. /** 
  476. * Add donate-link to plugin page 
  477. */ 
  478. function wjecf_plugin_meta( $links, $file ) { 
  479. if ( strpos( $file, 'woocommerce-jos-autocoupon.php' ) !== false ) { 
  480. $links = array_merge( $links, array( '<a href="' . WJECF_Admin::get_donate_url() . '" title="Support the development" target="_blank">Donate</a>' ) ); 
  481. return $links; 
  482.  
  483.  
  484. public static function get_donate_url() { 
  485. return "https://www.paypal.com/cgi-bin/webscr?cmd=_donations&business=5T9XQBCS2QHRY&lc=NL&item_name=Jos%20Koenis&item_number=wordpress%2dplugin¤cy_code=EUR&bn=PP%2dDonationsBF%3abtn_donateCC_LG%2egif%3aNonHosted";