Made "my orders" columns fully customisable for filters.

woocommerce_my_account_my_orders_columns filter used to define columns
and woocommerce_my_account_my_orders_column_ID to add content to said
column.

Removes the need for and thus Closes #9634 and closes #9633

@claudiosmweb
This commit is contained in:
Mike Jolley 2015-11-27 12:54:28 +00:00
parent fd5dd4cfb7
commit ec01c3d76f
2 changed files with 69 additions and 58 deletions

View File

@ -200,6 +200,7 @@ Yes you can! Join in on our [GitHub repository](http://github.com/woothemes/wooc
* Dev - Template - Product archive anchors are now hooked into templates rather than hard coded. * Dev - Template - Product archive anchors are now hooked into templates rather than hard coded.
* Dev - Template - Added template files for the customer details list in emails. emails/email-customer-details.php * Dev - Template - Added template files for the customer details list in emails. emails/email-customer-details.php
* Dev - Template - Revised single variation cart template. Template files now exist for variations, and the cart button will display (disabled) when no selections are made. * Dev - Template - Revised single variation cart template. Template files now exist for variations, and the cart button will display (disabled) when no selections are made.
* Dev - Template - Made "my orders" columns fully customizable with filters.
* Dev - Allow wc_clean to support arrays. * Dev - Allow wc_clean to support arrays.
* Dev - Added a manual update trigger for checkout. * Dev - Added a manual update trigger for checkout.
* Dev - Added woocommerce_is_price_filter_active filter to Query class. * Dev - Added woocommerce_is_price_filter_active filter to Query class.

View File

@ -14,13 +14,21 @@
* @see http://docs.woothemes.com/document/template-structure/ * @see http://docs.woothemes.com/document/template-structure/
* @author WooThemes * @author WooThemes
* @package WooCommerce/Templates * @package WooCommerce/Templates
* @version 2.3.10 * @version 2.5.0
*/ */
if ( ! defined( 'ABSPATH' ) ) { if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly exit;
} }
$my_orders_columns = apply_filters( 'woocommerce_my_account_my_orders_columns', array(
'order-number' => __( 'Order', 'woocommerce' ),
'order-date' => __( 'Date', 'woocommerce' ),
'order-status' => __( 'Status', 'woocommerce' ),
'order-total' => __( 'Total', 'woocommerce' ),
'order-actions' => ' ',
) );
$customer_orders = get_posts( apply_filters( 'woocommerce_my_account_my_orders_query', array( $customer_orders = get_posts( apply_filters( 'woocommerce_my_account_my_orders_query', array(
'numberposts' => $order_count, 'numberposts' => $order_count,
'meta_key' => '_customer_user', 'meta_key' => '_customer_user',
@ -37,71 +45,73 @@ if ( $customer_orders ) : ?>
<thead> <thead>
<tr> <tr>
<th class="order-number"><span class="nobr"><?php _e( 'Order', 'woocommerce' ); ?></span></th> <?php foreach ( $my_orders_columns as $column_id => $column_name ) : ?>
<th class="order-date"><span class="nobr"><?php _e( 'Date', 'woocommerce' ); ?></span></th> <th class="<?php echo esc_attr( $column_id ); ?>"><span class="nobr"><?php echo esc_html( $column_name ); ?></span></th>
<th class="order-status"><span class="nobr"><?php _e( 'Status', 'woocommerce' ); ?></span></th> <?php endforeach; ?>
<th class="order-total"><span class="nobr"><?php _e( 'Total', 'woocommerce' ); ?></span></th>
<th class="order-actions">&nbsp;</th>
</tr> </tr>
</thead> </thead>
<tbody><?php <tbody>
foreach ( $customer_orders as $customer_order ) { <?php foreach ( $customer_orders as $customer_order ) :
$order = wc_get_order( $customer_order ); $order = wc_get_order( $customer_order );
$order->populate( $customer_order );
$item_count = $order->get_item_count(); $item_count = $order->get_item_count();
?>
<tr class="order">
<?php foreach ( $my_orders_columns as $column_id => $column_name ) : ?>
<td class="<?php echo esc_attr( $column_id ); ?>" data-title="<?php echo esc_attr( $column_name ); ?>">
<?php if ( has_action( 'woocommerce_my_account_my_orders_column_' . $column_id ) ) : ?>
<?php do_action( 'woocommerce_my_account_my_orders_column_' . $column_id, $order ); ?>
?><tr class="order"> <?php elseif ( 'order-number' === $column_id ) : ?>
<td class="order-number" data-title="<?php esc_attr_e( 'Order Number', 'woocommerce' ); ?>">
<a href="<?php echo esc_url( $order->get_view_order_url() ); ?>"> <a href="<?php echo esc_url( $order->get_view_order_url() ); ?>">
<?php echo _x( '#', 'hash before order number', 'woocommerce' ) . $order->get_order_number(); ?> <?php echo _x( '#', 'hash before order number', 'woocommerce' ) . $order->get_order_number(); ?>
</a> </a>
</td>
<td class="order-date" data-title="<?php esc_attr_e( 'Date', 'woocommerce' ); ?>">
<time datetime="<?php echo date( 'Y-m-d', strtotime( $order->order_date ) ); ?>" title="<?php echo esc_attr( strtotime( $order->order_date ) ); ?>"><?php echo date_i18n( get_option( 'date_format' ), strtotime( $order->order_date ) ); ?></time>
</td>
<td class="order-status" data-title="<?php esc_attr_e( 'Status', 'woocommerce' ); ?>" style="text-align:left; white-space:nowrap;">
<?php echo wc_get_order_status_name( $order->get_status() ); ?>
</td>
<td class="order-total" data-title="<?php esc_attr_e( 'Total', 'woocommerce' ); ?>">
<?php echo sprintf( _n( '%s for %s item', '%s for %s items', $item_count, 'woocommerce' ), $order->get_formatted_order_total(), $item_count ); ?>
</td>
<td class="order-actions">
<?php
$actions = array();
if ( $order->needs_payment() ) { <?php elseif ( 'order-date' === $column_id ) : ?>
$actions['pay'] = array( <time datetime="<?php echo date( 'Y-m-d', strtotime( $order->order_date ) ); ?>" title="<?php echo esc_attr( strtotime( $order->order_date ) ); ?>"><?php echo date_i18n( get_option( 'date_format' ), strtotime( $order->order_date ) ); ?></time>
<?php elseif ( 'order-status' === $column_id ) : ?>
<?php echo wc_get_order_status_name( $order->get_status() ); ?>
<?php elseif ( 'order-total' === $column_id ) : ?>
<?php echo sprintf( _n( '%s for %s item', '%s for %s items', $item_count, 'woocommerce' ), $order->get_formatted_order_total(), $item_count ); ?>
<?php elseif ( 'order-actions' === $column_id ) : ?>
<?php
$actions = array(
'pay' => array(
'url' => $order->get_checkout_payment_url(), 'url' => $order->get_checkout_payment_url(),
'name' => __( 'Pay', 'woocommerce' ) 'name' => __( 'Pay', 'woocommerce' )
); ),
} 'view' => array(
if ( in_array( $order->get_status(), apply_filters( 'woocommerce_valid_order_statuses_for_cancel', array( 'pending', 'failed' ), $order ) ) ) {
$actions['cancel'] = array(
'url' => $order->get_cancel_order_url( wc_get_page_permalink( 'myaccount' ) ),
'name' => __( 'Cancel', 'woocommerce' )
);
}
$actions['view'] = array(
'url' => $order->get_view_order_url(), 'url' => $order->get_view_order_url(),
'name' => __( 'View', 'woocommerce' ) 'name' => __( 'View', 'woocommerce' )
),
'cancel' => array(
'url' => $order->get_cancel_order_url( wc_get_page_permalink( 'myaccount' ) ),
'name' => __( 'Cancel', 'woocommerce' )
)
); );
$actions = apply_filters( 'woocommerce_my_account_my_orders_actions', $actions, $order ); if ( ! $order->needs_payment() ) {
unset( $actions['pay'] );
}
if ( $actions ) { if ( ! in_array( $order->get_status(), apply_filters( 'woocommerce_valid_order_statuses_for_cancel', array( 'pending', 'failed' ), $order ) ) ) {
unset( $actions['cancel'] );
}
if ( $actions = apply_filters( 'woocommerce_my_account_my_orders_actions', $actions, $order ) ) {
foreach ( $actions as $key => $action ) { foreach ( $actions as $key => $action ) {
echo '<a href="' . esc_url( $action['url'] ) . '" class="button ' . sanitize_html_class( $key ) . '">' . esc_html( $action['name'] ) . '</a>'; echo '<a href="' . esc_url( $action['url'] ) . '" class="button ' . sanitize_html_class( $key ) . '">' . esc_html( $action['name'] ) . '</a>';
} }
} }
?> ?>
<?php endif; ?>
</td> </td>
</tr><?php <?php endforeach; ?>
} </tr>
?></tbody> <?php endforeach; ?>
</tbody>
</table> </table>
<?php endif; ?> <?php endif; ?>