On this tutorial I’m going to point out you find out how to customise Woocommerce admin dashboard with 16 easy hacks. These hacks are straightforward to implement and can take mainly no time to implement.
NB! To be able to use all these snippets proven on this put up you want add them inside your baby theme’s features.php file or higher but, use Code Snippets plugin. This fashion you’re not going to lose these modifications in case you’re switching your theme.
Additionally, check out the video tutorial right here beneath after which it’ll in all probability be a bit simpler to know what’s what.
Video: The way to Customise Woocommerce Admin Dashboard?
The way to set default Woocommerce login web page to “Orders”?
When is that this useful? Nicely, perhaps 80% of your work is both modifying orders or including product. Due to this fact, as a substitute of being directed to WordPress dashboard it will be sensible to let your self be redirected to orders (or product web page. This snippet permits you to be redirected to orders web page.
// Set default Woocommerce login web page to "Orders" web page
add_action( 'load-index.php', 'redirect_to_orders' );
operate redirect_to_orders(){
wp_redirect( admin_url( 'edit.php?post_type=shop_order' ) );
}
add_filter( 'login_redirect', 'redirect_to_orders_dashboard', 9999, 3 );
operate redirect_to_orders_dashboard( $redirect_to, $request, $person ){
$redirect_to = admin_url( 'edit.php?post_type=shop_order' );
return $redirect_to;
}
The way to redirect Store supervisor to “Order” web page after login?
If you want solely your store supervisor person position to be redirected to Orders web page after login then use this code right here beneath.
// Redirect Store supervisor to "Order" web page after login
operate is_shop_manager() {
$person = wp_get_current_user();
if ( isset( $person->roles[0] ) && $person->roles[0] == 'shop_manager' ) {
return true; // when person is store supervisor
} else {
return false; // when person will not be store supervisor
}
}
if ( is_shop_manager() ) {
add_action( 'load-index.php', 'redirect_to_orders' );
operate redirect_to_orders(){
wp_redirect( admin_url( 'edit.php?post_type=shop_order' ) );
}
add_filter( 'login_redirect', 'redirect_to_orders_dashboard', 9999, 3 );
operate redirect_to_orders_dashboard( $redirect_to, $request, $person ){
$redirect_to = admin_url( 'edit.php?post_type=shop_order' );
return $redirect_to;
}
}
The way to redirect Woocommerce admin to merchandise record after login?
If you must redirect your self to admin merchandise record web page, then use this snippet as a substitute.
// Redirect Woocommerce admin to merchandise record after login
add_action( 'load-index.php', 'redirect_to_products' );
operate redirect_to_products(){
wp_redirect( admin_url( 'edit.php?post_type=product' ) );
}
add_filter( 'login_redirect', 'redirect_to_products_dashboard', 9999, 3 );
operate redirect_to_products_dashboard( $redirect_to, $request, $person ){
$redirect_to = admin_url( 'edit.php?post_type=product' );
return $redirect_to;
}
The way to disable Woocommerce bloat?
This snippet right here beneath permits you to disable some Woocommerce bloat, that’s Advertising and Analytics menus/submenus. Additionally, it will pace your dashboard up a bit.
// Disable Woocommerce bloat
add_filter( 'woocommerce_admin_disabled', '__return_true' );
The way to add Woocommerce product ID column?
Subsequent, let’s customise Woocommerce admin dashboard additional. Generally it’s possible you’ll must visually see your Woocommerce product ID columns. This snippet will enable you out.
// Add Woocommerce produc ID column?
operate woo_product_extra_columns($columns)
{
$newcolumns = array(
"cb" => "<enter kind = "checkbox" />",
"product_ID" => esc_html__('ID', 'woocommerce'),
);
$columns = array_merge($newcolumns, $columns);
return $columns;
}
add_filter("manage_edit-product_columns", "woo_product_extra_columns");
operate woo_product_extra_columns_content($column)
{
international $put up;
$product_id = $put up->ID;
change ($column)
{
case "product_ID":
echo $product_id;
break;
}
}
add_action("manage_posts_custom_column", "woo_product_extra_columns_content");
// Modify column measurement
add_action('admin_head', 'my_column_width');
operate my_column_width() {
echo '<type kind="textual content/css">';
echo '.column-product_ID { width:40px; }';
echo '</type>';
}
The way to filter Woocommerce merchandise by featured merchandise in admin?
Lets customise Woocommerce Admin Dashboard a bit extra. By default Woocommerce admin doesn’t have an choice to filter merchandise by featured merchandise. If you want to have this function then use this snippet right here beneath.
// Filter Woocommerce merchandise by featured merchandise in admin
add_action('restrict_manage_posts', 'esiletostetud_tooted');
operate esiletostetud_tooted() {
international $typenow;
$post_type = 'product'; // change to your put up kind
$taxonomy = 'product_visibility'; // change to your taxonomy
if ($typenow == $post_type) {
$chosen = isset($_GET[$taxonomy]) ? $_GET[$taxonomy] : '';
$info_taxonomy = get_taxonomy($taxonomy);
wp_dropdown_categories(array(
'show_option_all' => __("Present all {$info_taxonomy->label}"),
'taxonomy' => $taxonomy,
'identify' => $taxonomy,
'orderby' => 'identify',
'chosen' => $chosen,
'show_count' => true,
'hide_empty' => true,
));
};
}
add_filter('parse_query', 'esiletostetud_tooted_paring');
operate esiletostetud_tooted_paring($question) {
international $pagenow;
$post_type = 'product'; // change to your put up kind
$taxonomy = 'product_visibility'; // change to your taxonomy
$q_vars = &$question->query_vars;
if ( $pagenow == 'edit.php' && isset($q_vars['post_type']) && $q_vars['post_type'] == $post_type && isset($q_vars[$taxonomy]) && is_numeric($q_vars[$taxonomy]) && $q_vars[$taxonomy] != 0 ) {
$time period = get_term_by('id', $q_vars[$taxonomy], $taxonomy);
$q_vars[$taxonomy] = $time period->slug;
}
}
The way to add tax class column and tax standing column to Woocommerce admin?
Don’t you are concerned, this snippet right here beneath will add tax class column and tax standing column to Woocommerce admin merchandise record.
// Add tax class column to Woocommerce admin
add_filter( 'manage_edit-product_columns', 'tax_class_product_column');
operate tax_class_product_column($columns){
$new_columns = [];
foreach( $columns as $key => $column ){
$new_columns[$key] = $columns[$key];
if( $key == 'is_in_stock' ) {
$new_columns['tax_class'] = __( 'Tax class','woocommerce');
}
}
return $new_columns;
}
add_action( 'manage_product_posts_custom_column', 'tax_class_product_column_content', 10, 2 );
operate tax_class_product_column_content( $column, $post_id ){
if( $column == 'tax_class' ){
international $put up, $product;
// Excluding variable and grouped merchandise
if( is_a( $product, 'WC_Product' ) ) {
$args = wc_get_product_tax_class_options();
echo $args[$product->get_tax_class()];
}
}
}
// Add Tax standing column to Woocommerce admin
add_filter( 'manage_edit-product_columns', 'tax_status_product_column');
operate tax_status_product_column($columns){
$new_columns = [];
foreach( $columns as $key => $column ){
$new_columns[$key] = $columns[$key];
if( $key == 'is_in_stock' ) {
$new_columns['tax_status'] = __( 'Taxes','woocommerce');
}
}
return $new_columns;
}
add_action( 'manage_product_posts_custom_column', 'tax_status_product_column_content', 10, 2 );
operate tax_status_product_column_content( $column, $post_id ){
if( $column == 'tax_status' ){
international $put up, $product;
// Excluding variable and grouped merchandise
if( is_a( $product, 'WC_Product' ) ) {
$args = array(
'taxable' => __( 'Taxable', 'woocommerce' ),
'delivery' => __( 'Delivery solely', 'woocommerce' ),
'none' => _x( 'None', 'Tax standing', 'woocommerce' ),
);
echo $args[$product->get_tax_status()];
}
}
}
The way to add customized Woocommerce order standing?
Generally it’s possible you’ll want so as to add a customized Woocommerce standing that fits in your store. With the assistance of this snippet right here beneath I’ll add a customized order standing known as “In-progress”. You could rename it as you want.
// 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="depend">(%s)</span>', 'In-progress <span class="depend">(%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 kind="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 way to filter Woocommerce orders by coupons used?
Subsequent hack is a nifty one and permits you to add one other filter to your Woocommerce admin orders web page. This fashion you may filter Woocommerce orders by coupon used.
// Filter Woocommerce orders by coupons used
outlined( 'ABSPATH' ) or exit;
// hearth 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 identify="_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 part of ) {
international $typenow, $wpdb;
if ( 'shop_order' === $typenow && isset( $_GET['_coupons_used'] ) && ! empty( $_GET['_coupons_used'] ) ) {
$be part of .= "LEFT JOIN {$wpdb->prefix}woocommerce_order_items woi ON {$wpdb->posts}.ID = woi.order_id";
}
return $be part of;
}
public operate add_filterable_where( $the place ) {
international $typenow, $wpdb;
if ( 'shop_order' === $typenow && isset( $_GET['_coupons_used'] ) && ! empty( $_GET['_coupons_used'] ) ) {
// Fundamental 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 identify */
_doing_it_wrong( __FUNCTION__, sprintf( esc_html__( 'You can't clone cases of %s.', 'wc-filter-orders' ), 'Filter WC Orders by Coupon' ), '1.1.0' );
}
public operate __wakeup() {
/* translators: Placeholders: %s - plugin identify */
_doing_it_wrong( __FUNCTION__, sprintf( esc_html__( 'You can't unserialize cases 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 way to show used coupons on WooCommerce admin orders record?
Some other methods we will customise Woocommerce admin dashboard? Sure it’s.
It occurs that generally you badly must see what coupon is used within the order. If that is one thing you want then this snippet right here will show used coupons on WooCommerce admin orders record in a separate column.
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, $put up;
if( $column == 'order_coupons' ) {
if( $coupons = $the_order->get_coupon_codes() ) {
echo implode(', ', $coupons) . ' ('.depend($coupons).')';
} else {
echo '<small><em>'. __('No coupon used') . '</em>
// Show used coupons on WooCommerce admin orders record
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, $put up;
if( $column == 'order_coupons' ) {
if( $coupons = $the_order->get_coupon_codes() ) {
echo implode(', ', $coupons) . ' ('.depend($coupons).')';
} else {
echo '<small><em>'. __('No coupon used') . '</em></small>';
}
}
}
The way to show used coupons on Woocommerce order edit web page?
Earlier snippet shows used coupons in columns but when you must show used coupons on Woocommerce order edit web page then use this snippet right here beneath.
operate custom_checkout_field_display_admin_order_meta($order){
if( $order->get_coupon_codes() ) {
$coupons_count = depend( $order->get_coupon_codes() );
echo '<h4>' . __('Coupon used') . ' (' . $coupons_count . ')</h4>';
echo '<p><sturdy>' . __('Coupon used') . ':</sturdy> ';
$i = 1;
foreach( $order->get_coupon_codes() as $coupon) {
echo $coupon;
if( $i < $coupons_count )
echo ', ';
$i++;
}
echo '
//Add used coupons to the order edit web page
operate custom_checkout_field_display_admin_order_meta($order){
if( $order->get_coupon_codes() ) {
$coupons_count = depend( $order->get_coupon_codes() );
echo '<h4>' . __('Coupon used') . ' (' . $coupons_count . ')</h4>';
echo '<p><sturdy>' . __('Coupon used') . ':</sturdy> ';
$i = 1;
foreach( $order->get_coupon_codes() as $coupon) {
echo $coupon;
if( $i < $coupons_count )
echo ', ';
$i++;
}
echo '</p>';
}
}
The way to show used coupons on Woocommerce order preview template?
As well as, you may show used coupons on Woocommerce order preview template. How? Simply use this snippet.
// Show used coupons on Woocommerce order preview template
add_filter( 'woocommerce_admin_order_preview_get_order_details', 'admin_order_preview_add_custom_data', 10, 2 );
operate admin_order_preview_add_custom_data( $knowledge, $order ) {
// Exchange '_custom_meta_key' by the right postmeta key
if( $coupons = $order->get_used_coupons() ) {
$knowledge['coupons_count'] = depend($coupons); // <= Retailer the depend within the knowledge array.
$knowledge['coupons_codes'] = implode(', ', $coupons); // <= Retailer the depend within the knowledge array.
}
return $knowledge;
}
// Show coupon in Order preview
add_action( 'woocommerce_admin_order_preview_end', 'custom_display_order_data_in_admin' );
operate custom_display_order_data_in_admin(){
// Name the saved worth and show it
echo '<div><sturdy>' . __('Coupons used') . ' ({{knowledge.coupons_count}})<sturdy>: {{knowledge.coupons_codes}}</div><br>';
}
The way to show used coupons on Woocommerce order affirmation emails?
Nicely, since we’re already messing with the coupons then let’s show usedused coupons on Woocommerce order affirmation emails additionally.
add_action( 'woocommerce_email_after_order_table', 'add_payment_method_to_admin_new_order', 15, 2 );
operate add_payment_method_to_admin_new_order( $order, $is_admin_email ) {
if ( $is_admin_email ) {
if( $order->get_coupon_codes() ) {
$coupons_count = depend( $order->get_coupon_codes() );
echo '<h4>' . __('Used coupon') . ' (' . $coupons_count . ')</h4>';
echo '<p><sturdy>' . __('Used coupon') . ':</sturdy> ';
$i = 1;
$coupons_list = '';
foreach( $order->get_coupon_codes() as $coupon) {
$coupons_list .= $coupon;
if( $i < $coupons_count )
$coupons_list .= ', ';
$i++;
}
echo '<p><sturdy>Used coupon (' . $coupons_count . ') :</sturdy> ' . $coupons_list . '
// Show used coupons on Woocommerce order affirmation emails
add_action( 'woocommerce_email_after_order_table', 'add_payment_method_to_admin_new_order', 15, 2 );
operate add_payment_method_to_admin_new_order( $order, $is_admin_email ) {
if ( $is_admin_email ) {
if( $order->get_coupon_codes() ) {
$coupons_count = depend( $order->get_coupon_codes() );
echo '<h4>' . __('Used coupon') . ' (' . $coupons_count . ')</h4>';
echo '<p><sturdy>' . __('Used coupon') . ':</sturdy> ';
$i = 1;
$coupons_list = '';
foreach( $order->get_coupon_codes() as $coupon) {
$coupons_list .= $coupon;
if( $i < $coupons_count )
$coupons_list .= ', ';
$i++;
}
echo '<p><sturdy>Used coupon (' . $coupons_count . ') :</sturdy> ' . $coupons_list . '</p>';
} // endif get_coupon_codes
} // endif $is_admin_email
}
The way to filter WooCommerce orders by fee technique?
Woocommerce orders desk has no choice to filter orders by fee gateway, however that is straightforward to repair. If you must filter Woocommerce orders by fee technique then use this snippet.
outlined( 'ABSPATH' ) or exit;
// hearth 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 identify="_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 technique
outlined( 'ABSPATH' ) or exit;
// hearth 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 identify="_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 way to filter Woocommerce orders by person position?
Check out this snippet right here beneath which lets you filter Woocommerce orders by person position. (see screenshot)
operate js_shop_order_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 specific person position
if ( ! empty( $_GET['_user_role'] ) ) {
$user_role = sanitize_text_field( $_GET['_user_role'] );
}
// Show drop down
?><choose identify='_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 js_shop_order_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 specific person position
if ( ! empty( $_GET['_user_role'] ) ) {
$user_role = sanitize_text_field( $_GET['_user_role'] );
}
// Show drop down
?><choose identify='_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', 'js_shop_order_user_role_filter' );
operate js_shop_order_user_role_posts_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', 'js_shop_order_user_role_posts_where' );
The way to autocomplete Woocommerce processing orders?
Straightforward repair. For those who want your “processing” standing to be skipped and set these orders to be accomplished routinely then use this snippet.
// autocomplete Woocommerce processing orders
add_filter( 'woocommerce_payment_complete_order_status', 'processing_orders_autocomplete', 9999 );
operate processing_orders_autocomplete() {
return 'accomplished';
}
The way to add a sortable person Registration date column in WordPress Customers web page?
By default WordPress All customers web page doesn’t present person registration dates, however this can be a “will need to have” function for lots us. So, if you wish to know find out how to add a sortable person registration date column in WordPress Customers web page then use this snippet right here beneath.
// Add a sortable person Registration date column in WordPress Customers web page
// Create person Registration date column in WordPress Customers web page
add_filter( 'manage_users_columns', 'modify_user_table' );
operate modify_user_table( $columns ) {
// unset( $columns['posts'] ); // perhaps you wish to take away default columns
$columns['registration_date'] = 'Registered'; // add new
return $columns;
}
add_filter( 'manage_users_custom_column', 'modify_user_table_row', 10, 3 );
operate modify_user_table_row( $row_output, $column_id_attr, $person ) {
$date_format = 'd.m.Y, H:i';
change ( $column_id_attr ) {
case 'registration_date' :
return date( $date_format, strtotime( get_the_author_meta( 'registered', $person ) ) );
break;
default:
}
return $row_output;
}
// Make WordPress person registration column sortable
add_filter( 'manage_users_sortable_columns', 'sortable_user_date_column' );
operate sortable_user_date_column( $columns ) {
return wp_parse_args( array( 'registration_date' => 'registered' ), $columns );
}
The way to show media file measurement column in WordPress media library?
WordPress media library has one main flaw and that’s: will not be displaying media file sizes. Now, lets repair this problem and show media file measurement column in WordPress media library.
// Show media file measurement column in WordPress media library. Add all code to Code snippets or your baby theme’s features.php file
add_filter( 'manage_media_columns', 'sk_media_columns_filesize' );
operate sk_media_columns_filesize( $posts_columns ) {
$posts_columns['filesize'] = __( 'File measurement', 'my-theme-text-domain' );
return $posts_columns;
}
add_action( 'manage_media_custom_column', 'sk_media_custom_column_filesize', 10, 2 );
// Show File Measurement column in WordPress media library desk record
operate sk_media_custom_column_filesize( $column_name, $post_id ) {
if ( 'filesize' !== $column_name ) {
return;
}
$bytes = filesize( get_attached_file( $post_id ) );
echo size_format( $bytes, 2 );
}
add_action( 'admin_print_styles-upload.php', 'sk_filesize_column_filesize' );
// Modify WordPress File Measurement column on Media Library web page
operate sk_filesize_column_filesize() {
echo
'<type>
.mounted .column-filesize {
width: 10%;
}
</type>';
}
Nicely, that’s it. now you understand how to customise Woocommerce Admin Dashboard.