Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
f79b18b
Implement order edit screen rendering.
vedanshujain Jul 4, 2022
503dbe5
Add changelog.
vedanshujain Jul 4, 2022
4324828
Use global function instead of harcoded string.
vedanshujain Jul 5, 2022
67642d2
Use pagecontroller to display order edit form.
vedanshujain Jul 7, 2022
3d6b886
Move HTML out from the translatable string.
vedanshujain Jul 7, 2022
53f66a0
Capitalize `Order` for consistency.
vedanshujain Jul 7, 2022
4248a84
Minor realignment.
vedanshujain Jul 7, 2022
cc452fe
phpcs fix .
vedanshujain Jul 7, 2022
505aa5c
Decouple meta boxes from global $post object to support custom order …
vedanshujain Jul 11, 2022
29d6b20
Bug fixes - improperly set $order object, and allow passing null.
vedanshujain Jul 11, 2022
2cc2fb8
Make order item meta work with order object.
vedanshujain Jul 13, 2022
ac35ec3
Use `$order` object to minimize diff.
vedanshujain Jul 13, 2022
b21fe97
Refactor $theorder object initialization to a common method.
vedanshujain Jul 13, 2022
e671a2a
Remove check for WC_Order object.
vedanshujain Jul 19, 2022
ae124d7
Move common methods to inside `src` in a dedicated class.
vedanshujain Jul 22, 2022
54461d9
Fix spacing for code style.
vedanshujain Jul 22, 2022
8791dd8
Merge branch 'trunk' into enhancement/32471
vedanshujain Jul 23, 2022
894953a
Renamed method to be more accurate.
vedanshujain Jul 26, 2022
a8d4a7f
Add proxies for static so they can be mocked.
vedanshujain Jul 27, 2022
77d5679
Remove PageController import.
vedanshujain Jul 27, 2022
730c4bb
Move helper methods to an internal util class.
vedanshujain Jul 28, 2022
b0f491d
Merge branch 'trunk' into enhancement/32471
vedanshujain Jul 28, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions plugins/woocommerce/changelog/enhancement-32471
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: minor
Type: add

Order edit screen rendering powered by custom order tables.
13 changes: 13 additions & 0 deletions plugins/woocommerce/includes/abstracts/abstract-wc-order.php
Original file line number Diff line number Diff line change
Expand Up @@ -2250,4 +2250,17 @@ public function has_free_item() {
}
return false;
}

