MG_Woo_Extra_Options

Main Loader Class Used to extend WooCommerce settings.

Defined (2)

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

/woocommerce-autocomplete-order.php  
  1. class MG_Woo_Extra_Options 
  2. /** 
  3. * $id  
  4. * holds settings tab id 
  5. * @var string 
  6. */ 
  7. public $id = 'mg_woo_eo'; 
  8.  
  9. /** 
  10. * __construct 
  11. * class constructor will set the needed filter and action hooks 
  12. */ 
  13. function __construct() 
  14. if (is_admin()) { 
  15. //add settings tab 
  16. add_filter('woocommerce_settings_tabs_array', array($this, 'woocommerce_settings_tabs_array'), 50); 
  17. //show settings tab 
  18. add_action('woocommerce_settings_tabs_'.$this->id, array($this, 'show_settings_tab')); 
  19. //save settings tab  
  20. add_action('woocommerce_update_options_'.$this->id, array($this, 'update_settings_tab')); 
  21. //add tabs select field 
  22. add_action('woocommerce_admin_field_'.$this->id, array($this, 'show_'.$this->id.'_field'), 10); 
  23. //save tabs select field 
  24. add_action('woocommerce_update_option_'.$this->id, array($this, 'save_'.$this->id.'_field'), 10); 
  25. //ajax search handler 
  26. //add_action('wp_ajax_woocommerce_json_custom_tabs', array($this, 'woocommerce_json_custom_tabs')); 
  27. //register_post_type 
  28. add_action('init', array($this, 'autocompleteOrders'), 0); 
  29.  
  30. function mgWooeoNotice() 
  31. global $current_user; 
  32. $user_id = $current_user->ID; 
  33. if (!get_user_meta($user_id, 'mg_ignore_notice')) { 
  34. echo '<div class="updated"><p>'; 
  35. printf(__('This is an annoying nag message. | <a href="%1$s">Hide Notice</a>'), '?mgWooeoNoticeIgnore=0'); 
  36. echo "</p></div>"; 
  37.  
  38. function mgWooeoNoticeIgnore() { 
  39. global $current_user; 
  40. $user_id = $current_user->ID; 
  41. if (isset($_GET['mgWooeoNoticeIgnore']) && '0' == $_GET['mgWooeoNoticeIgnore']) { 
  42. add_user_meta($user_id, 'mg_ignore_notice', 'true', true); 
  43. //add_action('admin_notices', 'mgWooeoNotice'); 
  44. //add_action('admin_init', 'mgWooeoNoticeIgnore'); 
  45.  
  46. /** 
  47. * woocommerce_settings_tabs_array  
  48. * Used to add a WooCommerce settings tab 
  49. * @param array $settings_tabs 
  50. * @return array 
  51. */ 
  52. function woocommerce_settings_tabs_array( $settings_tabs ) { 
  53. $settings_tabs[$this->id] = __('Woo Extra Options', 'wooExtraOptions'); 
  54. return $settings_tabs; 
  55.  
  56. /** 
  57. * show_settings_tab 
  58. * Used to display the WooCommerce settings tab content 
  59. * @return void 
  60. */ 
  61. function show_settings_tab() { 
  62. woocommerce_admin_fields($this->get_settings()); 
  63.  
  64. /** 
  65. * update_settings_tab 
  66. * Used to save the WooCommerce settings tab values 
  67. * @return void 
  68. */ 
  69. function update_settings_tab() { 
  70. woocommerce_update_options($this->get_settings()); 
  71.  
  72. /** 
  73. * get_settings 
  74. * Used to define the WooCommerce settings tab fields 
  75. * @return void 
  76. */ 
  77. function get_settings() { 
  78. $settings = array( 
  79. 'section_title' => array( 
  80. 'name' => __('Autocomplete Orders', 'wooExtraOptions'),  
  81. 'type' => 'title',  
  82. 'desc' => '',  
  83. 'id' => 'wc_'.$this->id.'_section_title' 
  84. ),  
  85. 'title' => array( 
  86. 'name' => __('Mode', 'wooExtraOptions'),  
  87. 'type' => 'select',  
  88. 'desc' => __('Select the type of autocompletion you want to activate.', 'wooExtraOptions'),  
  89. 'desc_tip' => true,  
  90. 'default' => 'off',  
  91. 'id' => 'wc_'.$this->id.'_mode',  
  92. 'options' => array( 
  93. 'off' => 'Off',  
  94. 'virtual' => 'Paid virtual products',  
  95. 'paid' => 'All paid products',  
  96. 'all' => 'All products' 
  97. ),  
  98. 'section_end' => array( 
  99. 'type' => 'sectionend',  
  100. 'id' => 'wc_'.$this->id.'_section_end' 
  101. ); 
  102. return apply_filters( 'wc_'.$this->id.'_settings', $settings ); 
  103.  
  104. /** 
  105. * autocompleteOrders  
  106. * Autocomplete Orders 
  107. * @return void 
  108. */ 
  109. function autocompleteOrders() 
  110. $mode = get_option('wc_'.$this->id.'_mode'); 
  111. if ($mode == 'all') { 
  112. add_action('woocommerce_thankyou', 'autocompleteAllOrders'); 
  113. /** 
  114. * autocompleteAllOrders  
  115. * Register custom tabs Post Type 
  116. * @return void 
  117. */ 
  118. function autocompleteAllOrders($order_id) 
  119. global $woocommerce; 
  120.  
  121. if (!$order_id) 
  122. return; 
  123. $order = new WC_Order($order_id); 
  124. $order->update_status('completed'); 
  125. } elseif ($mode == 'paid') { 
  126. add_filter('woocommerce_payment_complete_order_status', 'autocompletePaidOrders', 10, 2); 
  127. /** 
  128. * autocompletePaidOrders  
  129. * Register custom tabs Post Type 
  130. * @return void 
  131. */ 
  132. function autocompletePaidOrders($order_status, $order_id) 
  133. $order = new WC_Order($order_id); 
  134. if ($order_status == 'processing' && ($order->status == 'on-hold' || $order->status == 'pending' || $order->status == 'failed')) { 
  135. return 'completed'; 
  136. return $order_status; 
  137. } elseif ($mode == 'virtual') { 
  138. add_filter('woocommerce_payment_complete_order_status', 'autocompleteVirtualOrders', 10, 2); 
  139. /** 
  140. * autocompleteVirtualOrders  
  141. * Register custom tabs Post Type 
  142. * @return void 
  143. */ 
  144. function autocompleteVirtualOrders($order_status, $order_id) 
  145. $order = new WC_Order($order_id); 
  146. if ('processing' == $order_status && ('on-hold' == $order->status || 'pending' == $order->status || 'failed' == $order->status)) { 
  147. $virtual_order = null; 
  148. if (count($order->get_items()) > 0 ) { 
  149. foreach ($order->get_items() as $item) { 
  150. if ('line_item' == $item['type']) { 
  151. $_product = $order->get_product_from_item($item); 
  152. if (!$_product->is_virtual()) { 
  153. $virtual_order = false; 
  154. break; 
  155. } else { 
  156. $virtual_order = true; 
  157. if ($virtual_order) { 
  158. return 'completed'; 
  159. return $order_status; 
  160. }//end MG_Woo_Extra_Options class. 
  1. class MG_Woo_Extra_Options 
  2. /** 
  3. * $id  
  4. * holds settings tab id 
  5. * @var string 
  6. */ 
  7. public $id = 'mg_woo_eo'; 
  8.  
  9. /** 
  10. * __construct 
  11. * class constructor will set the needed filter and action hooks 
  12. */ 
  13. function __construct() 
  14. if (is_admin()) { 
  15. //add settings tab 
  16. add_filter('woocommerce_settings_tabs_array', array($this, 'woocommerce_settings_tabs_array'), 50); 
  17. //show settings tab 
  18. add_action('woocommerce_settings_tabs_'.$this->id, array($this, 'show_settings_tab')); 
  19. //save settings tab  
  20. add_action('woocommerce_update_options_'.$this->id, array($this, 'update_settings_tab')); 
  21. //add tabs select field 
  22. add_action('woocommerce_admin_field_'.$this->id, array($this, 'show_'.$this->id.'_field'), 10); 
  23. //save tabs select field 
  24. add_action('woocommerce_update_option_'.$this->id, array($this, 'save_'.$this->id.'_field'), 10); 
  25. //ajax search handler 
  26. //add_action('wp_ajax_woocommerce_json_custom_tabs', array($this, 'woocommerce_json_custom_tabs')); 
  27. //register_post_type 
  28. add_action('init', array($this, 'autocompleteOrders'), 0); 
  29.  
  30. function mgWooeoNotice() 
  31. global $current_user; 
  32. $user_id = $current_user->ID; 
  33. if (!get_user_meta($user_id, 'mg_ignore_notice')) { 
  34. echo '<div class="updated"><p>'; 
  35. printf(__('This is an annoying nag message. | <a href="%1$s">Hide Notice</a>'), '?mgWooeoNoticeIgnore=0'); 
  36. echo "</p></div>"; 
  37.  
  38. function mgWooeoNoticeIgnore() { 
  39. global $current_user; 
  40. $user_id = $current_user->ID; 
  41. if (isset($_GET['mgWooeoNoticeIgnore']) && '0' == $_GET['mgWooeoNoticeIgnore']) { 
  42. add_user_meta($user_id, 'mg_ignore_notice', 'true', true); 
  43. //add_action('admin_notices', 'mgWooeoNotice'); 
  44. //add_action('admin_init', 'mgWooeoNoticeIgnore'); 
  45.  
  46. /** 
  47. * woocommerce_settings_tabs_array  
  48. * Used to add a WooCommerce settings tab 
  49. * @param array $settings_tabs 
  50. * @return array 
  51. */ 
  52. function woocommerce_settings_tabs_array( $settings_tabs ) { 
  53. $settings_tabs[$this->id] = __('Woo Extra Options', 'wooExtraOptions'); 
  54. return $settings_tabs; 
  55.  
  56. /** 
  57. * show_settings_tab 
  58. * Used to display the WooCommerce settings tab content 
  59. * @return void 
  60. */ 
  61. function show_settings_tab() { 
  62. woocommerce_admin_fields($this->get_settings()); 
  63.  
  64. /** 
  65. * update_settings_tab 
  66. * Used to save the WooCommerce settings tab values 
  67. * @return void 
  68. */ 
  69. function update_settings_tab() { 
  70. woocommerce_update_options($this->get_settings()); 
  71.  
  72. /** 
  73. * get_settings 
  74. * Used to define the WooCommerce settings tab fields 
  75. * @return void 
  76. */ 
  77. function get_settings() { 
  78. $settings = array( 
  79. 'section_title' => array( 
  80. 'name' => __('Autocomplete Orders', 'wooExtraOptions'),  
  81. 'type' => 'title',  
  82. 'desc' => '',  
  83. 'id' => 'wc_'.$this->id.'_section_title' 
  84. ),  
  85. 'title' => array( 
  86. 'name' => __('Mode', 'wooExtraOptions'),  
  87. 'type' => 'select',  
  88. 'desc' => __('Select the type of autocompletion you want to activate.', 'wooExtraOptions'),  
  89. 'desc_tip' => true,  
  90. 'default' => 'off',  
  91. 'id' => 'wc_'.$this->id.'_mode',  
  92. 'options' => array( 
  93. 'off' => 'Off',  
  94. 'virtual' => 'Paid virtual products',  
  95. 'paid' => 'All paid products',  
  96. 'all' => 'All products' 
  97. ),  
  98. 'section_end' => array( 
  99. 'type' => 'sectionend',  
  100. 'id' => 'wc_'.$this->id.'_section_end' 
  101. ); 
  102. return apply_filters( 'wc_'.$this->id.'_settings', $settings ); 
  103.  
  104. /** 
  105. * autocompleteOrders  
  106. * Autocomplete Orders 
  107. * @return void 
  108. */ 
  109. function autocompleteOrders() 
  110. $mode = get_option('wc_'.$this->id.'_mode'); 
  111. if ($mode == 'all') { 
  112. add_action('woocommerce_thankyou', 'autocompleteAllOrders'); 
  113. /** 
  114. * autocompleteAllOrders  
  115. * Register custom tabs Post Type 
  116. * @return void 
  117. */ 
  118. function autocompleteAllOrders($order_id) 
  119. global $woocommerce; 
  120.  
  121. if (!$order_id) 
  122. return; 
  123. $order = new WC_Order($order_id); 
  124. $order->update_status('completed'); 
  125. } elseif ($mode == 'paid') { 
  126. add_filter('woocommerce_payment_complete_order_status', 'autocompletePaidOrders', 10, 2); 
  127. /** 
  128. * autocompletePaidOrders  
  129. * Register custom tabs Post Type 
  130. * @return void 
  131. */ 
  132. function autocompletePaidOrders($order_status, $order_id) 
  133. $order = new WC_Order($order_id); 
  134. if ($order_status == 'processing' && ($order->status == 'on-hold' || $order->status == 'pending' || $order->status == 'failed')) { 
  135. return 'completed'; 
  136. return $order_status; 
  137. } elseif ($mode == 'virtual') { 
  138. add_filter('woocommerce_payment_complete_order_status', 'autocompleteVirtualOrders', 10, 2); 
  139. /** 
  140. * autocompleteVirtualOrders  
  141. * Register custom tabs Post Type 
  142. * @return void 
  143. */ 
  144. function autocompleteVirtualOrders($order_status, $order_id) 
  145. $order = new WC_Order($order_id); 
  146. if ('processing' == $order_status && ('on-hold' == $order->status || 'pending' == $order->status || 'failed' == $order->status)) { 
  147. $virtual_order = null; 
  148. if (count($order->get_items()) > 0 ) { 
  149. foreach ($order->get_items() as $item) { 
  150. if ('line_item' == $item['type']) { 
  151. $_product = $order->get_product_from_item($item); 
  152. if (!$_product->is_virtual()) { 
  153. $virtual_order = false; 
  154. break; 
  155. } else { 
  156. $virtual_order = true; 
  157. if ($virtual_order) { 
  158. return 'completed'; 
  159. return $order_status; 
  160. }//end MG_Woo_Extra_Options class.