Skip to content

Commit

Permalink
= 4.2.6.9.3 =
Browse files Browse the repository at this point in the history
~ Added: get list order by status = trash.
~ Fixed: save date time of LP Order.
  • Loading branch information
tungnxt89 committed Jul 30, 2024
1 parent 58c7b34 commit 364fd72
Show file tree
Hide file tree
Showing 8 changed files with 41 additions and 5 deletions.
2 changes: 1 addition & 1 deletion assets/src/js/admin/order/add-courses-to-order.js
Original file line number Diff line number Diff line change
Expand Up @@ -361,7 +361,7 @@ const addCoursesToOrder = () => {
document.addEventListener( 'click', ( e ) => {
const target = e.target;
//console.dir( target );
if ( target.id === elBtnAddOrderItem.id ) {
if ( elBtnAddOrderItem && target.id === elBtnAddOrderItem.id ) {
e.preventDefault();
showPopupSearchCourses();
}
Expand Down
4 changes: 4 additions & 0 deletions assets/src/scss/admin/_custom-post-types.scss
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@
background: #f00;
}

&.trash {
color: rgba(128, 128, 128, 0.68);
}

i {
display: inline-block;
}
Expand Down
11 changes: 10 additions & 1 deletion inc/admin/views/meta-boxes/order/details.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,15 @@
:
<input type="number" class="order-minute" name="order-minute" min="0" max="59"
value="<?php echo esc_attr( $order->get_order_date( 'm' ) ); ?>">

<!-- Hidden fields for date only for default save post of Wordpress -->
<input type="hidden" name="aa" value="<?php echo gmdate( 'Y', $order->get_order_date( 'timestamp' ) ); ?>">
<input type="hidden" name="mm" value="<?php echo gmdate( 'm', $order->get_order_date( 'timestamp' ) ); ?>">
<input type="hidden" name="jj" value="<?php echo gmdate( 'd', $order->get_order_date( 'timestamp' ) ); ?>">
<input type="hidden" name="ss" value="<?php echo gmdate( 's', $order->get_order_date( 'timestamp' ) ); ?>">
<input type="hidden" name="hh" value="<?php echo gmdate( 'h', $order->get_order_date( 'h' ) ); ?>">
<input type="hidden" name="mn" value="<?php echo gmdate( 'm', $order->get_order_date( 'm' ) ); ?>">
<!-- Hidden fields for date only for default save post of Wordpress -->
</div>

<div class="order-data-field order-data-status <?php echo sanitize_title( $order->get_post_status() ); ?>">
Expand Down Expand Up @@ -137,7 +146,7 @@
</li>',
sprintf( '%s (%s)', $order->get_checkout_email(), __( 'Guest', 'learnpress' ) )
);
} elseif ( $order->is_manual() && $order->is_guest() ) {
} elseif ( $order->is_manual() && empty( $order->get_users() ) && $order->is_guest() ) {
printf(
'<li>
<div class="item">%s</div>
Expand Down
2 changes: 1 addition & 1 deletion inc/admin/views/meta-boxes/order/order-item.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
<?php if ( ! empty( $item['course_id'] ) ) { ?>
<tr class="order-item-row" data-item_id="<?php echo esc_attr( $item['id'] ); ?>" data-id="<?php echo esc_attr( $item['course_id'] ); ?>" data-remove_nonce="<?php echo wp_create_nonce( 'remove_order_item' ); ?>">
<td class="column-name">
<?php if ( $order->is_manual() ) : ?>
<?php if ( $order->is_manual() && $order->get_status() === LP_ORDER_PENDING ) : ?>
<a class="remove-order-item" href="#">
<span class="dashicons dashicons-no-alt"></span>
</a>
Expand Down
10 changes: 10 additions & 0 deletions inc/custom-post-types/order.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ public function __construct() {
add_filter( 'wp_untrash_post_status', array( $this, 'restore_status_order' ), 11, 3 );
add_filter( 'admin_footer', array( $this, 'admin_footer' ) );
add_filter( 'views_edit-lp_order', array( $this, 'filter_views' ) );
add_action( 'restrict_manage_posts', array( $this, 'show_btn_empty_order' ), 10, 2 );
// LP Order title

// Override title of LP Order on Admin
Expand All @@ -56,6 +57,13 @@ public function __construct() {
parent::__construct();
}

public function show_btn_empty_order( $post_type, $which ) {
if ( $post_type !== LP_ORDER_CPT || ! isset( $_GET['post_status'] ) || $_GET['post_status'] !== LP_ORDER_TRASH_DB ) {
return;
}
submit_button( __( 'Empty Trash' ), 'apply', 'delete_all', false );
}

/**
* Unset value in 'mine' key in views of LP Orders.
* The 'mine' is present in some case when 'user_posts_count'
Expand Down Expand Up @@ -257,6 +265,8 @@ public function posts_where_paged( $where ) {
if ( ! empty( $wp_query->get( 'post_status' ) ) ) {
$status = $wp_query->get( 'post_status' );
$where .= $wpdb->prepare( " AND {$lp_db->tb_posts}.post_status = %s", $status );
} else {
$where .= $wpdb->prepare( " AND {$lp_db->tb_posts}.post_status NOT IN (%s, %s)", LP_ORDER_TRASH_DB, 'auto-draft' );
}

return $where;
Expand Down
2 changes: 2 additions & 0 deletions inc/lp-constants.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,13 +88,15 @@
const LP_ORDER_PROCESSING = 'processing';
const LP_ORDER_CANCELLED = 'cancelled';
const LP_ORDER_FAILED = 'failed';
const LP_ORDER_TRASH = 'trash';

// Status LP Order to set DB.
const LP_ORDER_COMPLETED_DB = 'lp-completed';
const LP_ORDER_PENDING_DB = 'lp-pending';
const LP_ORDER_PROCESSING_DB = 'lp-processing';
const LP_ORDER_CANCELLED_DB = 'lp-cancelled';
const LP_ORDER_FAILED_DB = 'lp-failed';
const LP_ORDER_TRASH_DB = 'lp-trash';

// LP Order type create via.
const LP_ORDER_CREATED_VIA_MANUAL = 'manual';
Expand Down
3 changes: 3 additions & 0 deletions inc/order/class-lp-order.php
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,9 @@ public static function get_status_label( string $status ): string {
case LP_ORDER_FAILED:
$status = __( 'Failed', 'learnpress' );
break;
case LP_ORDER_TRASH:
$status = __( 'Trash', 'learnpress' );
break;
case 'on-hold':
$status = __( 'On hold', 'learnpress' );
break;
Expand Down
12 changes: 10 additions & 2 deletions inc/order/lp-order-functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -613,7 +613,7 @@ function learn_press_get_order_status_label( $order_id = 0 ) {
* @return array
* @deprecated 4.2.0
*/
function learn_press_get_order_statuses( $prefix = true, $status_only = false ) {
/*function learn_press_get_order_statuses( $prefix = true, $status_only = false ) {
_deprecated_function( __FUNCTION__, '4.2.0' );
$register_statues = learn_press_get_register_order_statuses();
Expand All @@ -638,7 +638,7 @@ function learn_press_get_order_statuses( $prefix = true, $status_only = false )
// @since 3.0.0
return apply_filters( 'learn-press/order-statues', $order_statuses );
}
}*/

/**
* Get list of registered order's statues for registering with wp post's status.
Expand Down Expand Up @@ -690,6 +690,14 @@ function learn_press_get_register_order_statuses() {
'show_in_admin_status_list' => true,
'label_count' => _n_noop( 'Failed <span class="count">(%s)</span>', 'Failed <span class="count">(%s)</span>', 'learnpress' ),
);
$order_statues['lp-trash'] = array(
'label' => _x( 'Trash', 'Order status', 'learnpress' ),
'public' => false,
'exclude_from_search' => false,
'show_in_admin_all_list' => true,
'show_in_admin_status_list' => true,
'label_count' => _n_noop( 'Trash <span class="count">(%s)</span>', 'Trash <span class="count">(%s)</span>', 'learnpress' ),
);

return $order_statues;
}
Expand Down

0 comments on commit 364fd72

Please sign in to comment.