settings = array( array( 'name' => __( 'Advanced Order Numbers', 'woocommerce-advanced-ordernumbers' ), 'desc' => __( 'Configure the format and the counters of the order numbers in WooCommerce.', 'woocommerce-advanced-ordernumbers' ), 'type' => 'title', 'id' => 'ordernumber_options' ), array( 'name' => __( 'Customize Order Numbers', 'woocommerce-advanced-ordernumbers' ), 'desc' => __( 'Check to use custom order numbers rather than the default wordpress post ID.', 'woocommerce-advanced-ordernumbers' ), 'id' => 'customize_ordernumber', 'type' => 'checkbox', 'default' => 'no' ), array( 'title' => __( 'Order number format', 'woocommerce-advanced-ordernumbers' ), 'desc' => __( 'The format for the order numbers (variables can be entered as [...], the counter is indicated by the #). To use a different counter name than displayed, put the custom counter name after a |, e.g. "[year]-[month]/#|[year]" to use the month in the order number, but reset the counter only yearly.', 'woocommerce-advanced-ordernumbers' ), 'desc_tip' => true, 'id' => 'ordernumber_format', 'default' => '#', 'type' => 'text', ), array( 'title' => __( 'Global', 'woocommerce-advanced-ordernumbers' ), 'desc' => __( 'Counter Scope', 'woocommerce-advanced-ordernumbers' ), 'id' => 'ordernumber_global', 'type' => 'checkbox', 'default' => 'no' ), array( 'title' => __( 'Counter Digits', 'woocommerce-advanced-ordernumbers' ), 'desc' => __( 'Minimum number of digits for the number', 'woocommerce-advanced-ordernumbers' ), 'desc_tip' => true, 'id' => 'ordernumber_padding', 'type' => 'number', 'default' => '0' ), array( 'title' => __( 'Counter Start', 'woocommerce-advanced-ordernumbers' ), 'desc' => __( 'Start value for each new counter', 'woocommerce-advanced-ordernumbers' ), 'desc_tip' => true, 'id' => 'ordernumber_start', 'type' => 'number', 'default' => '1' ), array( 'title' => __( 'Counter step', 'woocommerce-advanced-ordernumbers' ), 'desc' => __( 'By how much the counter will be increased after each order. Typically 1.', 'woocommerce-advanced-ordernumbers' ), 'desc_tip' => true, 'id' => 'ordernumber_step', 'type' => 'number', 'default' => '1' ), array( 'type' => 'sectionend', 'id' => 'ordernumber_options' ), // TODO: customize order password, and other numbers! array( 'name' => __( 'Custom Variables', 'woocommerce-advanced-ordernumbers' ), 'desc' => __( 'Define your own (conditional) variables for use in the number formats', 'woocommerce-advanced-ordernumbers' ), 'type' => 'title', 'id' => 'ordernumber_variables' ), array( // 'title' => __( 'Custom ', 'woocommerce-advanced-ordernumbers' ), // 'desc' => __( 'The format for the order numbers (variables can be entered as [...], the counter is indicated by the #). To use a different counter name than displayed, put the custom counter name after a |, e.g. "[year]-[month]/#|[year]" to use the month in the order number, but reset the counter only yearly.', 'woocommerce-advanced-ordernumbers' ), 'id' => 'ordernumber_variables', 'type' => 'ordernumber_variables', ), array( 'type' => 'sectionend', 'id' => 'ordernumber_variables' ), array( 'name' => __( 'Current Counters', 'woocommerce-advanced-ordernumbers' ), 'desc' => __( 'View and modify the current counter values.', 'woocommerce-advanced-ordernumbers' ), 'type' => 'title', 'id' => 'ordernumber_counters' ), array( 'id' => 'ordernumber_counters', 'type' => 'ordernumber_counters', ), array( 'type' => 'sectionend', 'id' => 'ordernumber_counters' ), ); // Default options add_option ('customize_ordernumber', '0'); add_option ('ordernumber_format', "#"); add_option ('ordernumber_global', '0'); add_option ('ordernumber_padding', '1'); add_option ('ordernumber_start', '1'); add_option ('ordernumber_step', '1'); // add_option ('ordernumber_counters', '1'); // register filters and actions // CONFIGURATION SCREENS add_filter( 'woocommerce_get_sections_checkout', array($this, 'add_admin_section')); // The checkout settings page assumes all subpages are payment gateways, so we have to override this and manually pass our settings: add_action( 'woocommerce_settings_checkout', array( $this, 'settings_output' ) ); add_action( 'woocommerce_settings_save_checkout', array( $this, 'settings_save' ) ); add_action( 'woocommerce_admin_field_ordernumber_variables', array( $this, 'admin_field_variables' ) ); add_action( 'woocommerce_admin_field_ordernumber_counters', array( $this, 'admin_field_counters' ) ); add_action( 'admin_print_styles-woocommerce_page_wc-settings', array($this, 'print_admin_styles')); add_action( 'admin_print_scripts-woocommerce_page_wc-settings', array($this, 'print_admin_scripts')); // AJAX counter modifications add_action( 'wp_ajax_set_counter', array($this, 'counter_set_callback') ); add_action( 'wp_ajax_add_counter', array($this, 'counter_add_callback') ); add_action( 'wp_ajax_delete_counter', array($this, 'counter_delete_callback') ); // Add the ordernumber post meta to the search in the backend add_filter( 'woocommerce_shop_order_search_fields', array($this, 'order_search_fields')); // Sort the order list in the backend by order number rather than ID, make sure this is called LAST so we modify the defaults passed as arguments add_filter( 'manage_edit-shop_order_sortable_columns', array( $this, 'modify_order_column_sortkey' ), 9999 ); // When a new order is created, we immediately assign the order number: add_action( 'wp_insert_post', array(&$this, 'check_create_ordernumber'), 10, 3); add_action( 'save_post', array(&$this, 'check_create_ordernumber'), 10, 3); // The filter to actually return the order number for the given order add_filter ('woocommerce_order_number', array(&$this, 'get_ordernumber'), 10, 2/*<= Also get the order object! */); } // Activate the plugin public static function activate() {} // Deactivate the plugin public static function deactivate() {} /** * Insert our own section in the checkout setting page. Rearrange the sections array to make sure our settings * come second place, directly after the default page with the '' key and before all the payment gateways */ function add_admin_section($sections) { $newsections = array(); foreach ($sections as $sec => $name ) { $newsections[$sec] = $name; if ($sec == '') { $newsections['ordernumber'] = __( 'Order Numbers', 'woocommerce-advanced-ordernumbers'); } } return $newsections; } public function settings_output() { global $current_section; if ($current_section == 'ordernumber') { $settings = $this->settings; WC_Admin_Settings::output_fields( $settings ); } } public function settings_save() { global $current_section; if ($current_section == 'ordernumber') { $settings = $this->settings; WC_Admin_Settings::save_fields( $settings ); } } /** * Print the CSS for the counter values and counter variables tables to the page header in the WC backend admin setting page */ public function print_admin_styles () { wp_register_style ( 'ordernumber-counter-style', plugins_url('assets/css/ordernumber-counter.css', __FILE__) ); wp_enqueue_style('ordernumber-counter-style'); } /** * Print the JS for the counter values and counter variables tables to the page header in the WC backend admin setting page */ public function print_admin_scripts() { wp_register_script( 'ordernumber-counter-script', plugins_url( 'assets/js/ordernumber-counter.js', __FILE__), array('jquery') ); wp_enqueue_script( 'ordernumber-counter-script'); // Handle the translations: $localizations = array( 'ajax_url' => admin_url( 'admin-ajax.php' ) ); $localizations['ORDERNUMBER_JS_JSONERROR'] = __("Error reading response from server:"); $localizations['ORDERNUMBER_JS_NOT_AUTHORIZED'] = __("You are not authorized to modify order number counters."); $localizations['ORDERNUMBER_JS_NEWCOUNTER'] = __("Please enter the format/name of the new counter:"); $localizations['ORDERNUMBER_JS_ADD_FAILED'] = __("Failed adding counter {0}"); $localizations['ORDERNUMBER_JS_INVALID_COUNTERVALUE'] = __("You entered an invalid value for the counter.\n\n"); $localizations['ORDERNUMBER_JS_EDITCOUNTER'] = __("{0}Please enter the new value for the counter '{1}' (current value: {2}):"); $localizations['ORDERNUMBER_JS_MODIFY_FAILED'] = __("Failed modifying counter {0}"); $localizations['ORDERNUMBER_JS_DELETECOUNTER'] = __("Really delete counter '{0}' with value '{1}'?"); $localizations['ORDERNUMBER_JS_DELETE_FAILED'] = __("Failed deleting counter {0}"); // in JavaScript, object properties are accessed as ajax_object.ajax_url, ajax_object.we_value wp_localize_script( 'ordernumber-counter-script', 'ajax_ordernumber', $localizations ); } /** * Render the Custom Variables configuration table */ public function admin_field_variables($settings) { echo "
All options: ".print_r(wp_load_alloptions(),1).""; $counters = array(); $pfxlen = strlen($this->ordernumber_counter_prefix ); foreach (wp_load_alloptions() as $name => $value) { if (substr($name, 0, $pfxlen) == $this->ordernumber_counter_prefix) { $parts = explode('-', substr($name, $pfxlen), 2); if (sizeof($parts)==1) { array_unshift($parts, 'ordernumber'); } $counters[] = array( 'type' => $parts[0], 'name' => $parts[1], 'value' => $value, ); } } ?>
' . esc_html( $column ) . ' | '; } ?>|||
---|---|---|---|
|
|||
|