Skip to content
Snippets Groups Projects
Commit 99ed5f31 authored by Reinhold Kainhofer's avatar Reinhold Kainhofer
Browse files

Make it work in the FE, too

parent 6327cf30
No related branches found
No related tags found
No related merge requests found
OpenTools Advanced Ordernumbers for WooCommerce - Open TODOs OpenTools Advanced Ordernumbers for WooCommerce - Open TODOs
============================================================ ============================================================
- Make sure the numbers are generated only for new orders, not for exsiting ones - Make sure the numbers are generated only for new orders, not for existing ones
- Check REST API - Check REST API
- Would it make sense to configure the order password format? - Would it make sense to configure the order password format?
- Find out how multisite works and make the plugin work with it - Find out how multisite works and make the plugin work with it
......
...@@ -192,7 +192,7 @@ if ( in_array( 'woocommerce/woocommerce.php', apply_filters( 'active_plugins', g ...@@ -192,7 +192,7 @@ if ( in_array( 'woocommerce/woocommerce.php', apply_filters( 'active_plugins', g
// When a new order is created, we immediately assign the order number: // 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( 'wp_insert_post', array(&$this, 'check_create_ordernumber'), 10, 3);
add_action( 'save_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 // 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! */); add_filter ('woocommerce_order_number', array(&$this, 'get_ordernumber'), 10, 2/*<= Also get the order object! */);
} }
...@@ -533,6 +533,20 @@ if ( in_array( 'woocommerce/woocommerce.php', apply_filters( 'active_plugins', g ...@@ -533,6 +533,20 @@ if ( in_array( 'woocommerce/woocommerce.php', apply_filters( 'active_plugins', g
return wp_parse_args ($custom, $columns); return wp_parse_args ($custom, $columns);
} }
/**
* Add the "create new order number" action to the edit order page in the Backend
*/
public function add_order_action_new_number($actions) {
$actions['assign_new_ordernumber'] = self::__('Assign a new order number');
}
/**
* Handle the "Assign a new order number" action from the edit order page in the backend
*/
public function order_action_assign_new_ordernumber( $order ) {
$number = $this->create_ordernumber($order->id, $order, 'ordernumber');
}
/** /**
* Handle new posts created in the frontend. This action will be called for all posts, * Handle new posts created in the frontend. This action will be called for all posts,
* not only for orders, so we need to check explicitly. Also, this function will be called * not only for orders, so we need to check explicitly. Also, this function will be called
...@@ -884,7 +898,7 @@ if ( in_array( 'woocommerce/woocommerce.php', apply_filters( 'active_plugins', g ...@@ -884,7 +898,7 @@ if ( in_array( 'woocommerce/woocommerce.php', apply_filters( 'active_plugins', g
* The hook to assign a customized order number (unless the order already has one assigned) * The hook to assign a customized order number (unless the order already has one assigned)
*/ */
function assign_new_ordernumber($orderid, $order, $update=true) { function assign_new_ordernumber($orderid, $order, $update=true) {
if ((!$update) && ($order->post_status == 'auto-draft')) { if ((!$update) /*&& ($order->post_status == 'auto-draft')*/) {
// New order => assign placeholder, which will later be overwritten the real order number // New order => assign placeholder, which will later be overwritten the real order number
update_post_meta( $orderid, $this->ordernumber_meta, $this->ordernumber_new_placeholder ); update_post_meta( $orderid, $this->ordernumber_meta, $this->ordernumber_new_placeholder );
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment