目錄
原始文章
WooCommerce-在後台訂單編輯頁面新增上一筆/下一筆 快速切換按鈕
//----- ↓ 上一筆 / 下一筆訂單 Previous Order / Next Order ↓ -----//
add_action('woocommerce_order_actions_end','jump_to_previous_and_next_order');
function jump_to_previous_and_next_order($order_id) {
global $post, $wpdb;
$order_navigation = $wpdb->get_row( $wpdb->prepare( "
SELECT
(SELECT ID FROM {$wpdb->prefix}posts
WHERE ID < %d
AND post_type = '%s'
AND post_status <> 'trash'
ORDER BY ID DESC LIMIT 1 )
AS prev_order_id,
(SELECT ID FROM {$wpdb->prefix}posts
WHERE ID > %d
AND post_type = '%s'
AND post_status <> 'trash'
ORDER BY ID ASC LIMIT 1 )
AS next_order_id
", $post->ID, $post->post_type, $post->ID, $post->post_type ), ARRAY_A ); ?>
<ul class="clearfix">
<?php if ( array_filter( $order_navigation ) ) : ?>
<?php $next_order_id = absint( $order_navigation[ 'next_order_id' ] ); ?>
<?php $disable = (is_null( $order_navigation[ 'next_order_id' ])) ? ' style="pointer-events:none; background-color:#e0e0e0;"' : ''; ?>
<li><?php echo sprintf( '<a href="%1$s" class="button button-secondary prev-order tips button-small" data-tip=" ' . __( 'Order', 'wc-order-navigation' ) . ' #%2$s" '.$disable.'>< 較新</a>', esc_url( sprintf( admin_url( 'post.php?post=%d&action=edit' ), $next_order_id ) ), $next_order_id); ?></li>
<?php $previous_order_id = absint( $order_navigation[ 'prev_order_id' ] ); ?>
<li><?php echo sprintf( '<a href="%1$s" class="button button-secondary prev-order tips button-small" data-tip=" ' . __( 'Order', 'wc-order-navigation') . ' #%2$s">較舊 ></a>', esc_url( sprintf( admin_url( 'post.php?post=%d&action=edit' ), $previous_order_id ) ), $previous_order_id); ?></li>
<?php else : ?>
<li><?php _e( 'You need to have at least two orders, to use the navigation.', 'wc-order-navigation' ); ?></li>
<?php endif; ?>
</ul>
<?php }
//----- ↑ 上一筆 / 下一筆訂單 Previous Order / Next Order ↑ -----//