Make HPOS UX more consistent with posts (so that same e2e tests passes). (#36282)
This commit is contained in:
parent
af9389d50d
commit
01e8a2029a
|
@ -0,0 +1,4 @@
|
|||
Significance: patch
|
||||
Type: fix
|
||||
|
||||
Make HPOS UX more consistent with posts UI (so that same e2e tests passes for both).
|
|
@ -33,6 +33,20 @@ class Edit {
|
|||
*/
|
||||
private $order;
|
||||
|
||||
/**
|
||||
* Action name that the form is currently handling. Could be new_order or edit_order.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private $current_action;
|
||||
|
||||
/**
|
||||
* Message to be displayed to the user. Index of message from the messages array registered when declaring shop_order post type.
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
private $message;
|
||||
|
||||
/**
|
||||
* Hooks all meta-boxes for order edit page. This is static since this may be called by post edit form rendering.
|
||||
*
|
||||
|
@ -123,6 +137,15 @@ class Edit {
|
|||
$this->enqueue_scripts();
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the current action for the form.
|
||||
*
|
||||
* @param string $action Action name.
|
||||
*/
|
||||
public function set_current_action( string $action ) {
|
||||
$this->current_action = $action;
|
||||
}
|
||||
|
||||
/**
|
||||
* Hooks meta box for order specific meta.
|
||||
*/
|
||||
|
@ -163,6 +186,9 @@ class Edit {
|
|||
*/
|
||||
do_action( 'woocommerce_process_shop_order_meta', $this->order->get_id(), $this->order );
|
||||
|
||||
// Order updated message.
|
||||
$this->message = 1;
|
||||
|
||||
// Refresh the order from DB.
|
||||
$this->order = wc_get_order( $this->order->get_id() );
|
||||
$theorder = $this->order;
|
||||
|
@ -188,7 +214,39 @@ class Edit {
|
|||
* Render order edit page.
|
||||
*/
|
||||
public function display() {
|
||||
$this->render_wrapper_start();
|
||||
/**
|
||||
* This is used by the order edit page to show messages in the notice fields.
|
||||
* It should be similar to post_updated_messages filter, i.e.:
|
||||
* array(
|
||||
* {order_type} => array(
|
||||
* 1 => 'Order updated.',
|
||||
* 2 => 'Custom field updated.',
|
||||
* ...
|
||||
* ).
|
||||
*
|
||||
* The index to be displayed is computed from the $_GET['message'] variable.
|
||||
*
|
||||
* @since 7.4.0.
|
||||
*/
|
||||
$messages = apply_filters( 'woocommerce_order_updated_messages', array() );
|
||||
|
||||
/**
|
||||
* Backward compatibility for displaying messages using the post fields.
|
||||
*
|
||||
* @since 7.4.0. (Although available earlier by the posts based screen).
|
||||
*/
|
||||
$messages = apply_filters( 'post_updated_messages', $messages );
|
||||
|
||||
$message = $this->message;
|
||||
if ( isset( $_GET['message'] ) ) {
|
||||
$message = absint( $_GET['message'] );
|
||||
}
|
||||
|
||||
if ( isset( $message ) ) {
|
||||
$message = $messages[ $this->order->get_type() ][ $message ] ?? false;
|
||||
}
|
||||
|
||||
$this->render_wrapper_start( '', $message );
|
||||
$this->render_meta_boxes();
|
||||
$this->render_wrapper_end();
|
||||
}
|
||||
|
@ -210,10 +268,14 @@ class Edit {
|
|||
?>
|
||||
<div class="wrap">
|
||||
<h1 class="wp-heading-inline">
|
||||
<?php echo esc_html( $post_type->labels->edit_item ); ?>
|
||||
<?php
|
||||
echo 'new_order' === $this->current_action ? esc_html( $post_type->labels->add_new_item ) : esc_html( $post_type->labels->edit_item );
|
||||
?>
|
||||
</h1>
|
||||
<?php
|
||||
echo ' <a href="' . esc_url( $new_page_url ) . '" class="page-title-action">' . esc_html( $post_type->labels->add_new ) . '</a>';
|
||||
if ( 'edit_order' === $this->current_action ) {
|
||||
echo ' <a href="' . esc_url( $new_page_url ) . '" class="page-title-action">' . esc_html( $post_type->labels->add_new ) . '</a>';
|
||||
}
|
||||
?>
|
||||
<hr class="wp-header-end">
|
||||
|
||||
|
|
|
@ -211,6 +211,7 @@ class PageController {
|
|||
$this->order_edit_form = new Edit();
|
||||
$this->order_edit_form->setup( $this->order );
|
||||
}
|
||||
$this->order_edit_form->set_current_action( $this->current_action );
|
||||
$this->order_edit_form->display();
|
||||
break;
|
||||
case 'list_orders':
|
||||
|
@ -285,7 +286,7 @@ class PageController {
|
|||
|
||||
$this->order = new $order_class_name();
|
||||
$this->order->set_object_read( false );
|
||||
$this->order->set_status( 'auto-draft' );
|
||||
$this->order->set_status( 'pending' );
|
||||
$this->order->save();
|
||||
|
||||
$theorder = $this->order;
|
||||
|
|
Loading…
Reference in New Issue