Changeset 2288263
- Timestamp:
- 04/21/2020 11:05:12 AM (4 years ago)
- Location:
- autocomplete-woocommerce-orders
- Files:
-
- 6 added
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
autocomplete-woocommerce-orders/trunk/includes/class-aco.php
r1772218 r2288263 9 9 */ 10 10 11 if ( ! defined( 'ABSPATH' )) {12 11 if () { 12 exit; // Exit if accessed directly. 13 13 } 14 14 … … 17 17 * 18 18 * @class ACO 19 * @version 19 * @version1.0.0 20 20 */ 21 final class ACO { 21 final class ACO 22 { 22 23 23 24 25 26 27 28 29 24 /** 25 * The single instance of the class. 26 * 27 * @var ACO 28 * @since 1.0 29 */ 30 protected static $_instance = null; 30 31 31 /** 32 * Main ACO Instance. 33 * 34 * Ensures only one instance of ACO is loaded or can be loaded. 35 * 36 * @since 1.0 37 * @static 38 * @see ACO() 39 * @return ACO - Main instance. 40 */ 41 public static function instance() { 42 if ( is_null( self::$_instance ) ) { 43 self::$_instance = new self(); 44 } 45 return self::$_instance; 46 } 32 /** 33 * Main ACO Instance. 34 * 35 * Ensures only one instance of ACO is loaded or can be loaded. 36 * 37 * @return ACO - Main instance. 38 * @see ACO() 39 * @since 1.0 40 * @static 41 */ 42 public static function instance() 43 { 44 if (is_null(self::$_instance)) { 45 self::$_instance = new self(); 46 } 47 return self::$_instance; 48 } 47 49 48 /** 49 * Cloning is forbidden. 50 * 51 * @since 1.0 52 */ 53 public function __clone() { 54 wc_doing_it_wrong( __FUNCTION__, __( 'Cheatin’ huh?', 'aco' ), '1.1' ); 55 } 50 /** 51 * Cloning is forbidden. 52 * 53 * @since 1.0 54 */ 55 public function __clone() 56 { 57 wc_doing_it_wrong(__FUNCTION__, __('Cheatin’ huh?', 'aco'), '1.1'); 58 } 56 59 57 /** 58 * Unserializing instances of this class is forbidden. 59 * 60 * @since 1.0 61 */ 62 public function __wakeup() { 63 wc_doing_it_wrong( __FUNCTION__, __( 'Cheatin’ huh?', 'aco' ), '2.1' ); 64 } 60 /** 61 * Unserializing instances of this class is forbidden. 62 * 63 * @since 1.0 64 */ 65 public function __wakeup() 66 { 67 wc_doing_it_wrong(__FUNCTION__, __('Cheatin’ huh?', 'aco'), '2.1'); 68 } 65 69 66 /** 67 * Include required core files used in admin and on the frontend. 68 */ 69 public function includes() { 70 /** 71 * Include required core files used in admin and on the frontend. 72 */ 73 public function includes() 74 { 70 75 71 72 73 74 include_once dirname( __FILE__) . '/class-admin.php';76 /** 77 * Interfaces. 78 */ 79 ) . '/class-admin.php'; 75 80 76 81 } 77 82 78 /** 79 * ACO Constructor. 80 */ 81 public function __construct() { 82 $this->includes(); 83 } 83 /** 84 * ACO Constructor. 85 */ 86 public function __construct() 87 { 88 $this->includes(); 89 } 84 90 85 91 } -
autocomplete-woocommerce-orders/trunk/includes/class-admin.php
r1772218 r2288263 9 9 */ 10 10 11 if ( ! defined( 'ABSPATH' )) {12 11 if () { 12 exit; // Exit if accessed directly. 13 13 } 14 14 15 class ACO_Admin { 16 public $id = 'silkwave_aco'; 15 class ACO_Admin 16 { 17 public $id = 'silkwave_aco'; 17 18 18 function __construct() { 19 if ( is_admin() ) { 20 //add settings tab 21 add_filter( 'woocommerce_settings_tabs_array', array( 22 $this, 23 'silkwave_woocommerce_settings_tabs_array' 24 ), 50 ); 25 //show settings tab 26 add_action( 'woocommerce_settings_tabs_' . $this->id, array( 27 $this, 28 'silkwave_show_settings_tab' 29 ) ); 30 //save settings tab 31 add_action( 'woocommerce_update_options_' . $this->id, array( 32 $this, 33 'silkwave_update_settings_tab' 34 ) ); 35 //add tabs select field 36 add_action( 'woocommerce_admin_field_' . $this->id, array( 37 $this, 38 'show_' . $this->id . '_field' 39 ), 10 ); 40 //save tabs select field 41 add_action( 'woocommerce_update_option_' . $this->id, array( 42 $this, 43 'save_' . $this->id . '_field' 44 ), 10 ); 45 } 46 add_action( 'init', array( $this, 'silkwave_autocomplete_orders' ), 0 ); 47 } 19 function __construct() 20 { 21 if (is_admin()) { 22 //add settings tab 23 add_filter('woocommerce_settings_tabs_array', array( 24 $this, 25 'silkwave_woocommerce_settings_tabs_array' 26 ), 50); 27 //show settings tab 28 add_action('woocommerce_settings_tabs_' . $this->id, array( 29 $this, 30 'silkwave_show_settings_tab' 31 )); 32 //save settings tab 33 add_action('woocommerce_update_options_' . $this->id, array( 34 $this, 35 'silkwave_update_settings_tab' 36 )); 37 //add tabs select field 38 add_action('woocommerce_admin_field_' . $this->id, array( 39 $this, 40 'show_' . $this->id . '_field' 41 ), 10); 42 //save tabs select field 43 add_action('woocommerce_update_option_' . $this->id, array( 44 $this, 45 'save_' . $this->id . '_field' 46 ), 10); 47 } 48 add_action('init', array($this, 'silkwave_autocomplete_orders'), 0); 49 } 48 50 49 function silkwave_autocomplete_orders() { 50 $mode = get_option( 'wc_' . $this->id . '_mode' ); 51 if ( $mode == 'all' ) { 52 add_action( 'woocommerce_thankyou', 'silkwave_autocomplete_all_orders' ); 51 function silkwave_autocomplete_orders() 52 { 53 $mode = get_option('wc_' . $this->id . '_mode'); 53 54 54 function silkwave_autocomplete_all_orders( $order_id) {55 global $woocommerce;55 ) { 56 ; 56 57 57 if ( ! $order_id ) { 58 return; 59 } 60 $order = new WC_Order( $order_id ); 61 $order->update_status( 'completed' ); 62 } 63 } elseif ( $mode == 'paid' ) { 64 add_filter( 'woocommerce_payment_complete_order_status', 'silkwave_autocomplete_paid_orders', 10, 2 ); 58 function silkwave_autocomplete_all_orders($order_id) 59 { 60 global $woocommerce; 65 61 66 function silkwave_autocomplete_paid_orders( $order_status, $order_id ) { 67 $order = new WC_Order( $order_id ); 68 if ( $order_status == 'processing' && ( $order->get_status() == 'on-hold' || $order->get_status() == 'pending' || $order->get_status() == 'failed' ) ) { 69 return 'completed'; 70 } 62 if (!$order_id) { 63 return; 64 } 65 $order = new WC_Order($order_id); 66 $order->update_status('completed'); 67 } 68 } elseif ($mode == 'paid') { 69 add_filter('woocommerce_payment_complete_order_status', 'silkwave_autocomplete_paid_orders', 10, 2); 71 70 72 return $order_status; 73 } 74 } elseif ( $mode == 'virtual' ) { 75 add_filter( 'woocommerce_payment_complete_order_status', 'silkwave_autocomplete_paid_virtual_orders', 10, 2 ); 71 function silkwave_autocomplete_paid_orders($order_status, $order_id) 72 { 73 $order = new WC_Order($order_id); 74 $statuses = ['on-hold', 'pending', 'failed']; 75 if ($order_status == 'processing' && !in_array($order->get_status(), $statuses)) { 76 $order->update_status('completed'); 77 return 'completed'; 78 } 76 79 77 function silkwave_autocomplete_paid_virtual_orders( $order_status, $order_id ) { 78 $order = new WC_Order( $order_id ); 79 if ( 'processing' == $order_status && ( 'on-hold' == $order->get_status() || 'pending' == $order->get_status() || 'failed' == $order->get_status() ) ) { 80 $virtual_order = null; 81 if ( count( $order->get_items() ) > 0 ) { 82 foreach ( $order->get_items() as $item ) { 83 if ( 'line_item' == $item['type'] ) { 84 if ( defined( 'WOOCOMMERCE_VERSION' ) && version_compare( WOOCOMMERCE_VERSION, '3.0', '<' ) ) { 85 $_product = $order->get_product_from_item( $item ); 86 } else { 87 $_product = $item->get_product(); 88 } 89 if ( ! $_product->is_virtual() ) { 90 $virtual_order = false; 91 break; 92 } else { 93 $virtual_order = true; 94 } 95 } 96 } 97 } 98 if ( $virtual_order ) { 99 return 'completed'; 100 } 101 } 80 return $order_status; 81 } 82 } elseif ($mode == 'virtual') { 83 add_filter('woocommerce_payment_complete_order_status', 'silkwave_autocomplete_paid_virtual_orders', 10, 2); 102 84 103 return $order_status; 104 } 105 } 106 } 85 function silkwave_autocomplete_paid_virtual_orders($order_status, $order_id) 86 { 87 $order = new WC_Order($order_id); 88 $statuses = ['on-hold', 'pending', 'failed']; 89 if ('processing' == $order_status && !in_array($order->get_status(), $statuses)) { 90 $virtual_order = null; 91 if (count($order->get_items()) > 0) { 92 foreach ($order->get_items() as $item) { 93 if ('line_item' == $item['type']) { 94 if (defined('WOOCOMMERCE_VERSION') && version_compare(WOOCOMMERCE_VERSION, '3.0', '<')) { 95 $_product = $order->get_product_from_item($item); 96 } else { 97 $_product = $item->get_product(); 98 } 99 if (!$_product->is_virtual()) { 100 $virtual_order = false; 101 break; 102 } else { 103 $virtual_order = true; 104 } 105 } 106 } 107 } 108 if ($virtual_order) { 109 $order->update_status('completed'); 110 return 'completed'; 111 } 112 } 107 113 108 function silkwave_register_plugin_links( $links, $file ) { 109 $base = plugin_basename( __FILE__ ); 110 if ( $file == $base ) { 111 $links[] = '<a href="admin.php?page=wc-settings&tab=silkwave_aco">' . __( 'Settings', 'wcAutocompleteOrders' ) . '</a>'; 112 } 114 return $order_status; 115 } 116 } 117 } 113 118 114 return $links; 115 } 119 function silkwave_register_plugin_links($links, $file) 120 { 121 $base = plugin_basename(__FILE__); 122 if ($file == $base) { 123 $links[] = '<a href="admin.php?page=wc-settings&tab=silkwave_aco">' . __('Settings', 'wcAutocompleteOrders') . '</a>'; 124 } 116 125 117 function silkwave_woocommerce_settings_tabs_array( $settings_tabs ) { 118 $settings_tabs[ $this->id ] = __( 'Autocomplete Orders', 'wcAutocompleteOrders' ); 126 return $links; 127 } 119 128 120 return $settings_tabs; 121 } 129 function silkwave_woocommerce_settings_tabs_array($settings_tabs) 130 { 131 $settings_tabs[$this->id] = __('Autocomplete Orders', 'wcAutocompleteOrders'); 122 132 123 function silkwave_show_settings_tab() { 124 woocommerce_admin_fields( $this->silkwave_get_settings() ); 125 } 133 return $settings_tabs; 134 } 126 135 127 function silkwave_update_settings_tab() { 128 woocommerce_update_options( $this->silkwave_get_settings() ); 129 } 136 function silkwave_show_settings_tab() 137 { 138 woocommerce_admin_fields($this->silkwave_get_settings()); 139 } 130 140 131 function silkwave_get_settings() { 132 $settings = array( 133 'section_title' => array( 134 'name' => __( 'Autocomplete Orders', 'wcAutocompleteOrders' ), 135 'type' => 'title', 136 'desc' => 'Activate the plugin selecting one option from the menu', 137 'id' => 'wc_' . $this->id . '_section_title' 138 ), 139 'title' => array( 140 'name' => __( 'Mode', 'wcAutocompleteOrders' ), 141 'type' => 'select', 142 'desc' => __( 'Specify how you want the plugin to work.', 'wcAutocompleteOrders' ), 143 'desc_tip' => true, 144 'default' => 'off', 145 'id' => 'wc_' . $this->id . '_mode', 146 'css' => 'height:auto;', 147 'options' => array( 148 'off' => 'Off', 149 'virtual' => 'Paid orders of virtual products only', 150 'paid' => 'All paid orders of any product', 151 'all' => 'Any order (paid or unpaid)', 152 ) 153 ), 154 'section_end' => array( 155 'type' => 'sectionend', 156 'id' => 'wc_' . $this->id . '_section_end' 157 ) 158 ); 141 function silkwave_update_settings_tab() 142 { 143 woocommerce_update_options($this->silkwave_get_settings()); 144 } 159 145 160 return apply_filters( 'wc_' . $this->id . '_settings', $settings ); 161 } 146 function silkwave_get_settings() 147 { 148 $settings = array( 149 'section_title' => array( 150 'name' => __('Autocomplete Orders', 'wcAutocompleteOrders'), 151 'type' => 'title', 152 'desc' => 'Activate the plugin selecting one option from the menu', 153 'id' => 'wc_' . $this->id . '_section_title' 154 ), 155 'title' => array( 156 'name' => __('Mode', 'wcAutocompleteOrders'), 157 'type' => 'select', 158 'desc' => __('Specify how you want the plugin to work.', 'wcAutocompleteOrders'), 159 'desc_tip' => true, 160 'default' => 'off', 161 'id' => 'wc_' . $this->id . '_mode', 162 'css' => 'height:auto;', 163 'options' => array( 164 'off' => 'Off', 165 'virtual' => 'Paid orders of virtual products only', 166 'paid' => 'All paid orders of any product', 167 'all' => 'Any order (paid or unpaid)', 168 ) 169 ), 170 'section_end' => array( 171 'type' => 'sectionend', 172 'id' => 'wc_' . $this->id . '_section_end' 173 ) 174 ); 175 176 return apply_filters('wc_' . $this->id . '_settings', $settings); 177 } 162 178 163 179 } … … 165 181 new ACO_Admin(); 166 182 167 add_filter( 'silkwave_register_plugin_links', 'plugin_row_meta', 10, 2);183 add_filter();
Note: See TracChangeset
for help on using the changeset viewer.