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:
Vedanshu Jain 2022-07-30 01:38:38 +05:30 committed by GitHub
parent 406853634a
commit f7959c7680
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 34 additions and 19 deletions

View File

@ -0,0 +1,4 @@
Significance: patch
Type: fix
Generate ID when creating a new order in COT for consistency with posts.

View File

@ -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;
}
}