Add order edit rendering when creating new order (#33848)
* Create an empty order when initializing new order form. * Set object read to false to preent order note. * Add changelog.
This commit is contained in:
parent
406853634a
commit
f7959c7680
|
@ -0,0 +1,4 @@
|
|||
Significance: patch
|
||||
Type: fix
|
||||
|
||||
Generate ID when creating a new order in COT for consistency with posts.
|
|
@ -27,6 +27,13 @@ class PageController {
|
|||
*/
|
||||
private $current_action = '';
|
||||
|
||||
/**
|
||||
* Order object to be used in edit/new form.
|
||||
*
|
||||
* @var \WC_Order
|
||||
*/
|
||||
private $order;
|
||||
|
||||
/**
|
||||
* Sets up the page controller, including registering the menu item.
|
||||
*
|
||||
|
@ -141,27 +148,31 @@ class PageController {
|
|||
*/
|
||||
private function setup_action_edit_order(): void {
|
||||
global $theorder;
|
||||
switch ( $this->current_action ) {
|
||||
case 'edit_order':
|
||||
$this->order = wc_get_order( absint( isset( $_GET['id'] ) ? $_GET['id'] : 0 ) );
|
||||
if ( 'edit_order' === $this->current_action && ( ! isset( $this->order ) || ! $this->order ) ) {
|
||||
wp_die( esc_html__( 'You attempted to edit an item that does not exist. Perhaps it was deleted?', 'woocommerce' ) );
|
||||
}
|
||||
if ( ! current_user_can( 'edit_others_shop_orders' ) && ! current_user_can( 'manage_woocommerce' ) ) {
|
||||
wp_die( esc_html__( 'You do not have permission to edit this order', 'woocommerce' ) );
|
||||
}
|
||||
break;
|
||||
case 'new_order':
|
||||
$this->order = new \WC_Order();
|
||||
if ( ! current_user_can( 'publish_shop_orders' ) && ! current_user_can( 'manage_woocommerce' ) ) {
|
||||
wp_die( esc_html__( 'You don\'t have permission to create a new order', 'woocommerce' ) );
|
||||
}
|
||||
break;
|
||||
default:
|
||||
wp_safe_redirect( admin_url( 'admin.php?page=wc-orders' ) );
|
||||
exit;
|
||||
$this->order = wc_get_order( absint( isset( $_GET['id'] ) ? $_GET['id'] : 0 ) );
|
||||
if ( 'edit_order' === $this->current_action && ( ! isset( $this->order ) || ! $this->order ) ) {
|
||||
wp_die( esc_html__( 'You attempted to edit an item that does not exist. Perhaps it was deleted?', 'woocommerce' ) );
|
||||
}
|
||||
if ( ! current_user_can( 'edit_others_shop_orders' ) && ! current_user_can( 'manage_woocommerce' ) ) {
|
||||
wp_die( esc_html__( 'You do not have permission to edit this order', 'woocommerce' ) );
|
||||
}
|
||||
$theorder = $this->order;
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles initialization of the orders edit form with a new order.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
private function setup_action_new_order(): void {
|
||||
global $theorder;
|
||||
if ( ! current_user_can( 'publish_shop_orders' ) && ! current_user_can( 'manage_woocommerce' ) ) {
|
||||
wp_die( esc_html__( 'You don\'t have permission to create a new order', 'woocommerce' ) );
|
||||
}
|
||||
$this->order = new \WC_Order();
|
||||
$this->order->set_object_read( false );
|
||||
$this->order->set_status( 'auto-draft' );
|
||||
$this->order->save();
|
||||
$theorder = $this->order;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue