The right way to Customise Woocommerce Orders web page? (20 hacks)

On this submit I’ll present you find out how to customise Woocommerce orders web page with the assistance of easy code snippets. Now, so as to make this work add your chosen snippets proven to your baby theme’s features.php file or higher but, use a snippet supervisor like Code Snippets.

WpCodeBox is my favourite code snippets supervisor for WordPress. This can be a premium plugin and if you happen to’re , then seize WPCodeBox with a pleasant 20% low cost right here (SAVE 20% Coupon WPSH20).

Video: The right way to Customise Woocommerce Orders web page?

In case you could have a tough time utilizing or following snippets proven beneath, check out the video. In it I’ll present you find out how to use them.

The right way to add an Woocommerce order quantity search subject to the WP Admin prime bar?

For the time being you need to go to the Woocommerce >> Orders web page so as to search orders. With the assistance of this hack you are able to do it straight out of your WordPress admin bar (see screenshot)

How to add an Woocommerce order number search field to the WP Admin top bar?
<span position="button" tabindex="0" data-code="// Add an Woocommerce order quantity search subject to the WP Admin prime bar
add_action('wp_before_admin_bar_render', operate() {
if(!current_user_can('administrator')) {
return;
}

international $wp_admin_bar;

$search_query = '';
if (!empty($_GET['post_type']) && $_GET['post_type'] == 'shop_order' ) {

$search_query = !empty($_GET['s']) ? $_GET['s'] : '';

if($search_query) {
$order = get_post(intval($search_query));

if($order) {
wp_redirect(get_edit_post_link($order->ID, ''));
exit;
}
}
}

$wp_admin_bar->add_menu(array(
'id' => 'admin_bar_shop_order_form',
'title' => '<type methodology="get" motion="'.get_site_url().'/wp-admin/edit.php?post_type=shop_order">
<enter title="s" sort="textual content" placeholder="Order ID" worth="' . esc_attr($search_query) . '" type="width:100px; top: 25px; padding-left: 5px;">
<button class="button button-primary" type="top: 25px; padding: 0px 10px 0px 10px; margin-left: -5px;">Verify this order</button>
<enter title="post_type" worth="shop_order" sort="hidden">

// Add an Woocommerce order quantity search subject to the WP Admin prime bar
add_action('wp_before_admin_bar_render', operate() {
  if(!current_user_can('administrator')) {
    return;
  }
  
  international $wp_admin_bar;

  $search_query = '';
  if (!empty($_GET['post_type']) && $_GET['post_type'] == 'shop_order' ) {

    $search_query = !empty($_GET['s']) ? $_GET['s'] : '';

    if($search_query) {
        $order = get_post(intval($search_query));

        if($order) {
            wp_redirect(get_edit_post_link($order->ID, ''));
            exit;
        }
    }
  }

  $wp_admin_bar->add_menu(array(
    'id' => 'admin_bar_shop_order_form',
    'title' => '<type methodology="get" motion="'.get_site_url().'/wp-admin/edit.php?post_type=shop_order">
      <enter title="s" sort="textual content" placeholder="Order ID" worth="' . esc_attr($search_query) . '" type="width:100px; top: 25px; padding-left: 5px;">
      <button  class="button button-primary" type="top: 25px; padding: 0px 10px 0px 10px; margin-left: -5px;">Verify this order</button>
      <enter title="post_type" worth="shop_order" sort="hidden">
    </type>'
  ));
},100
);

The right way to ship a customized reminder electronic mail for WooCommerce On-Maintain orders after two days?

By default, Woocommerce doesn’t ship out reminder emails for the on-hold emails. With the assistance of this snippet right here you possibly can ship a customized reminder electronic mail for WooCommerce On-Maintain orders after two days of order completion.

NB! Take note of the road 8. In it, you possibly can change the remider delay.

<span position="button" tabindex="0" data-code="// Ship a customized reminder electronic mail for WooCommerce On-Maintain orders after two days of order completion

add_action( 'restrict_manage_posts', 'wpsh_payment_reminder' );
operate wpsh_payment_reminder() {
international $pagenow, $post_type;

if( 'shop_order' === $post_type && 'edit.php' === $pagenow
&& get_option( 'unpaid_orders_reminder_daily_process' ) < time() ) :

$days_delay = 2; // 24 hours
$one_day = 24 * 60 * 60;
$at present = strtotime( date('Y-m-d') );

$unpaid_orders = (array) wc_get_orders( array(
'restrict' => -1,
'standing' => 'on-hold',
'date_created' => '<' . ( $at present – ($days_delay * $one_day) ),
) );

if ( sizeof($unpaid_orders) > 0 ) {
$reminder_text = __("Fee reminder electronic mail despatched to buyer $at present.", "woocommerce");

foreach ( $unpaid_orders as $order ) {
$order->update_meta_data( '_send_on_hold', true );
$order->update_status( 'reminder', $reminder_text );

$wc_emails = WC()->mailer()->get_emails(); // Get all WC_emails objects situations
$wc_emails['WC_Email_Customer_On_Hold_Order']->set off( $order->get_id() ); // Ship electronic mail
}
}
update_option( 'unpaid_orders_reminder_daily_process', $at present + $one_day );

endif;
}

add_action ( 'woocommerce_email_order_details', 'wpsh_payment_reminder_notification', 5, 4 );
operate wpsh_payment_reminder_notification( $order, $sent_to_admin, $plain_text, $electronic mail ){
if ( 'customer_on_hold_order' == $email->id && $order->get_meta('_send_on_hold') ){
$order_id = $order->get_id();
$order_link = wc_get_page_permalink('myaccount').'view-order/'.$order_id.'/';
$order_number = $order->get_order_number();

echo '<h2>'.__("Don’t forget about your order.").'</h2>
<p>'.sprintf( __("CUSTOM MESSAGE HERE… %s"),
'<a href="'.$order_link.'">'.__("Your My account order #").$order_number.'<a>'
) .'

// Ship a customized reminder electronic mail for WooCommerce On-Maintain orders after two days of order completion

add_action( 'restrict_manage_posts', 'wpsh_payment_reminder' );
operate wpsh_payment_reminder() {
    international $pagenow, $post_type;

    if( 'shop_order' === $post_type && 'edit.php' === $pagenow
        && get_option( 'unpaid_orders_reminder_daily_process' ) < time() ) :

    $days_delay = 2; // 24 hours
    $one_day    = 24 * 60 * 60;
    $at present      = strtotime( date('Y-m-d') );

    $unpaid_orders = (array) wc_get_orders( array(
        'restrict'        => -1,
        'standing'       => 'on-hold',
        'date_created' => '<' . ( $at present - ($days_delay * $one_day) ),
    ) );

    if ( sizeof($unpaid_orders) > 0 ) {
        $reminder_text = __("Fee reminder electronic mail despatched to buyer $at present.", "woocommerce");

        foreach ( $unpaid_orders as $order ) {
            $order->update_meta_data( '_send_on_hold', true );
            $order->update_status( 'reminder', $reminder_text );

            $wc_emails = WC()->mailer()->get_emails(); // Get all WC_emails objects situations
            $wc_emails['WC_Email_Customer_On_Hold_Order']->set off( $order->get_id() ); // Ship electronic mail
        }
    }
    update_option( 'unpaid_orders_reminder_daily_process', $at present + $one_day );

    endif;
}

add_action ( 'woocommerce_email_order_details', 'wpsh_payment_reminder_notification', 5, 4 );
operate wpsh_payment_reminder_notification( $order, $sent_to_admin, $plain_text, $electronic mail ){
    if ( 'customer_on_hold_order' == $electronic mail->id && $order->get_meta('_send_on_hold') ){
        $order_id     = $order->get_id();
        $order_link   = wc_get_page_permalink('myaccount').'view-order/'.$order_id.'/';
        $order_number = $order->get_order_number();

        echo '<h2>'.__("Don't forget about your order.").'</h2>
        <p>'.sprintf( __("CUSTOM MESSAGE HERE… %s"), 
            '<a href="'.$order_link.'">'.__("Your My account order #").$order_number.'<a>'
        ) .'</p>';

        $order->delete_meta_data('_send_on_hold');
        $order->save();
    }
}

The right way to create customized order standing for Woocommerce?

Now let’s check out find out how to create customized order standing for Woocommerce. With the assistance of this snippet I’m going to create a customized standing referred to as “In-progress” that’s displayed on each backend and front-end order pages.

<span position="button" tabindex="0" data-code="// Add customized Woocommerce order standing
operate register_in_progress_order_status() {
register_post_status( 'wc-invoiced', array(
'label' => _x( 'In-progress', 'Order Standing', 'woocommerce' ),
'public' => true,
'exclude_from_search' => false,
'show_in_all_admin_list' => true,
'show_in_admin_status_list' => true,
'label_count' => _n_noop( 'In-progress <span class="rely">(%s)</span>', 'In-progress <span class="rely">(%s)</span>', 'woocommerce' )
)
);
}

add_action( 'init', 'register_in_progress_order_status' );

operate my_invoiced_order_status( $order_statuses ){
$order_statuses['wc-invoiced'] = _x( 'In-progress', 'Order Standing', 'woocommerce' );
return $order_statuses;

}
add_filter( 'wc_order_statuses', 'my_invoiced_order_status' );

operate show_in_bulk_actions() {
international $post_type;

if( 'shop_order' == $post_type ) {
?>
<script sort="textual content/javascript">
jQuery(doc).prepared(operate(){
jQuery('<choice>').val('mark_invoiced').textual content('<?php _e( 'Change Standing to In-progress','woocommerce' ); ?>').appendTo("choose[name='action']");
jQuery('<choice>').val('mark_invoiced').textual content('<?php _e( 'Change Standing to In-progress','woocommerce' ); ?>').appendTo("choose[name='action2']");
});
</script>

// Add customized Woocommerce order standing
operate register_in_progress_order_status() {
    register_post_status( 'wc-invoiced', array(
            'label' => _x( 'In-progress', 'Order Standing', 'woocommerce' ),
            'public' => true,
            'exclude_from_search' => false,
            'show_in_all_admin_list' => true,
            'show_in_admin_status_list' => true,
            'label_count' => _n_noop( 'In-progress <span class="rely">(%s)</span>', 'In-progress <span class="rely">(%s)</span>', 'woocommerce' )
        )
    );
}

add_action( 'init', 'register_in_progress_order_status' );

operate my_invoiced_order_status( $order_statuses ){
    $order_statuses['wc-invoiced'] = _x( 'In-progress', 'Order Standing', 'woocommerce' );
    return $order_statuses;

}
add_filter( 'wc_order_statuses', 'my_invoiced_order_status' );

operate show_in_bulk_actions() {
    international $post_type;

    if( 'shop_order' == $post_type ) {
        ?>
            <script sort="textual content/javascript">
                jQuery(doc).prepared(operate(){
                    jQuery('<choice>').val('mark_invoiced').textual content('<?php _e( 'Change Standing to In-progress','woocommerce' ); ?>').appendTo("choose[name='action']");
                    jQuery('<choice>').val('mark_invoiced').textual content('<?php _e( 'Change Standing to In-progress','woocommerce' ); ?>').appendTo("choose[name='action2']");
                });
            </script>
        <?php
    }
}
add_action( 'admin_footer', 'show_in_bulk_actions' );

The right way to Filter Woocommerce orders by coupons used?

If you want to know find out how to filter Woocommerce orders by coupons used, then it’s only a snippet away. That’s, use this one right here beneath.

<span position="button" tabindex="0" data-code="// Filter Woocommerce orders by coupons used
outlined( 'ABSPATH' ) or exit;

// fireplace it up!
add_action( 'plugins_loaded', 'wc_filter_orders_by_coupon' );

class WC_Filter_Orders_By_Coupon {
const VERSION = '1.1.0';

/** @var WC_Filter_Orders_By_Coupon single occasion of this plugin */
protected static $occasion;
public operate __construct() {

// load translations
add_action( 'init', array( $this, 'load_translation' ) );
if ( is_admin() && ! outlined( 'DOING_AJAX' ) ) {

// provides the coupon filtering dropdown to the orders web page
add_action( 'restrict_manage_posts', array( $this, 'filter_orders_by_coupon_used' ) );

// makes coupons filterable
add_filter( 'posts_join', array( $this, 'add_order_items_join' ) );
add_filter( 'posts_where', array( $this, 'add_filterable_where' ) );
}
}

public operate filter_orders_by_coupon_used() {
international $typenow;

if ( 'shop_order' === $typenow ) {

$args = array(
'posts_per_page' => – 1,
'orderby' => 'title',
'order' => 'asc',
'post_type' => 'shop_coupon',
'post_status' => 'publish',
);

$coupons = get_posts( $args );

if ( ! empty( $coupons ) ) : ?>

<choose title="_coupons_used" id="dropdown_coupons_used">
<choice worth="">
<?php esc_html_e( 'Filter by coupon used', 'wc-filter-orders' ); ?>
</choice>
<?php foreach ( $coupons as $coupon ) : ?>
<choice worth="<?php echo esc_attr( $coupon->post_title ); ?>" <?php echo esc_attr( isset( $_GET['_coupons_used'] ) ? chosen( $coupon->post_title, $_GET['_coupons_used'], false ) : '' ); ?>>
<?php echo esc_html( $coupon->post_title ); ?>
</choice>
<?php endforeach; ?>
</choose>

// Filter Woocommerce orders by coupons used
outlined( 'ABSPATH' ) or exit;

// fireplace it up!
add_action( 'plugins_loaded', 'wc_filter_orders_by_coupon' );

 class WC_Filter_Orders_By_Coupon {
	const VERSION = '1.1.0';

	/** @var WC_Filter_Orders_By_Coupon single occasion of this plugin */
	protected static $occasion;
	public operate __construct() {

		// load translations
		add_action( 'init', array( $this, 'load_translation' ) );
		if ( is_admin() && ! outlined( 'DOING_AJAX' ) ) {

			// provides the coupon filtering dropdown to the orders web page
			add_action( 'restrict_manage_posts', array( $this, 'filter_orders_by_coupon_used' ) );

			// makes coupons filterable
			add_filter( 'posts_join',  array( $this, 'add_order_items_join' ) );
			add_filter( 'posts_where', array( $this, 'add_filterable_where' ) );
		}
	}

	public operate filter_orders_by_coupon_used() {
		international $typenow;

		if ( 'shop_order' === $typenow ) {

			$args = array(
				'posts_per_page' => - 1,
				'orderby'        => 'title',
				'order'          => 'asc',
				'post_type'      => 'shop_coupon',
				'post_status'    => 'publish',
			);

			$coupons = get_posts( $args );

			if ( ! empty( $coupons ) ) : ?>

				<choose title="_coupons_used" id="dropdown_coupons_used">
					<choice worth="">
						<?php esc_html_e( 'Filter by coupon used', 'wc-filter-orders' ); ?>
					</choice>
					<?php foreach ( $coupons as $coupon ) : ?>
						<choice worth="<?php echo esc_attr( $coupon->post_title ); ?>" <?php echo esc_attr( isset( $_GET['_coupons_used'] ) ? chosen( $coupon->post_title, $_GET['_coupons_used'], false ) : '' ); ?>>
							<?php echo esc_html( $coupon->post_title ); ?>
						</choice>
					<?php endforeach; ?>
				</choose>
			<?php endif;
		}
	}

	public operate add_order_items_join( $be a part of ) {
		international $typenow, $wpdb;

		if ( 'shop_order' === $typenow && isset( $_GET['_coupons_used'] ) && ! empty( $_GET['_coupons_used'] ) ) {

			$be a part of .= "LEFT JOIN {$wpdb->prefix}woocommerce_order_items woi ON {$wpdb->posts}.ID = woi.order_id";
		}

		return $be a part of;
	}

	public operate add_filterable_where( $the place ) {
		international $typenow, $wpdb;

		if ( 'shop_order' === $typenow && isset( $_GET['_coupons_used'] ) && ! empty( $_GET['_coupons_used'] ) ) {

			// Essential WHERE question half
			$the place .= $wpdb->put together( " AND woi.order_item_type='coupon' AND woi.order_item_name='%s'", wc_clean( $_GET['_coupons_used'] ) );
		}

		return $the place;
	}

	public operate load_translation() {
		// localization
		load_plugin_textdomain( 'wc-filter-orders', false, dirname( plugin_basename( __FILE__ ) ) . '/i18n/languages' );
	}

	public static operate occasion() {
		if ( is_null( self::$occasion ) ) {
		 	self::$occasion = new self();
		}
		return self::$occasion;
	}

	public operate __clone() {
		/* translators: Placeholders: %s - plugin title */
		_doing_it_wrong( __FUNCTION__, sprintf( esc_html__( 'You can not clone situations of %s.', 'wc-filter-orders' ), 'Filter WC Orders by Coupon' ), '1.1.0' );
	}

	public operate __wakeup() {
		/* translators: Placeholders: %s - plugin title */
		_doing_it_wrong( __FUNCTION__, sprintf( esc_html__( 'You can not unserialize situations of %s.', 'wc-filter-orders' ), 'Filter WC Orders by Coupon' ), '1.1.0' );
	}
}

operate wc_filter_orders_by_coupon() {
	return WC_Filter_Orders_By_Coupon::occasion();
}

The right way to filter WooCommerce orders by fee methodology?

Now let’s see find out how to filter WooCommerce orders by fee methodology. Simply use this snippet right here beneath.

<span position="button" tabindex="0" data-code="// Filter Woocommerce orders by fee methodology
outlined( 'ABSPATH' ) or exit;

// fireplace it up!
add_action( 'plugins_loaded', 'wc_filter_orders_by_payment' );

class WC_Filter_Orders_By_Payment {

const VERSION = '1.0.0';

/** @var WC_Filter_Orders_By_Payment single occasion of this plugin */
protected static $occasion;

public operate __construct() {

if ( is_admin() ) {

// add bulk order filter for exported / non-exported orders
add_action( 'restrict_manage_posts', array( $this, 'filter_orders_by_payment_method') , 20 );
add_filter( 'request', array( $this, 'filter_orders_by_payment_method_query' ) );
}
}

public operate filter_orders_by_payment_method() {
international $typenow;

if ( 'shop_order' === $typenow ) {

// get all fee strategies, even inactive ones
$gateways = WC()->payment_gateways->payment_gateways();

?>
<choose title="_shop_order_payment_method" id="dropdown_shop_order_payment_method">
<choice worth="">
<?php esc_html_e( 'All Fee Strategies', 'wc-filter-orders-by-payment' ); ?>
</choice>

<?php foreach ( $gateways as $id => $gateway ) : ?>
<choice worth="<?php echo esc_attr( $id ); ?>" <?php echo esc_attr( isset( $_GET['_shop_order_payment_method'] ) ? chosen( $id, $_GET['_shop_order_payment_method'], false ) : '' ); ?>>
<?php echo esc_html( $gateway->get_method_title() ); ?>
</choice>
<?php endforeach; ?>
</choose>

// Filter Woocommerce orders by fee methodology
outlined( 'ABSPATH' ) or exit;

// fireplace it up!
add_action( 'plugins_loaded', 'wc_filter_orders_by_payment' );

class WC_Filter_Orders_By_Payment {

	const VERSION = '1.0.0';

	/** @var WC_Filter_Orders_By_Payment single occasion of this plugin */
	protected static $occasion;

	public operate __construct() {

		if ( is_admin() ) {

			// add bulk order filter for exported / non-exported orders
			add_action( 'restrict_manage_posts', array( $this, 'filter_orders_by_payment_method') , 20 );
			add_filter( 'request',               array( $this, 'filter_orders_by_payment_method_query' ) );		
		}
	}

	public operate filter_orders_by_payment_method() {
		international $typenow;

		if ( 'shop_order' === $typenow ) {

			// get all fee strategies, even inactive ones
			$gateways = WC()->payment_gateways->payment_gateways();

			?>
			<choose title="_shop_order_payment_method" id="dropdown_shop_order_payment_method">
				<choice worth="">
					<?php esc_html_e( 'All Fee Strategies', 'wc-filter-orders-by-payment' ); ?>
				</choice>

				<?php foreach ( $gateways as $id => $gateway ) : ?>
				<choice worth="<?php echo esc_attr( $id ); ?>" <?php echo esc_attr( isset( $_GET['_shop_order_payment_method'] ) ? chosen( $id, $_GET['_shop_order_payment_method'], false ) : '' ); ?>>
					<?php echo esc_html( $gateway->get_method_title() ); ?>
				</choice>
				<?php endforeach; ?>
			</choose>
			<?php
		}
	}
	public operate filter_orders_by_payment_method_query( $vars ) {
		international $typenow;
		if ( 'shop_order' === $typenow && isset( $_GET['_shop_order_payment_method'] ) && ! empty( $_GET['_shop_order_payment_method'] ) ) {

			$vars['meta_key']   = '_payment_method';
			$vars['meta_value'] = wc_clean( $_GET['_shop_order_payment_method'] );
		}
		return $vars;
	}
	public static operate occasion() {
		if ( is_null( self::$occasion ) ) {
			self::$occasion = new self();
		}
		return self::$occasion;
	}
}

operate wc_filter_orders_by_payment() {
    return WC_Filter_Orders_By_Payment::occasion();
}

The right way to filter Woocommerce orders by person position?

Subsequent, let’s filter Woocommerce orders by person position. The tip result’s the one you see on the screenshot right here beneath.

How to Customize Woocommerce Orders page?
<span position="button" tabindex="0" data-code="// Filter Woocommerce orders by person position

operate wpsh_user_role_filter() {

international $typenow, $wp_query;

if ( in_array( $typenow, wc_get_order_types( 'order-meta-boxes' ) ) ) {
$user_role = '';

// Get all person roles
$user_roles = array( 'visitor' => 'Visitor' );
foreach ( get_editable_roles() as $key => $values ) {
$user_roles[ $key ] = $values['name'];
}

// Set a particular person position
if ( ! empty( $_GET['_user_role'] ) ) {
$user_role = sanitize_text_field( $_GET['_user_role'] );
}

// Show drop down
?><choose title='_user_role'>
<choice worth=''><?php _e( 'Choose a person position', 'woocommerce' ); ?></choice><?php
foreach ( $user_roles as $key => $worth ) :
?><choice <?php chosen( $user_role, $key ); ?> worth='<?php echo $key; ?>'><?php echo $worth; ?></choice><?php
endforeach;
?></choose>

// Filter Woocommerce orders by person position

operate wpsh_user_role_filter() {

	international $typenow, $wp_query;

	if ( in_array( $typenow, wc_get_order_types( 'order-meta-boxes' ) ) ) {
		$user_role	= '';

		// Get all person roles
		$user_roles = array( 'visitor' => 'Visitor' );
		foreach ( get_editable_roles() as $key => $values ) {
			$user_roles[ $key ] = $values['name'];
		}

		// Set a particular person position
		if ( ! empty( $_GET['_user_role'] ) ) {
			$user_role	= sanitize_text_field( $_GET['_user_role'] );
		}

		// Show drop down
		?><choose title='_user_role'>
			<choice worth=''><?php _e( 'Choose a person position', 'woocommerce' ); ?></choice><?php
			foreach ( $user_roles as $key => $worth ) :
				?><choice <?php chosen( $user_role, $key ); ?> worth='<?php echo $key; ?>'><?php echo $worth; ?></choice><?php
			endforeach;
		?></choose><?php
	}

}
add_action( 'restrict_manage_posts', 'wpsh_user_role_filter' );

operate wpsh_user_role_filter_where( $question ) {

	if ( ! $question->is_main_query() || empty( $_GET['_user_role'] ) || $_GET['post_type'] !== 'shop_order' ) {
		return;
	}

	if ( $_GET['_user_role'] != 'visitor' ) {
		$ids = get_users( array( 'position' => sanitize_text_field( $_GET['_user_role'] ), 'fields' => 'ID' ) );
		$ids = array_map( 'absint', $ids );
	} else {
		$ids = array( 0 );
	}

	$question->set( 'meta_query', array(
		array(
			'key' => '_customer_user',
			'evaluate' => 'IN',
			'worth' => $ids,
		)
	) );

	if ( empty( $ids ) ) {
		$question->set( 'posts_per_page', 0 );
	}
}
add_filter( 'pre_get_posts', 'wpsh_user_role_filter_where' );

The right way to show used coupons on WooCommerce admin orders listing?

If you want to show used coupons on WooCommerce admin orders listing then use this snippet right here beneath. If no coupons is used then “No coupons used” is displayed. See the screenshot above.

<span position="button" tabindex="0" data-code="// Show used coupons on WooCommerce admin orders listing
add_filter( 'manage_edit-shop_order_columns', 'woo_customer_order_coupon_column_for_orders' );
operate woo_customer_order_coupon_column_for_orders( $columns ) {
$new_columns = array();

foreach ( $columns as $column_key => $column_label ) {
if ( 'order_total' === $column_key ) {
$new_columns['order_coupons'] = __('Coupons', 'woocommerce');
}

$new_columns[$column_key] = $column_label;
}
return $new_columns;
}

add_action( 'manage_shop_order_posts_custom_column' , 'woo_display_customer_order_coupon_in_column_for_orders' );
operate woo_display_customer_order_coupon_in_column_for_orders( $column ) {
international $the_order, $submit;
if( $column == 'order_coupons' ) {
if( $coupons = $the_order->get_coupon_codes() ) {
echo implode(', ', $coupons) . ' ('.rely($coupons).')';
} else {
echo '<small><em>'. __('No coupon used') . '</em>

// Show used coupons on WooCommerce admin orders listing
add_filter( 'manage_edit-shop_order_columns', 'woo_customer_order_coupon_column_for_orders' );
operate woo_customer_order_coupon_column_for_orders( $columns ) {
    $new_columns = array();

    foreach ( $columns as $column_key => $column_label ) {
        if ( 'order_total' === $column_key ) {
            $new_columns['order_coupons'] = __('Coupons', 'woocommerce');
        }

        $new_columns[$column_key] = $column_label;
    }
    return $new_columns;
}

add_action( 'manage_shop_order_posts_custom_column' , 'woo_display_customer_order_coupon_in_column_for_orders' );
operate woo_display_customer_order_coupon_in_column_for_orders( $column ) {
    international $the_order, $submit;
    if( $column  == 'order_coupons' ) {
        if( $coupons = $the_order->get_coupon_codes() ) {
            echo implode(', ', $coupons) . ' ('.rely($coupons).')';
        } else {
            echo '<small><em>'. __('No coupon used') . '</em></small>';
        }
    }
}

The right way to show used coupons on Woocommerce order preview template?

With the earlier snippet we’re displaying coupons within the Woocommerce admin orders listing. Now, with the assistance of this one right here we’re going to show used coupons on Woocommerce order preview template.

<span position="button" tabindex="0" data-code="// Show used coupons on Woocommerce order preview template

add_filter( 'woocommerce_admin_order_preview_get_order_details', 'wpsh_coupon_in_order_preview', 10, 2 );
operate wpsh_coupon_in_order_preview( $information, $order ) {
// Substitute '_custom_meta_key' by the proper postmeta key
if( $coupons = $order->get_used_coupons() ) {
$information['coupons_count'] = rely($coupons); // <= Retailer the rely within the information array.
$information['coupons_codes'] = implode(', ', $coupons); // <= Retailer the rely within the information array.
}
return $information;
}
// Show coupon in Order preview
add_action( 'woocommerce_admin_order_preview_end', 'wpsh_coupon_in_order_preview_data' );
operate wpsh_coupon_in_order_preview_data(){
// Name the saved worth and show it
echo '<div><robust>' . __('Coupons used') . ' ({{information.coupons_count}})<robust>: {{information.coupons_codes}}</div>

// Show used coupons on Woocommerce order preview template

add_filter( 'woocommerce_admin_order_preview_get_order_details', 'wpsh_coupon_in_order_preview', 10, 2 );
operate wpsh_coupon_in_order_preview( $information, $order ) {
    // Substitute '_custom_meta_key' by the proper postmeta key
    if( $coupons = $order->get_used_coupons() ) {
        $information['coupons_count'] = rely($coupons); // <= Retailer the rely within the information array.
        $information['coupons_codes'] = implode(', ', $coupons); // <= Retailer the rely within the information array.
    }
    return $information;
}
// Show coupon in Order preview
add_action( 'woocommerce_admin_order_preview_end', 'wpsh_coupon_in_order_preview_data' );
operate wpsh_coupon_in_order_preview_data(){
    // Name the saved worth and show it
    echo '<div><robust>' . __('Coupons used') . ' ({{information.coupons_count}})<robust>: {{information.coupons_codes}}</div><br>';
}

The right way to show buyer telephone and electronic mail in Woocommerce orders desk?

Check out the screenshot beneath, and also you’ll see that there’s a buyer telephone and electronic mail that’s displayed in Woocommerce orders desk. If you want to realize the identical outcome, then use this snippet right here beneath.

Display customer email in Woocommerce orders table
<span position="button" tabindex="0" data-code="// Show buyer telephone and electronic mail in Woocommerce orders desk
add_action( 'manage_shop_order_posts_custom_column' , 'wpsh_phone_and_email_column', 50, 2 );
operate wpsh_phone_and_email_column( $column, $post_id ) {
if ( $column == 'order_number' )
{
international $the_order;
// Show buyer telephone in Woocommerce orders desk
if( $telephone = $the_order->get_billing_phone() ){
$phone_wp_dashicon = '<span class="dashicons dashicons-phone"></span> ';
echo '<br><a href="tel:'.$telephone.'">' . $phone_wp_dashicon . $telephone.'</a></robust>';
}
// Show buyer electronic mail in Woocommerce orders desk
if( $electronic mail = $the_order->get_billing_email() ){
echo '<br><robust><a href="mailto:'.$electronic mail.'">' . $electronic mail . '</a>

// Show buyer telephone and electronic mail in Woocommerce orders desk
add_action( 'manage_shop_order_posts_custom_column' , 'wpsh_phone_and_email_column', 50, 2 );
operate wpsh_phone_and_email_column( $column, $post_id ) {
    if ( $column == 'order_number' )
    {
        international $the_order;
 // Show buyer telephone in Woocommerce orders desk
        if( $telephone = $the_order->get_billing_phone() ){
            $phone_wp_dashicon = '<span class="dashicons dashicons-phone"></span> ';
            echo '<br><a href="tel:'.$telephone.'">' . $phone_wp_dashicon . $telephone.'</a></robust>';
        }
	 // Show buyer electronic mail in Woocommerce orders desk
	          if( $electronic mail = $the_order->get_billing_email() ){
            echo '<br><robust><a href="mailto:'.$electronic mail.'">' . $electronic mail . '</a></robust>';
        }
    }
}

The right way to add customized button to Woocommerce orders web page (and merchandise web page)

It’s time so as to add customized button to Woocommerce orders web page (and merchandise web page). See the screenshot.

Add custom button to Woocommerce orders page
<span position="button" tabindex="0" data-code="// Add customized button to Woocommerce orders web page
add_action( 'manage_posts_extra_tablenav', 'wpsh_button_on_orders_page', 20, 1 );
operate wpsh_button_on_orders_page( $which ) {
international $typenow;

if ( 'shop_order' === $typenow && 'prime' === $which ) {
?>
<div class="alignright actions customized">
<button sort="submit" title="custom_" type="top:32px;" class="button" worth=""><?php
// Change your URL and button textual content right here
echo __( '<a method="text-decoration: none;" href="/wp-admin/edit.php?post_type=product">
Go to merchandise »
</a>', 'woocommerce' ); ?></button>
</div>
<?php
}
}
// Add customized button to Woocommerce merchandise web page
add_action( 'manage_posts_extra_tablenav', 'wpsh_button_on_products_page', 20, 1 );
operate wpsh_button_on_products_page( $which ) {
international $typenow;

if ( 'product' === $typenow && 'prime' === $which ) {
?>
<div class="alignleft actions customized">
<button sort="submit" title="custom_" type="top:32px;" class="button" worth=""><?php
// Change your URL and button textual content right here
echo __( '<a method="text-decoration: none;" href="/wp-admin/edit.php?post_type=shop_order">
Go to orders »
</a>', 'woocommerce' ); ?></button>
</div>

// Add customized button to Woocommerce orders web page 
add_action( 'manage_posts_extra_tablenav', 'wpsh_button_on_orders_page', 20, 1 );
operate wpsh_button_on_orders_page( $which ) {
    international $typenow;

    if ( 'shop_order' === $typenow && 'prime' === $which ) {
        ?>
        <div class="alignright actions customized">
            <button sort="submit" title="custom_" type="top:32px;" class="button"  worth=""><?php
	  // Change your URL and button textual content right here
                echo __( '<a method="text-decoration: none;" href="/wp-admin/edit.php?post_type=product">
				Go to merchandise »
				</a>', 'woocommerce' ); ?></button>
        </div>
        <?php
    }
}
// Add customized button to Woocommerce merchandise web page 
add_action( 'manage_posts_extra_tablenav', 'wpsh_button_on_products_page', 20, 1 );
operate wpsh_button_on_products_page( $which ) {
    international $typenow;

    if ( 'product' === $typenow && 'prime' === $which ) {
        ?>
        <div class="alignleft actions customized">
            <button sort="submit" title="custom_" type="top:32px;" class="button"  worth=""><?php
	  	  // Change your URL and button textual content right here
                echo __( '<a method="text-decoration: none;" href="/wp-admin/edit.php?post_type=shop_order">
				Go to orders »
				</a>', 'woocommerce' ); ?></button>
        </div>
        <?php
    }
}

The right way to set default Woocommerce login web page to “Orders” web page?

This snippet right here beneath will redirect you to the Woocommerce “Orders” after login.

// Set default Woocommerce login web page to "Orders" web page
add_action( 'load-index.php', 'wpsh_redirect_to_orders' );
operate wpsh_redirect_to_orders(){
    wp_redirect( admin_url( 'edit.php?post_type=shop_order' ) );
}
add_filter( 'login_redirect', 'wpsh_redirect_to_orders_dashboard', 9999, 3 );
operate wpsh_redirect_to_orders_dashboard( $redirect_to, $request, $person ){
    $redirect_to = admin_url( 'edit.php?post_type=shop_order' );
    return $redirect_to;
}

The right way to autocomplete Woocommerce processing orders?

Why would you should autocomplete Woocommerce processing orders? For instance, if you happen to’re promoting digital product (Programs and so on.) and also you want to add an entry to it proper after funds.

// Autocomplete Woocommerce processing orders

add_filter( 'woocommerce_payment_complete_order_status', 'processing_orders_autocomplete', 9999 );
operate processing_orders_autocomplete() {
   return 'accomplished';
}

The right way to autocomplete all Woocommerce orders?

However (simply “however) what if you want to autocomplete all Woocommerce orders? That’s evan on-hold orders? If that is so then use this nippet right here beneath.

// Auto Full all WooCommerce orders.

add_action( 'woocommerce_thankyou', 'wpsh_complete_all_orders' );
operate wpsh_complete_all_orders( $order_id ) { 
    if ( ! $order_id ) {
        return;
    }
    $order = wc_get_order( $order_id );
    $order->update_status( 'accomplished' );
}

The right way to add the product picture to Woocommerce my account order view at My account web page?

What do I imply by that? Check out the screenshot beneath, and also you’ll see that there’s a picture on Woocommerce orders view at My account web page.

Add the product image to Woocommerce my account order view
<span position="button" tabindex="0" data-code="// Show the product thumbnail in Woocommerce order view pages
add_filter( 'woocommerce_order_item_name', 'wpsh_display_product_image_in_order_item', 20, 3 );
operate wpsh_display_product_image_in_order_item( $item_name, $merchandise, $is_visible ) {
// Focusing on view order pages solely
if( is_wc_endpoint_url( 'view-order' ) ) {
$product = $item->get_product(); // Get the WC_Product object (from order merchandise)
$thumbnail = $product->get_image(array( 50, 50)); // Get the product thumbnail (from product object)
if( $product->get_image_id() > 0 )
$item_name = '<div class="item-thumbnail">' . $thumbnail . '

// Show the product thumbnail in Woocommerce order view pages
add_filter( 'woocommerce_order_item_name', 'wpsh_display_product_image_in_order_item', 20, 3 );
operate wpsh_display_product_image_in_order_item( $item_name, $merchandise, $is_visible ) {
    // Focusing on view order pages solely
    if( is_wc_endpoint_url( 'view-order' ) ) {
        $product   = $merchandise->get_product(); // Get the WC_Product object (from order merchandise)
        $thumbnail = $product->get_image(array( 50, 50)); // Get the product thumbnail (from product object)
        if( $product->get_image_id() > 0 )
            $item_name = '<div class="item-thumbnail">' . $thumbnail . '</div>' . $item_name;
    }
    return $item_name;
}

The right way to Add Bought merchandise tab to Woocommerce my account web page?

Now let’s add Bought merchandise tab to Woocommerce my account web page (se the screenshot above). This tabb shows your not too long ago bought merchandise within the separate tabe.

<span position="button" tabindex="0" data-code="// Add Bought merchandise tab to Woocommerce my account web page

// right here we hook the My Account menu hyperlinks and add our customized one
add_filter( 'woocommerce_account_menu_items', 'wpsh_purchased_products', 40 );
operate wpsh_purchased_products( $menu_links ){

// Set 5 on this line to one thing else if you want to maneuver the place of the tab
return array_slice( $menu_links, 0, 5, true )
+ array( 'purchased-products' => 'Bought Merchandise' )
+ array_slice( $menu_links, 2, NULL, true );

}

add_action( 'init', 'wpsh_purchased_products_endpoint' );
operate wpsh_purchased_products_endpoint() {
add_rewrite_endpoint( 'purchased-products', EP_PAGES );
}

// Add bought porducts as a tab content material
add_action( 'woocommerce_account_purchased-products_endpoint', 'wpsh_purchased_products_content' );
operate wpsh_purchased_products_content() {

international $wpdb;

// Bought merchandise are sorted by date
$purchased_products_ids = $wpdb->get_col(
$wpdb->put together(
"
SELECT itemmeta.meta_value
FROM " . $wpdb->prefix . "woocommerce_order_itemmeta itemmeta
INNER JOIN " . $wpdb->prefix . "woocommerce_order_items gadgets
ON itemmeta.order_item_id = gadgets.order_item_id
INNER JOIN $wpdb->posts orders
ON orders.ID = gadgets.order_id
INNER JOIN $wpdb->postmeta ordermeta
ON orders.ID = ordermeta.post_id
WHERE itemmeta.meta_key = '_product_id'
AND ordermeta.meta_key = '_customer_user'
AND ordermeta.meta_value = %s
ORDER BY orders.post_date DESC
",
get_current_user_id()
)
);

// Don’t show duplicate merchandise
$purchased_products_ids = array_unique( $purchased_products_ids );
if( ! empty( $purchased_products_ids ) ) {

echo '<div class="woocommerce-message">Bought merchandise

// Add Bought merchandise tab to Woocommerce my account web page

// right here we hook the My Account menu hyperlinks and add our customized one
add_filter( 'woocommerce_account_menu_items', 'wpsh_purchased_products', 40 );
operate wpsh_purchased_products( $menu_links ){

// Set 5 on this line to one thing else if you want to maneuver the place of the tab
	return array_slice( $menu_links, 0, 5, true )
	+ array( 'purchased-products' => 'Bought Merchandise' )
	+ array_slice( $menu_links, 2, NULL, true );

}

add_action( 'init', 'wpsh_purchased_products_endpoint' );
operate wpsh_purchased_products_endpoint() {
	add_rewrite_endpoint( 'purchased-products', EP_PAGES );
}

// Add bought porducts as a tab content material
add_action( 'woocommerce_account_purchased-products_endpoint', 'wpsh_purchased_products_content' );
operate wpsh_purchased_products_content() {

	international $wpdb;

	// Bought merchandise are sorted by date
	$purchased_products_ids = $wpdb->get_col( 
		$wpdb->put together(
			"
			SELECT      itemmeta.meta_value
			FROM        " . $wpdb->prefix . "woocommerce_order_itemmeta itemmeta
			INNER JOIN  " . $wpdb->prefix . "woocommerce_order_items gadgets
			            ON itemmeta.order_item_id = gadgets.order_item_id
			INNER JOIN  $wpdb->posts orders
			            ON orders.ID = gadgets.order_id
			INNER JOIN  $wpdb->postmeta ordermeta
			            ON orders.ID = ordermeta.post_id
			WHERE       itemmeta.meta_key = '_product_id'
			            AND ordermeta.meta_key = '_customer_user'
			            AND ordermeta.meta_value = %s
			ORDER BY    orders.post_date DESC
			",
			get_current_user_id()
		)
	);

	// Don’t show duplicate merchandise
	$purchased_products_ids = array_unique( $purchased_products_ids );
	if( ! empty( $purchased_products_ids ) ) {
	  
	 echo '<div class="woocommerce-message">Bought merchandise</div>';
	  
		$purchased_products = new WP_Query( array(
			'post_type' => 'product',
			'post_status' => 'publish',
			'post__in' => $purchased_products_ids,
			'orderby' => 'post__in',
			'posts_per_page' => -1,
		) );
	
		woocommerce_product_loop_start();

		whereas ( $purchased_products->have_posts() ) : $purchased_products->the_post();

			wc_get_template_part( 'content material', 'product' );

		endwhile;

		woocommerce_product_loop_end();

		woocommerce_reset_loop();
		wp_reset_postdata();

	} else {
	  // Change this textual content if wanted)
		echo 'Sadly you haven't any purchases but';
	}
}

The right way to add “Cancel” button to Woocommerce my account web page?

Check out this screenshot right here. As you see, there are two customized buttons (“Cancel” and “Order once more” buttons). So, if you want so as to add “Cancel” button to Woocommerce my account web page, then use this snippet right here beneath.

NB! Concentrate on the line 8. In it you possibly can set the delay in days. At present it’s set to three dayst, that’s withnin 3 days it’s allowed to cancel the order.

How to add "Cancel" button to Woocommerce my account page?

// Add "Cancel" button to Woocommerce my account web page

add_filter( 'woocommerce_valid_order_statuses_for_cancel', 'wpsh_add_cancel_button', 20, 2 );
operate wpsh_add_cancel_button( $statuses, $order = '' ){

    // Set HERE the order statuses the place you need the cancel button to look
    $custom_statuses    = array( 'pending', 'processing', 'on-hold', 'failed' );

    // Set HERE the delay (in days)
    $length = 3; // 3 days

    // UPDATE: Get the order ID and the WC_Order object
    if( ! is_object( $order ) && isset($_GET['order_id']) )
        $order = wc_get_order( absint( $_GET['order_id'] ) );

    $delay = $length*24*60*60; // (length in seconds)
    $date_created_time  = strtotime($order->get_date_created()); // Creation date time stamp
    $date_modified_time = strtotime($order->get_date_modified()); // Modified date time stamp
    $now = strtotime("now"); // Now  time stamp

    // Utilizing Creation date time stamp
    if ( ( $date_created_time + $delay ) >= $now ) return $custom_statuses;
    else return $statuses;
}

The right way to add “Order once more” button to Woocommerce my account web page?

As menitonet above, we’re goint so as to add “Order once more” button to Woocommerce my account web page. Use this snippet right here beneath.

// Add "Order once more" button to Woocommerce my account web page
add_filter( 'woocommerce_my_account_my_orders_actions', 'wpsh_order_again_button', 9999, 2 );
    
operate wpsh_order_again_button( $actions, $order ) {
    if ( $order->has_status( 'accomplished' ) ) {
        $actions['order-again'] = array(
            'url' => wp_nonce_url( add_query_arg( 'order_again', $order->get_id(), wc_get_cart_url() ), 'woocommerce-order_again' ),
            'title' => __( 'Order once more', 'woocommerce' ),
        );
    }
    return $actions;
}

The right way to set Woocommerce my account web page orders show restrict?

By default, your Woocommerce “My account” shows a bunch of orders. If you want to set your personal Woocommerce “My account” web page orders show restrict, then use this snippet. With the assistance of it we’ll set the show restrict to five orders.

// Set Woocommerce my account web page orders show restrict
add_filter( 'woocommerce_my_account_my_orders_query', 'wpsh_my_account_orders_limit', 10, 1 );
operate wpsh_my_account_orders_limit( $args ) {
    // Set the submit per web page
    $args['limit'] = 5;
    return $args;
}

The right way to show merchandise title and amount in a brand new column on Woocommerce “My account” web page orders desk?

Check out the “The right way to add “Cancel” button to Woocommerce my account web page?” part above. There’s a screenshot and also you’ll see that in it I show merchandise title and amount in a brand new column on Woocommerce “My account” web page orders desk. So, if you want to perform the identical outcome, simply use this snippet right here beneath.

<span position="button" tabindex="0" data-code="// Show The right way to show merchandise title and amount in a brand new column on Woocommerce "My account" web page orders desk

add_filter( 'woocommerce_my_account_my_orders_columns', 'wpsh_product_column', 10, 1 );
operate wpsh_product_column( $columns ) {
$new_columns = [];

foreach ( $columns as $key => $title ) {
$new_columns[ $key ] = $title;

if ( 'order-status' === $key ) Qty', 'woocommerce' );

}
return $new_columns;
}

add_action( 'woocommerce_my_account_my_orders_column_order-items', 'wpsh_product_column_content', 10, 1 );
operate wpsh_product_column_content( $order ) {
$particulars = array();

foreach( $order->get_items() as $merchandise )
$particulars[] = $item->get_name() . ' &occasions; ' . $item->get_quantity();

echo rely( $particulars ) > 0 ? implode( '

// Show The right way to show merchandise title and amount in a brand new column on Woocommerce "My account" web page orders desk

add_filter( 'woocommerce_my_account_my_orders_columns', 'wpsh_product_column', 10, 1 );
operate wpsh_product_column( $columns ) {
    $new_columns = [];

    foreach ( $columns as $key => $title ) {
        $new_columns[ $key ] = $title;

        if ( 'order-status' === $key )  Qty', 'woocommerce' );
        
    }
    return $new_columns;
}

add_action( 'woocommerce_my_account_my_orders_column_order-items', 'wpsh_product_column_content', 10, 1 );
operate wpsh_product_column_content( $order ) {
    $particulars = array();

    foreach( $order->get_items() as $merchandise )
        $particulars[] = $merchandise->get_name() . ' × ' . $merchandise->get_quantity();

    echo rely( $particulars ) > 0 ? implode( '<br>', $particulars ) : '–';
}

The right way to Hyperlink earlier WooCommerce visitor orders to buyer account after registration?

This snippet permits you to hyperlink earlier WooCommerce visitor orders to buyer account after registration.

// Hyperlink earlier WooCommerce visitor orders to buyer account after registration
operate action_woocommerce_created_customer( $customer_id, $new_customer_data, $password_generated ) {
    // Hyperlink previous orders to this newly created buyer
    wc_update_new_customer_past_orders( $customer_id );
}
add_action( 'woocommerce_created_customer', 'action_woocommerce_created_customer', 10, 3 ); 

Woocommerce hacks sequence

  • The right way to Cover Woocommerce Transport Strategies (Conditionally) – A Full Information

  • The right way to show Woocommerce my account tabs horizontally?

  • The right way to Customise Woocommerce Admin Dashboard? 16 hacks

  • The right way to Show Woocommerce Fee Strategies Conditionally? (14 hacks)

  • The right way to Customise Woocommerce Inventory Standing? (17 hacks)

  • The right way to Add Customized Endpoints in WooCommerce?

  • The right way to Create Customized Product Badges for Woocommerce?

Leave a Comment

Your email address will not be published. Required fields are marked *

Shopping Cart
Scroll to Top