Commit 99ed5f31 authored by Reinhold Kainhofer's avatar Reinhold Kainhofer

Make it work in the FE, too

parent 6327cf30
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
- Would it make sense to configure the order password format?
- 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
// 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);
// 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! */);
}
......@@ -533,6 +533,20 @@ if ( in_array( 'woocommerce/woocommerce.php', apply_filters( 'active_plugins', g
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,
* 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
* The hook to assign a customized order number (unless the order already has one assigned)
*/
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
update_post_meta( $orderid, $this->ordernumber_meta, $this->ordernumber_new_placeholder );
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment