MG_Woo_Extra_Options

Main Loader Class Used to extend WooCommerce settings.

Defined (1)

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. add_action('init', array($this, 'autocompleteOrders'), 0); 
  26.  
  27.  
  28. /** 
  29. * woocommerce_settings_tabs_array  
  30. * Used to add a WooCommerce settings tab 
  31. * @param array $settings_tabs 
  32. * @return array 
  33. */ 
  34. function woocommerce_settings_tabs_array( $settings_tabs ) { 
  35. $settings_tabs[$this->id] = __('Woo Extra Options', 'wooExtraOptions'); 
  36. return $settings_tabs; 
  37.  
  38. /** 
  39. * show_settings_tab 
  40. * Used to display the WooCommerce settings tab content 
  41. * @return void 
  42. */ 
  43. function show_settings_tab() { 
  44. woocommerce_admin_fields($this->get_settings()); 
  45.  
  46. /** 
  47. * update_settings_tab 
  48. * Used to save the WooCommerce settings tab values 
  49. * @return void 
  50. */ 
  51. function update_settings_tab() { 
  52. woocommerce_update_options($this->get_settings()); 
  53.  
  54. /** 
  55. * get_settings 
  56. * Used to define the WooCommerce settings tab fields 
  57. * @return void 
  58. */ 
  59. function get_settings() { 
  60. $settings = array( 
  61. 'section_title' => array( 
  62. 'name' => __('Autocomplete Orders', 'wooExtraOptions'),  
  63. 'type' => 'title',  
  64. 'desc' => '',  
  65. 'id' => 'wc_'.$this->id.'_section_title' 
  66. ),  
  67. 'title' => array( 
  68. 'name' => __('Mode', 'wooExtraOptions'),  
  69. 'type' => 'select',  
  70. 'desc' => __('Select the type of autocompletion you want to activate.', 'wooExtraOptions'),  
  71. 'desc_tip' => true,  
  72. 'default' => 'off',  
  73. 'id' => 'wc_'.$this->id.'_mode',  
  74. 'options' => array( 
  75. 'off' => 'Off',  
  76. 'virtual' => 'Paid virtual products',  
  77. 'paid' => 'All paid products',  
  78. 'all' => 'All products' 
  79. ),  
  80. 'section_end' => array( 
  81. 'type' => 'sectionend',  
  82. 'id' => 'wc_'.$this->id.'_section_end' 
  83. ); 
  84. return apply_filters( 'wc_'.$this->id.'_settings', $settings ); 
  85.  
  86. /** 
  87. * autocompleteOrders  
  88. * Autocomplete Orders 
  89. * @return void 
  90. */ 
  91. function autocompleteOrders() 
  92. $mode = get_option('wc_'.$this->id.'_mode'); 
  93. if ($mode == 'all') { 
  94. add_action('woocommerce_thankyou', 'autocompleteAllOrders'); 
  95. /** 
  96. * autocompleteAllOrders  
  97. * Register custom tabs Post Type 
  98. * @return void 
  99. */ 
  100. function autocompleteAllOrders($order_id) 
  101. global $woocommerce; 
  102.  
  103. if (!$order_id) 
  104. return; 
  105. $order = new WC_Order($order_id); 
  106. $order->update_status('completed'); 
  107. } elseif ($mode == 'paid') { 
  108. add_filter('woocommerce_payment_complete_order_status', 'autocompletePaidOrders', 10, 2); 
  109. /** 
  110. * autocompletePaidOrders  
  111. * Register custom tabs Post Type 
  112. * @return void 
  113. */ 
  114. function autocompletePaidOrders($order_status, $order_id) 
  115. $order = new WC_Order($order_id); 
  116. if ($order_status == 'processing' && ($order->status == 'on-hold' || $order->status == 'pending' || $order->status == 'failed')) { 
  117. return 'completed'; 
  118. return $order_status; 
  119. } elseif ($mode == 'virtual') { 
  120. add_filter('woocommerce_payment_complete_order_status', 'autocompleteVirtualOrders', 10, 2); 
  121. /** 
  122. * autocompleteVirtualOrders  
  123. * Register custom tabs Post Type 
  124. * @return void 
  125. */ 
  126. function autocompleteVirtualOrders($order_status, $order_id) 
  127. $order = new WC_Order($order_id); 
  128. if ('processing' == $order_status && ('on-hold' == $order->status || 'pending' == $order->status || 'failed' == $order->status)) { 
  129. $virtual_order = null; 
  130. if (count($order->get_items()) > 0 ) { 
  131. foreach ($order->get_items() as $item) { 
  132. if ('line_item' == $item['type']) { 
  133. $_product = $order->get_product_from_item($item); 
  134. if (!$_product->is_virtual()) { 
  135. $virtual_order = false; 
  136. break; 
  137. } else { 
  138. $virtual_order = true; 
  139. if ($virtual_order) { 
  140. return 'completed'; 
  141. return $order_status; 
  142. }//end MG_Woo_Extra_Options class.