/**
* Get order title.
*
* @return string Order title.
*/
public function get_title() : string {
if ( method_exists( $this->data_store, 'get_title' ) ) {
return $this->data_store->get_title( $this );
} else {
return __( 'Order', 'woocommerce' );
}
}
}
18 changes: 15 additions & 3 deletions plugins/woocommerce/includes/admin/class-wc-admin-assets.php
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ public function admin_scripts() {

wp_localize_script( 'wc-admin-variation-meta-boxes', 'woocommerce_admin_meta_boxes_variations', $params );
}
if ( in_array( str_replace( 'edit-', '', $screen_id ), wc_get_order_types( 'order-meta-boxes' ) ) ) {
if ( $this->is_order_meta_box_screen( $screen_id ) ) {
$default_location = wc_get_customer_default_location();

wp_enqueue_script( 'wc-admin-order-meta-boxes', WC()->plugin_url() . '/assets/js/admin/meta-boxes-order' . $suffix . '.js', array( 'wc-admin-meta-boxes', 'wc-backbone-modal', 'selectWoo', 'wc-clipboard' ), $version );
Expand Down Expand Up @@ -305,14 +305,14 @@ public function admin_scripts() {
)
);
}
if ( in_array( str_replace( 'edit-', '', $screen_id ), array_merge( array( 'shop_coupon', 'product' ), wc_get_order_types( 'order-meta-boxes' ) ) ) ) {
if ( in_array( str_replace( 'edit-', '', $screen_id ), array( 'shop_coupon', 'product' ) ) || $this->is_order_meta_box_screen( $screen_id ) ) {
$post_id = isset( $post->ID ) ? $post->ID : '';
$currency = '';
$remove_item_notice = __( 'Are you sure you want to remove the selected items?', 'woocommerce' );
$remove_fee_notice = __( 'Are you sure you want to remove the selected fees?', 'woocommerce' );
$remove_shipping_notice = __( 'Are you sure you want to remove the selected shipping?', 'woocommerce' );

if ( $post_id && in_array( get_post_type( $post_id ), wc_get_order_types( 'order-meta-boxes' ) ) ) {
if ( $post_id && $this->is_order_meta_box_screen( $screen_id ) ) {
$order = wc_get_order( $post_id );
if ( $order ) {
$currency = $order->get_currency();
Expand Down Expand Up @@ -491,6 +491,18 @@ public function admin_scripts() {

}

/**
* Helper function to determine whether the current screen is an order edit screen.
*
* @param string $screen_id Screen ID.
*
* @return bool Whether the current screen is an order edit screen.
*/
private function is_order_meta_box_screen( string $screen_id ) {
return in_array( str_replace( 'edit-', '', $screen_id ), wc_get_order_types( 'order-meta-boxes' ) ) ||
wc_get_page_screen_id( 'shop-order' ) === $screen_id;
}

}

endif;
Expand Down
5 changes: 0 additions & 5 deletions plugins/woocommerce/includes/admin/class-wc-admin-menus.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
* @version 2.5.0
*/

use Automattic\WooCommerce\Internal\Admin\Orders\ListTable as Custom_Orders_List_Table;
use Automattic\WooCommerce\Internal\Admin\Orders\PageController as Custom_Orders_PageController;
use Automattic\WooCommerce\Internal\DataStores\Orders\CustomOrdersTableController;

Expand All @@ -20,10 +19,6 @@
* WC_Admin_Menus Class.
*/
class WC_Admin_Menus {
/**
* @var Custom_Orders_List_Table
*/
private $orders_list_table;

/**
* Hook in tabs.
Expand Down
26 changes: 18 additions & 8 deletions plugins/woocommerce/includes/admin/class-wc-admin-meta-boxes.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
*/

use Automattic\Jetpack\Constants;
use Automattic\WooCommerce\Internal\Admin\Orders\Edit;

defined( 'ABSPATH' ) || exit;

Expand Down Expand Up @@ -148,14 +149,7 @@ public function add_meta_boxes() {
// Orders.
foreach ( wc_get_order_types( 'order-meta-boxes' ) as $type ) {
$order_type_object = get_post_type_object( $type );
/* Translators: %s order type name. */
add_meta_box( 'woocommerce-order-data', sprintf( __( '%s data', 'woocommerce' ), $order_type_object->labels->singular_name ), 'WC_Meta_Box_Order_Data::output', $type, 'normal', 'high' );
add_meta_box( 'woocommerce-order-items', __( 'Items', 'woocommerce' ), 'WC_Meta_Box_Order_Items::output', $type, 'normal', 'high' );
/* Translators: %s order type name. */
add_meta_box( 'woocommerce-order-notes', sprintf( __( '%s notes', 'woocommerce' ), $order_type_object->labels->singular_name ), 'WC_Meta_Box_Order_Notes::output', $type, 'side', 'default' );
add_meta_box( 'woocommerce-order-downloads', __( 'Downloadable product permissions', 'woocommerce' ) . wc_help_tip( __( 'Note: Permissions for order items will automatically be granted when the order status changes to processing/completed.', 'woocommerce' ) ), 'WC_Meta_Box_Order_Downloads::output', $type, 'normal', 'default' );
/* Translators: %s order type name. */
add_meta_box( 'woocommerce-order-actions', sprintf( __( '%s actions', 'woocommerce' ), $order_type_object->labels->singular_name ), 'WC_Meta_Box_Order_Actions::output', $type, 'side', 'high' );
Automattic\WooCommerce\Internal\Admin\Orders\Edit::add_order_meta_boxes( $type, $order_type_object->labels->singular_name );
}

// Coupons.
Expand Down Expand Up @@ -266,8 +260,24 @@ public function save_meta_boxes( $post_id, $post ) {

// Check the post type.
if ( in_array( $post->post_type, wc_get_order_types( 'order-meta-boxes' ), true ) ) {
/**
* Save meta for shop order.
*
* @param int $post_id Post ID.
* @param object $post Post object.
*
* @since 2.1.0
*/
do_action( 'woocommerce_process_shop_order_meta', $post_id, $post );
} elseif ( in_array( $post->post_type, array( 'product', 'shop_coupon' ), true ) ) {
/**
* Save meta for product.
*
* @param int $post_id Post ID.
* @param object $post Post object.
*
* @since 2.1.0
*/
do_action( 'woocommerce_process_' . $post->post_type . '_meta', $post_id, $post );
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ public static function render_suggestions_container( $context ) {
*/
public static function show_suggestions_for_screen( $screen_id ) {
// We only show suggestions on certain admin screens.
if ( ! in_array( $screen_id, array( 'edit-product', 'edit-shop_order', 'product', 'woocommerce_page_wc-orders' ), true ) ) {
if ( ! in_array( $screen_id, array( 'edit-product', 'edit-shop_order', 'product', wc_get_page_screen_id( 'shop-order' ) ), true ) ) {
return false;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
* @version 2.1.0
*/

use Automattic\WooCommerce\Utilities\OrderUtil;

if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly.
}
Expand All @@ -20,23 +22,28 @@ class WC_Meta_Box_Order_Actions {
/**
* Output the metabox.
*
* @param WP_Post $post Post object.
* @param WP_Post|WC_Order $post Post or order object.
*/
public static function output( $post ) {
global $theorder;

// This is used by some callbacks attached to hooks such as woocommerce_order_actions which rely on the global to determine if actions should be displayed for certain orders.
// Avoid using this global with the `woocommerce_order_actions` filter, instead use the $order filter arg.
if ( ! is_object( $theorder ) ) {
$theorder = wc_get_order( $post->ID );
}
OrderUtil::init_theorder_object( $post );
$order = $theorder;

$theorder = $theorder instanceof WC_Order ? $theorder : null;
$order_actions = self::get_available_order_actions_for_order( $theorder );
$order_id = $order->get_id();
$order_actions = self::get_available_order_actions_for_order( $order );
?>
<ul class="order_actions submitbox">

<?php do_action( 'woocommerce_order_actions_start', $post->ID ); ?>
<?php
/**
* Fires at the start of order actions meta box rendering.
*
* @since 2.1.0
*/
do_action( 'woocommerce_order_actions_start', $order_id );
?>


<li class="wide" id="actions">
<select name="wc_order_action">
Expand All @@ -51,24 +58,31 @@ public static function output( $post ) {
<li class="wide">
<div id="delete-action">
<?php
if ( current_user_can( 'delete_post', $post->ID ) ) {
if ( current_user_can( 'delete_post', $order_id ) ) {

if ( ! EMPTY_TRASH_DAYS ) {
$delete_text = __( 'Delete permanently', 'woocommerce' );
} else {
$delete_text = __( 'Move to Trash', 'woocommerce' );
}
?>
<a class="submitdelete deletion" href="<?php echo esc_url( get_delete_post_link( $post->ID ) ); ?>"><?php echo esc_html( $delete_text ); ?></a>
<a class="submitdelete deletion" href="<?php echo esc_url( get_delete_post_link( $order_id ) ); ?>"><?php echo esc_html( $delete_text ); ?></a>
<?php
}
?>
</div>

<button type="submit" class="button save_order button-primary" name="save" value="<?php echo 'auto-draft' === $post->post_status ? esc_attr__( 'Create', 'woocommerce' ) : esc_attr__( 'Update', 'woocommerce' ); ?>"><?php echo 'auto-draft' === $post->post_status ? esc_html__( 'Create', 'woocommerce' ) : esc_html__( 'Update', 'woocommerce' ); ?></button>
<button type="submit" class="button save_order button-primary" name="save" value="<?php echo 'auto-draft' === $order->get_status() ? esc_attr__( 'Create', 'woocommerce' ) : esc_attr__( 'Update', 'woocommerce' ); ?>"><?php echo 'auto-draft' === $order->get_status() ? esc_html__( 'Create', 'woocommerce' ) : esc_html__( 'Update', 'woocommerce' ); ?></button>
</li>

<?php do_action( 'woocommerce_order_actions_end', $post->ID ); ?>
<?php
/**
* Fires at the end of order actions meta box rendering.
*
* @since 2.1.0
*/
do_action( 'woocommerce_order_actions_end', $order_id );
?>

</ul>
<?php
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
* @version 2.2.0
*/

use Automattic\WooCommerce\Utilities\OrderUtil;

if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly.
}
Expand Down Expand Up @@ -141,14 +143,12 @@ public static function init_address_fields() {
/**
* Output the metabox.
*
* @param WP_Post $post The post to output the metabox for.
* @param WP_Post|WC_Order $post Post or order object.
*/
public static function output( $post ) {
global $theorder;

if ( ! is_object( $theorder ) ) {
$theorder = wc_get_order( $post->ID );
}
OrderUtil::init_theorder_object( $post );

$order = $theorder;

Expand All @@ -162,15 +162,15 @@ public static function output( $post ) {

$payment_method = $order->get_payment_method();

$order_type_object = get_post_type_object( $post->post_type );
$order_type_object = get_post_type_object( $order->get_type() );
wp_nonce_field( 'woocommerce_save_data', 'woocommerce_meta_nonce' );
?>
<style type="text/css">
#post-body-content, #titlediv { display:none }
</style>
<div class="panel-wrap woocommerce">
<input name="post_title" type="hidden" value="<?php echo empty( $post->post_title ) ? esc_attr__( 'Order', 'woocommerce' ) : esc_attr( $post->post_title ); ?>" />
<input name="post_status" type="hidden" value="<?php echo esc_attr( $post->post_status ); ?>" />
<input name="post_title" type="hidden" value="<?php echo esc_attr( empty( $order->get_title() ) ? __( 'Order', 'woocommerce' ) : $order->get_title() ); ?>" />
<input name="post_status" type="hidden" value="<?php echo esc_attr( $order->get_status() ); ?>" />
<div id="order_data" class="panel woocommerce-order-data">
<h2 class="woocommerce-order-data__heading">
<?php
Expand Down Expand Up @@ -198,6 +198,7 @@ public static function output( $post ) {

$transaction_id = $order->get_transaction_id();
if ( $transaction_id ) {

$to_add = null;
if ( isset( $payment_gateways[ $payment_method ] ) ) {
$url = $payment_gateways[ $payment_method ]->get_transaction_url( $order );
Expand All @@ -222,6 +223,7 @@ public static function output( $post ) {
);
}


$ip_address = $order->get_customer_ip_address();
if ( $ip_address ) {
$meta_list[] = sprintf(
Expand All @@ -240,12 +242,12 @@ public static function output( $post ) {
<h3><?php esc_html_e( 'General', 'woocommerce' ); ?></h3>

<p class="form-field form-field-wide">
<label for="order_date"><?php esc_html_e( 'Date created:', 'woocommerce' ); ?></label>
<input type="text" class="date-picker" name="order_date" maxlength="10" value="<?php echo esc_attr( date_i18n( 'Y-m-d', strtotime( $post->post_date ) ) ); ?>" pattern="<?php echo esc_attr( apply_filters( 'woocommerce_date_input_html_pattern', '[0-9]{4}-(0[1-9]|1[012])-(0[1-9]|1[0-9]|2[0-9]|3[01])' ) ); ?>" />@
<label for="order_date"><?php _e( 'Date created:', 'woocommerce' ); ?></label>
<input type="text" class="date-picker" name="order_date" maxlength="10" value="<?php echo esc_attr( date_i18n( 'Y-m-d', strtotime( $order->get_date_created() ) ) ); ?>" pattern="<?php echo esc_attr( apply_filters( 'woocommerce_date_input_html_pattern', '[0-9]{4}-(0[1-9]|1[012])-(0[1-9]|1[0-9]|2[0-9]|3[01])' ) ); // phpcs:ignore WooCommerce.Commenting.CommentHooks.MissingHookComment ?>" />@
&lrm;
<input type="number" class="hour" placeholder="<?php esc_attr_e( 'h', 'woocommerce' ); ?>" name="order_date_hour" min="0" max="23" step="1" value="<?php echo esc_attr( date_i18n( 'H', strtotime( $post->post_date ) ) ); ?>" pattern="([01]?[0-9]{1}|2[0-3]{1})" />:
<input type="number" class="minute" placeholder="<?php esc_attr_e( 'm', 'woocommerce' ); ?>" name="order_date_minute" min="0" max="59" step="1" value="<?php echo esc_attr( date_i18n( 'i', strtotime( $post->post_date ) ) ); ?>" pattern="[0-5]{1}[0-9]{1}" />
<input type="hidden" name="order_date_second" value="<?php echo esc_attr( date_i18n( 's', strtotime( $post->post_date ) ) ); ?>" />
<input type="number" class="hour" placeholder="<?php esc_attr_e( 'h', 'woocommerce' ); ?>" name="order_date_hour" min="0" max="23" step="1" value="<?php echo esc_attr( date_i18n( 'H', strtotime( $order->get_date_created() ) ) ); ?>" pattern="([01]?[0-9]{1}|2[0-3]{1})" />:
<input type="number" class="minute" placeholder="<?php esc_attr_e( 'm', 'woocommerce' ); ?>" name="order_date_minute" min="0" max="59" step="1" value="<?php echo esc_attr( date_i18n( 'i', strtotime( $order->get_date_created() ) ) ); ?>" pattern="[0-5]{1}[0-9]{1}" />
<input type="hidden" name="order_date_second" value="<?php echo esc_attr( date_i18n( 's', strtotime( $order->get_date_created() ) ) ); ?>" />
</p>

<p class="form-field form-field-wide wc-order-status">
Expand Down Expand Up @@ -320,7 +322,7 @@ public static function output( $post ) {
</select>
<!--/email_off-->
</p>
<?php do_action( 'woocommerce_admin_order_data_after_order_details', $order ); ?>
<?php do_action( 'woocommerce_admin_order_data_after_order_details', $order ); // phpcs:ignore WooCommerce.Commenting.CommentHooks.MissingHookComment ?>
</div>
<div class="order_data_column">
<h3>
Expand Down Expand Up @@ -394,10 +396,10 @@ public static function output( $post ) {

switch ( $field['type'] ) {
case 'select':
woocommerce_wp_select( $field );
woocommerce_wp_select( $field, $order );
break;
default:
woocommerce_wp_text_input( $field );
woocommerce_wp_text_input( $field, $order );
break;
}
}
Expand Down Expand Up @@ -433,12 +435,13 @@ public static function output( $post ) {
'id' => '_transaction_id',
'label' => __( 'Transaction ID', 'woocommerce' ),
'value' => $order->get_transaction_id( 'edit' ),
)
),
$order
);
?>

</div>
<?php do_action( 'woocommerce_admin_order_data_after_billing_address', $order ); ?>
<?php do_action( 'woocommerce_admin_order_data_after_billing_address', $order ); // phpcs:ignore WooCommerce.Commenting.CommentHooks.MissingHookComment ?>
</div>
<div class="order_data_column">
<h3>
Expand Down Expand Up @@ -483,8 +486,8 @@ public static function output( $post ) {
}
}

if ( apply_filters( 'woocommerce_enable_order_notes_field', 'yes' === get_option( 'woocommerce_enable_order_comments', 'yes' ) ) && $post->post_excerpt ) {
echo '<p class="order_note"><strong>' . esc_html__( 'Customer provided note:', 'woocommerce' ) . '</strong> ' . nl2br( esc_html( $post->post_excerpt ) ) . '</p>';
if ( apply_filters( 'woocommerce_enable_order_notes_field', 'yes' === get_option( 'woocommerce_enable_order_comments', 'yes' ) ) && $order->get_customer_note() ) { // phpcs:ignore WooCommerce.Commenting.CommentHooks.MissingHookComment
echo '<p class="order_note"><strong>' . esc_html( __( 'Customer provided note:', 'woocommerce' ) ) . '</strong> ' . nl2br( esc_html( $order->get_customer_note() ) ) . '</p>';
}
?>
</div>
Expand All @@ -511,10 +514,10 @@ public static function output( $post ) {

switch ( $field['type'] ) {
case 'select':
woocommerce_wp_select( $field );
woocommerce_wp_select( $field, $order );
break;
default:
woocommerce_wp_text_input( $field );
woocommerce_wp_text_input( $field, $order );
break;
}
}
Expand All @@ -523,13 +526,13 @@ public static function output( $post ) {
if ( apply_filters( 'woocommerce_enable_order_notes_field', 'yes' === get_option( 'woocommerce_enable_order_comments', 'yes' ) ) ) :
?>
<p class="form-field form-field-wide">
<label for="excerpt"><?php esc_html_e( 'Customer provided note', 'woocommerce' ); ?>:</label>
<textarea rows="1" cols="40" name="excerpt" tabindex="6" id="excerpt" placeholder="<?php esc_attr_e( 'Customer notes about the order', 'woocommerce' ); ?>"><?php echo wp_kses_post( $post->post_excerpt ); ?></textarea>
<label for="excerpt"><?php _e( 'Customer provided note', 'woocommerce' ); ?>:</label>
<textarea rows="1" cols="40" name="excerpt" tabindex="6" id="excerpt" placeholder="<?php esc_attr_e( 'Customer notes about the order', 'woocommerce' ); ?>"><?php echo wp_kses_post( $order->get_customer_note() ); ?></textarea>
</p>
<?php endif; ?>
</div>

<?php do_action( 'woocommerce_admin_order_data_after_shipping_address', $order ); ?>
<?php do_action( 'woocommerce_admin_order_data_after_shipping_address', $order ); // phpcs:ignore WooCommerce.Commenting.CommentHooks.MissingHookComment ?>
</div>
</div>
<div class="clear"></div>
Expand Down
Loading