If you take a look around here on my site you’ll find ca 250 different Woocommerce related hacks. In this post I’ll show you 27 of my favorite Woocommerce cart page, checkout page and my account page related hacks. So, let’s take a look at the 27 ways how to improve your Woocommerce store.
One thing you need to know beforehand, though. If you don’t know where to add those snippets here below, then add them either to your child theme’s functions.php file or better yet, use a snippet manager like Code Snippets
Video: 27 Ways How to Improve Woocommerce Store
How to set Minimum Order Amount in WooCommerce?
With the help of this snippet here below we will set a minimum order amount in Woocommerce to 1000 euros and will display an error message on the cart and checkout pages if the conditions are not met (see the screenshot). Just replace the amount inside the code accordingly.

// Set Minimum Order Amount in WooCommerce
add_action( 'woocommerce_checkout_process', 'wc_minimum_order_amount' );
add_action( 'woocommerce_before_cart' , 'wc_minimum_order_amount' );
function wc_minimum_order_amount() {
$minimum = 1000; // Set this variable to specify a minimum order value
if ( WC()->cart->total < $minimum ) {
if( is_cart() ) {
wc_print_notice(
sprintf( 'Your current order total is %s — you must have an order with a minimum of %s to place your order ' ,
wc_price( WC()->cart->total ),
wc_price( $minimum )
), 'error'
);
} else {
wc_add_notice(
sprintf( 'Your current order total is %s — you must have an order with a minimum of %s to place your order' ,
wc_price( WC()->cart->total ),
wc_price( $minimum )
), 'error'
);
}
}
}How to show “XX to free shipping” notification in Woocommerce?
It is a good idea to motivate your users to buy a bit more in order to get free shipping. This snippet here below will add this text to your cart “Buy XX€ worth products more to get free shipping”

// Show "XX to free shipping" notification in Woocommerce
add_action( 'woocommerce_before_cart_table', 'cart_page_notice' );
function cart_page_notice() {
$min_amount = 1000; //This is the amount of your free shipping threshold. Change according to your free shipping settings
$current = WC()->cart->subtotal;
if ( $current < $min_amount ) {
$added_text = '<div class="woocommerce-message"><strong>Buy ' . wc_price( $min_amount - $current ) . ' worth products more to get free shipping</strong>'; // This is the message shown on the cart page
$return_to = wc_get_page_permalink( 'shop' );
$notice = sprintf( '%s<a class="button" href="%s">%s</a>', $added_text, esc_url( $return_to ), 'Continue shopping</div>' ); // This is the text shown below the notification. Link redirects to the shop page
echo $notice;
}
}How to display custom message to Woocommerce cart page?
Maybe you need to warn your customers that shipping is delayed or you need something elso to communicate. If so, then use this snippet and replace text accordingly.

// Add custom message to Woocommerce cart page
add_action( 'woocommerce_before_cart_table', 'shop_message', 20 );
function shop_message() {
echo '<p class="woocommerce-message">Estimated delivery time: 2 weeks</p>'; // Change this text
}
How to Update WooCommerce Cart on Quantity Change?
Next snippet is also a nice one. This allows you to hide Update cart button and it will update your cart amount every time you update product quantities. So, if you need to update WooCommerce cart on quantity change then use this snippet here below.
add_action('wp_head',function(){$css_code=<<<CSS<style>.woocommerce-notices-wrapperdiv.woocommerce-message[role=alert]{display:none;}.woocommercebutton[name="update_cart"]{display:none!important;}</style>CSS;$js_code=<<<JS<scripttype="text/javascript">jQuery(document).ready(function(){varwpcbScrollToNotices;jQuery(document).ajaxComplete(function(e){jQuery.scroll_to_notices=wpcbScrollToNotices;});jQuery('.woocommerce').on('change','input.qty',function(){wpcbScrollToNotices=jQuery.scroll_to_notices;jQuery.scroll_to_notices=function(scrollElement){return!1;};setTimeout(function(){jQuery('button[name="update_cart"]').trigger('click');},200);});});</script>JS;echo $css_code;echo $js_code;});How to change Woocommere“Return to shop”URL?
Take a look at the URL/about-us/in the snippet and if you want to change your Woocommerce“Return to shop”url then replace it with your own URL.
add_filter('woocommerce_return_to_shop_redirect','return_to_shop_url');functionreturn_to_shop_url(){return'/about-us/';}How to add Woocommerce backorder notification in cart page?
I have had customers who complain that they did not realize that they ordered a product which was not in stock and was available on backorder.Therefore,this snippets adds Woocommerce backorder notification in cart page.
As you see from the screenshot below it outputs this message styled as error message.If you want it to show as default Woocommerce message notification then replace‘error’with‘notice’

add_action('woocommerce_before_cart_table','show_backordered_items_cart_notice');functionshow_backordered_items_cart_notice(){$found=!1;foreach(WC()->cart->get_cart()as$cart_item){if($cart_item['data']->is_on_backorder($cart_item['quantity'])){$found=!0;break;}}if($found){wc_print_notice(__("<strong>You have products in the cart that are available only in backorder.</strong><br>For those products estimated delivery time is 2-3 weeks.","woocommerce"),'error');}}How to display backorder notification at Woocommerce checkout page
Some of my customer have complained that they did not realize that they ordered a product which was not in stock and was available only on backorder.Since I wanted to made it less confusing for them I added this snippet here below which shows backorder notification in Woocommerce checkout page.hence,I’m going to show you how to customize Woocommerce checkout page with this little hack.
As you see from the screenshot below it outputs this message styled as error message.If you want it to show as default Woocommerce message notification then replace‘error’with‘notice’

add_action('woocommerce_before_checkout_form','show_backorder_checkout_notice');functionshow_backorder_checkout_notice(){$found=!1;foreach(WC()->cart->get_cart()as$cart_item){if($cart_item['data']->is_on_backorder($cart_item['quantity'])){$found=!0;break;}}if($found){wc_print_notice(__("<strong>You have products in the cart that are available only in backorder.</strong><br>For those products estimated delivery time is 2-3 weeks.","woocommerce"),'error');}}How to auto-expand coupon field on Woocommerce checkout page?No need to click on“Have a coupon?”link
Let’s be honest:it’s a bit annoying to click on a“Have a coupon?”link on your Woocommerce chekcout page.Therefore,let’s auto-expand the coupon field and remove one more unnecessary click.
add_action('wp_footer','wpsh_display_coupon_field',99);functionwpsh_display_coupon_field(){echo'<script type="text/javascript">jQuery(document).ready(function($){$(\'.checkout_coupon\').show();});</script>';}How to change Woocommerce coupon field location on checkout page v.1?
If you like the styling and layout of the previous hack and you would like to display it also on a Woocommerce checkout page(under the Place order button),then use this snippet here below(and don’t forget to add CSS from the previous snippet).
remove_action('woocommerce_before_checkout_form','woocommerce_checkout_coupon_form',10);add_action('woocommerce_review_order_after_submit','move_checkout_coupon_field',1);functionmove_checkout_coupon_field(){?><formclass="woocommerce-coupon-form"action="<?php echo esc_url(wc_get_checkout_url());?>"method="post"><?phpif(wc_coupons_enabled()){?><divclass="coupon under-proceed"><inputtype="text"name="coupon_code"class="input-text"id="coupon_code"value=""placeholder="<?php esc_attr_e('Coupon code','woocommerce');?>"style="width:100%;margin-top:10px;"/><buttontype="submit"class="button"name="apply_coupon"value="<?php esc_attr_e('Apply coupon','woocommerce');?>"style="width:100%"><?phpesc_attr_e('Apply coupon','woocommerce');?></button></div><?php}?></form><?php}How to change Woocommerce coupon field location on checkout page v.2?
There’s also another way to move your Woocommerce coupon field location on checkout page.Here’s the end result.

So,to make it work like that,just use this snippet.
remove_action('woocommerce_before_checkout_form','woocommerce_checkout_coupon_form',10);add_action('woocommerce_review_order_after_submit','wpsh_move_coupon_button',1);functionwpsh_move_coupon_button(){echo'<hr/';woocommerce_checkout_coupon_form();}How to remove“Ship to adifferent address”if Local Pickup is selected?
There is no need for“ship to a different address”section if customer has chosen Local pickup as a shiping method.Therefore,let’s“ship to different address”if Local Pickup is selected.
add_action('woocommerce_after_checkout_form','wpsh_remove_ship_to_section');functionwpsh_remove_ship_to_section($available_gateways){$chosen_methods=WC()->session->get('chosen_shipping_methods');$chosen_shipping=$chosen_methods[0];if(0===strpos($chosen_shipping,'local_pickup')){?><scripttype="text/javascript">jQuery('#customer_details.col-2 .woocommerce-shipping-fields').fadeOut();</script><?php}?><scripttype="text/javascript">jQuery('form.checkout').on('change','input[name^="shipping_method"]',function(){varval=jQuery(this).val();if(val.match("^local_pickup")){jQuery('#customer_details.col-2 .woocommerce-shipping-fields').fadeOut();}else{jQuery('#customer_details.col-2 .woocommerce-shipping-fields').fadeIn();}});</script><?php}How to disable Woocommerce shipping methods for a specific shipping class?
Now,there are two things you would need to do beforehand:
- Add a shipping class.Go to Woocommerce>>Settings>>Shipping>>Shipping classes and add one.For example:“Courier only”
- Write down the shipping class slugbecause you will need it later.Where to get the slug?See the screenshot below.
- Add shipping class to the needed product.Open your product and see under Shipping tab.

Next,go to Snippets>>Add new and paste this snippet here below inside your code box.Pay attention though that you need to change the shipping class slug on line 4 accordingly.
So,if in this example I have a“Courier only”shipping class with a slug“courier-only”,then replace the slug in the code accordingly with the correct one.
One more thing,on line 12 there is a shipping method that you are hiding(Flat rate).Change the shipping method name and ID as needed.How to find your shipping ID number?Well,take a look at the video above(see the 3min 44sec mark).
functionhide_flat_rate_shipping($rates,$package){$shipping_classes=array('courier-only');$if_exists=!1;foreach($package['contents']as$key=>$values){if(in_array($values['data']->get_shipping_class(),$shipping_classes))$if_exists=!0;}if($if_exists)unset($rates['flat_rate:2']);return$rates;}add_filter('woocommerce_package_rates','hide_flat_rate_shipping',10,2);If you would like to know how to hide Woocommerce multiple shipping methods using shipping classes,thensee my previous post here.
How to Hide Woocommerce Checkout Fields When Local Pickup is Selected?
One of the most annoying things with the Woocommerce shiping system is that if Local Pickup shipping method is chosen then you still need to fill in all the address and postcode fields.But what if you could automatically hide those fields if Local pickup method is chosen?
add_filter('woocommerce_checkout_fields','hide_local_pickup_method');functionhide_local_pickup_method($fields_pickup){$shipping_method_pickup='local_pickup:2';$hide_fields_pickup=array('billing_company','billing_country','billing_postcode','billing_address_1','billing_address_2','billing_city','billing_state');$chosen_methods_pickup=WC()->session->get('chosen_shipping_methods');$chosen_shipping_pickup=$chosen_methods_pickup[0];foreach($hide_fields_pickupas$field_pickup){if($chosen_shipping_pickup==$shipping_method_pickup){$fields_pickup['billing'][$field_pickup]['required']=!1;$fields_pickup['billing'][$field_pickup]['class'][]='hide_pickup';}$fields_pickup['billing'][$field_pickup]['class'][]='billing-dynamic_pickup';}return$fields_pickup;}add_action('wp_head','local_pickup_fields',999);functionlocal_pickup_fields(){if(is_checkout()):?><style>.hide_pickup{display:none!important}</style><script>jQuery(function($){if(typeofwoocommerce_params==='undefined'){return!1;}$(document).on('change','#shipping_method input[type="radio"]',function(){$('.billing-dynamic_pickup').toggleClass('hide_pickup',this.value=='local_pickup:2');});});</script><?phpendif;}Now,pay attention that the snippet above works only with one Local Pickup Shipping method.If you have multiple Local Pickup selections,then the code above works only with one of them and then you should use this snippet here below
How to Hide Woocommerce Checkout Fields Based on Shipping Methods?
This one here is a bit tricky one and will do this:
- If Local pickup(local_pickup:2)is selected,Billing country,postcode,address 1,address 2 and city fields are disabled.
- If Local Pickup 2(local_pickup:8)is selected,Billing country,postcode,address 1,address 2 and city fields are disabled.
- If Local pickup(multiparcels_smartpost_pickup_point:7)is selected,Billing country,postcode,address 1,address 2 andcity and phonefields are disabled.
If you would like to use this snippet,then take a look at line 30 for changing your shipping ID.Line 33 contains fields to be hidden.And line 70 should once again contains your shipping method.So,everything between lines 25 and 76 contains code for Local pickup method.Lines 78-130 is used for Local pickup 2 and lines 132-182 are for SmartPost shipping method.
In a similar way you can add(or remove)your own additional shipping methods.
add_filter('woocommerce_checkout_fields','wpsh_hide_local_pickup_fields');functionwpsh_hide_local_pickup_fields($fields_itella){$shipping_method_itella='local_pickup:2';$hide_fields_itella=array('billing_company','billing_country','billing_postcode','billing_address_1','billing_address_2','billing_city');$chosen_methods_itella=WC()->session->get('chosen_shipping_methods');$chosen_shipping_itella=$chosen_methods_itella[0];foreach($hide_fields_itellaas$field_itella){if($chosen_shipping_itella==$shipping_method_itella){$fields_itella['billing'][$field_itella]['required']=!1;$fields_itella['billing'][$field_itella]['class'][]='hide_local';}$fields_itella['billing'][$field_itella]['class'][]='billing-dynamic_itella';}return$fields_itella;}add_action('wp_head','wpsh_local_pickup_ajax',999);functionwpsh_local_pickup_ajax(){if(is_checkout()):?><style>.hide_local{display:none!important}</style><script>jQuery(function($){if(typeofwoocommerce_params==='undefined'){return!1;}$(document).on('change','#shipping_method input[type="radio"]',function(){$('.billing-dynamic_itella').toggleClass('hide_local',this.value=='local_pickup:2');});});</script><?phpendif;}add_filter('woocommerce_checkout_fields','wpsh_hide_local_pickup2_fields');functionwpsh_hide_local_pickup2_fields($fields_omniva){$shipping_method_omniva='local_pickup:8';$hide_fields_omniva=array('billing_company','billing_country','billing_postcode','billing_address_1','billing_address_2','billing_city');$chosen_methods_omniva=WC()->session->get('chosen_shipping_methods');$chosen_shipping_omniva=$chosen_methods_omniva[0];foreach($hide_fields_omnivaas$field_omniva){if($chosen_shipping_omniva==$shipping_method_omniva){$fields_omniva['billing'][$field_omniva]['required']=!1;$fields_omniva['billing'][$field_omniva]['class'][]='hide_local';}$fields_omniva['billing'][$field_omniva]['class'][]='billing-dynamic_omniva';}return$fields_omniva;}add_action('wp_head','wpsh_hide_local_pickup2_ajax',999);functionwpsh_hide_local_pickup2_ajax(){if(is_checkout()):?><style>.hide_local2{display:none!important}</style><script>jQuery(function($){if(typeofwoocommerce_params==='undefined'){return!1;}$(document).on('change','#shipping_method input[type="radio"]',function(){$('.billing-dynamic_omniva').toggleClass('hide_local2',this.value=='local_pickup:8');});});</script><?phpendif;}add_filter('woocommerce_checkout_fields','wpsh_hide_smartpost_fields');functionwpsh_hide_smartpost_fields($fields_pickup){$shipping_method_pickup='multiparcels_smartpost_pickup_point:7';$hide_fields_pickup=array('billing_company','billing_country','billing_postcode','billing_address_1','billing_address_2','billing_city','billing_phone');$chosen_methods_pickup=WC()->session->get('chosen_shipping_methods');$chosen_shipping_pickup=$chosen_methods_pickup[0];foreach($hide_fields_pickupas$field_pickup){if($chosen_shipping_pickup==$shipping_method_pickup){$fields_pickup['billing'][$field_pickup]['required']=!1;$fields_pickup['billing'][$field_pickup]['class'][]='hide_smartpost';}$fields_pickup['billing'][$field_pickup]['class'][]='billing-dynamic_pickup';}return$fields_pickup;}add_action('wp_head','wpsh_hide_smartpost_fields_ajax',999);functionwpsh_hide_smartpost_fields_ajax(){if(is_checkout()):?><style>.hide_smartpost{display:none!important}</style><script>jQuery(function($){if(typeofwoocommerce_params==='undefined'){return!1;}$(document).on('change','#shipping_method input[type="radio"]',function(){$('.billing-dynamic_pickup').toggleClass('hide_smartpost',this.value=='multiparcels_smartpost_pickup_point:7');});});</script><?phpendif;}How to display Woocommerce store address for Local pickup shipping method?
The first thing you need to do is you need to find out your Local pickup ID number.
If you don’t know how to do that then go to Woocommerce>>Settings>>Shipping>>Open your shipping zone.
Now hover on the Local pickup method and see the link.It is something like this:
https:
See the ID=2,this is your shipping method ID.
Now add this piece of CSS inside Appearace>>Customizer>>Additional CSS code box.
#shipping_method_0_local_pickup2:checked+label[for=shipping_method_0_local_pickup2]::after{display:block;content:"London, Buckingham palace";color:red;font-weight:600}How to hide all shipping rates when free shipping is available,but keep“Local pickup?
Let’s tweak this solution I showed in previous chapten and hide all shipping rates when free shipping is available,but keep“Local pickup”method.
add_filter('woocommerce_package_rates','wpsh_hide_if_free',100);functionwpsh_hide_if_free($rates){$free=$local=array();foreach($ratesas$rate_id=>$rate){if('free_shipping'===$rate->method_id){$free[$rate_id]=$rate;}elseif('local_pickup'===$rate->method_id){$local[$rate_id]=$rate;}}return!empty($free)?array_merge($free,$local):$rates;}How to add Custom Woocommerce Checkout Message?
Now let’s take a look how to customize Woocommerce checkout page with the custom message.
This snippet here below adds custom Woocommerce checkout message on top of the checkout page.Just replace the message content(“Estimated delivery time:2 weeks”)accordingly.
add_action('woocommerce_before_checkout_form','shop_message',20);functionshop_message(){echo'<p class="woocommerce-message">Estimated delivery time:2 weeks</p>';}How to Give a Discount if Woocommerce Local Pickup shipping method is selected?
There are two main reasons why you should consider giving a discount for those who select Local pickup as their shipping method.
- You have a small shop and therefore you have no time to hassle with the shipments all the time.Therefore,it would be much easier for you if the customer would come to the shop to pick the product up.Because…
- …this way you can offer the customer up-sells,cross-sells etc.It is a handy method to make your customer to visit your shop.
So,to motivate your customers to choose a local pickup shipping method you may want to consider give them a small discount.
functionlocal_pickup_discount($cart){$chosen_methods=WC()->session->get('chosen_shipping_methods');$chosen_shipping_no_ajax=$chosen_methods[0];if(0===strpos($chosen_shipping_no_ajax,'local_pickup')){$discount=$cart->subtotal*0.15;$cart->add_fee(__('Discount added','yourtext-domain'),-$discount);}}add_action('woocommerce_cart_calculate_fees','local_pickup_discount');How to move Woocommerce email to top at checkout page?
add_filter('woocommerce_checkout_fields','move_email_field_to_top');functionmove_email_field_to_top($checkout_fields){$checkout_fields['billing']['billing_email']['priority']=4;return$checkout_fields;}How to remove Woocommerce checkout fields?
Here below are all the fields you can remove.
add_filter('woocommerce_checkout_fields','custom_override_checkout_fields');functioncustom_override_checkout_fields($fields){unset($fields['billing']['billing_first_name']);unset($fields['billing']['billing_last_name']);unset($fields['billing']['billing_company']);unset($fields['billing']['billing_address_1']);unset($fields['billing']['billing_address_2']);unset($fields['billing']['billing_city']);unset($fields['billing']['billing_postcode']);unset($fields['billing']['billing_country']);unset($fields['billing']['billing_state']);unset($fields['billing']['billing_phone']);unset($fields['billing']['billing_email']);unset($fields['shipping']['shipping_first_name']);unset($fields['shipping']['shipping_last_name']);unset($fields['shipping']['shipping_company']);unset($fields['shipping']['shipping_address_1']);unset($fields['shipping']['shipping_address_2']);unset($fields['shipping']['shipping_city']);unset($fields['shipping']['shipping_postcode']);unset($fields['shipping']['shipping_country']);unset($fields['shipping']['shipping_state']);unset($fields['order']['order_comments']);return$fields;}You don’t have to paste all of them,instead use only these you need.For example,if you need to remove billing address 2,state and company fields then use this code here below.
add_filter('woocommerce_checkout_fields','custom_override_checkout_fields');functioncustom_override_checkout_fields($fields){unset($fields['billing']['billing_company']);unset($fields['billing']['billing_address_2']);unset($fields['billing']['billing_state']);return$fields;}How to make Woocommerce checkout fields optional?
Pay attention that“!0”=required and if you want the field to be optional then set it to“!1”.
add_filter('woocommerce_default_address_fields','optional_default_address_fields');functionoptional_default_address_fields($address_fields){$address_fields['first_name']['required']=!0;$address_fields['last_name']['required']=!0;$address_fields['company']['required']=!1;$address_fields['address_1']['required']=!0;$address_fields['address_2']['required']=!1;$address_fields['country']['required']=!1;$address_fields['postcode']['required']=!1;$address_fields['city']['required']=!1;$address_fields['state']['required']=!1;return$address_fields;}add_filter('woocommerce_billing_fields','optional_checkout_fields1',1000,1);functionoptional_checkout_fields1($fields){$fields['billing_email']['required']=!0;$fields['billing_phone']['required']=!1;return$fields;}And once more,if you need a only couple of fields to be optional then just paste the lines you need.For example,this snippet makes country and phone fields optional.
add_filter('woocommerce_default_address_fields','optional_default_address_fields');functionoptional_default_address_fields($address_fields){$address_fields['country']['required']=!1;return$address_fields;}add_filter('woocommerce_billing_fields','optional_checkout_fields1',1000,1);functionoptional_checkout_fields1($fields){$fields['billing_phone']['required']=!1;return$fields;}How to add custom fields in Woocommerce checkout page?
This snipepts allows you to add custom fields in Woocommerce checkout page withut any plugin.It will add three text fields(Home,Entrance and Floor)in the billing section.Just rename the field names and placehodler text if needed and you’re good to go.
All the date will be added to the emails on order tables and what is especially good,is that all the data is editable.If you don’t need three fields then just remove the ones you don’t need from the code.
add_filter('woocommerce_billing_fields','add_custom_billing_fields',20,1);functionadd_custom_billing_fields($fields){$fields['billing_address_3']=array('label'=>__('Home','woocommerce'),'placeholder'=>_x('Fill in your Home','placeholder','woocommerce'),'required'=>!0,'class'=>array('form-row-wide'),'clear'=>!0);$fields['billing_address_4']=array('label'=>__('Entrance','woocommerce'),'placeholder'=>_x('Fill in your Entrance','placeholder','woocommerce'),'required'=>!0,'class'=>array('form-row-wide'),'clear'=>!0);$fields['billing_address_5']=array('label'=>__('Floor','woocommerce'),'placeholder'=>_x('Fill in your Floor','placeholder','woocommerce'),'required'=>!0,'class'=>array('form-row-wide'),'clear'=>!0);return$fields;}add_action('woocommerce_checkout_create_order','save_custom_billingt_fields',20,2);functionsave_custom_billingt_fields($order,$data){if(isset($_POST['billing_address_3'])&&!empty($_POST['billing_address_3'])){$order->update_meta_data('_billing_address_3',sanitize_text_field($_POST['billing_address_3']));update_user_meta($order->get_customer_id(),'billing_address_3',sanitize_text_field($_POST['billing_address_3']));}if(isset($_POST['billing_address_4'])&&!empty($_POST['billing_address_4'])){$order->update_meta_data('_billing_address_4',sanitize_text_field($_POST['billing_address_4']));update_user_meta($order->get_customer_id(),'billing_address_4',sanitize_text_field($_POST['billing_address_4']));}if(isset($_POST['billing_address_5'])&&!empty($_POST['billing_address_5'])){$order->update_meta_data('_billing_address_5',sanitize_text_field($_POST['billing_address_5']));update_user_meta($order->get_customer_id(),'billing_address_5',sanitize_text_field($_POST['billing_address_5']));}}add_action('woocommerce_email_after_order_table','display_new_checkout_fields_in_emails',20,4);functiondisplay_new_checkout_fields_in_emails($order,$sent_to_admin,$plain_text,$email){if(get_post_meta($order->get_id(),'_billing_address_3',!0))echo'<p><strong>Home:</strong>'.get_post_meta($order->get_id(),'_billing_address_3',!0).'</p>';if(get_post_meta($order->get_id(),'_billing_address_4',!0))echo'<p><strong>Entrance:</strong>'.get_post_meta($order->get_id(),'_billing_address_4',!0).'</p>';if(get_post_meta($order->get_id(),'_billing_address_5',!0))echo'<p><strong>Floor:</strong>'.get_post_meta($order->get_id(),'_billing_address_5',!0).'</p>';}add_filter('woocommerce_admin_billing_fields','order_admin_custom_fields');functionorder_admin_custom_fields($fields){global$the_order;$fields['address_3']=array('label'=>__('Home','woocommerce'),'show'=>!0,'wrapper_class'=>'form-field-wide','style'=>'',);$fields['address_4']=array('label'=>__('Entrance','woocommerce'),'show'=>!0,'wrapper_class'=>'form-field-wide','style'=>'',);$fields['address_5']=array('label'=>__('Floor','woocommerce'),'show'=>!0,'wrapper_class'=>'form-field-wide','style'=>'',);return$fields;}How to disable all Woocommerce payment gateways?
The reason you would need to disable all payment gateways is that maybe you need it just for some catalogue or ordering system.Hence,use this small piece of code.
add_filter('woocommerce_cart_needs_payment','__return_false');And this is the result.

How to Disable Woocommerce payment gateways for specific user roles?
Let’s imagine that your shop has a bunch of user roles.For example,customer,Gold member,Silver package etc.This snippet here allows you to disable Woocommerce payment gateways for specific user roles.
Pay attention to line 8 for user role and lines 11-15 for payment gateways to be removed.In this example customer can use onluy BACS and all other gateways are removed.
add_filter('woocommerce_available_payment_gateways','wpsh_hide_payment_roles',1);functionwpsh_hide_payment_roles($gateways){$current_user=wp_get_current_user();$role=$current_user->roles;global$woocommerce;if($role[0]=='customer'){unset($gateways['cheque']);unset($gateways['cod']);unset($gateways['paypal']);}return$gateways;}How to Disable Woocommerce payment gateways for specific user roles(alternative method)?
If for some reason previous method didn’t work out for you then use this snippet here below.
add_filter('woocommerce_available_payment_gateways','wpsh_disable:payment_for_roles');functionwpsh_disable:payment_for_roles($available_gateways){if(current_user_can('customer')){if(isset($available_gateways['paypal'])){unset($available_gateways['paypal']);}if(isset($available_gateways['bacs'])){unset($available_gateways['bacs']);}}return$available_gateways;}How to Disable Woocommerce payment gateways for logged-out users?
Sometimes,if you would like to display WooCommerce payment methods conditionally,you need to set up some rules for your logged-out users.
For example,I have a customer who needed to hide direct bank payments(BACS)for logged-out users.So,if you need to disable some specific Woocommerce payment gateway for logged-out users then this snippet here helps you out.
Once again,pay attention to line 7 which defines roles that are allowed to use gateways.Other roles have no access to these gateways.In this example customer and administrator roles can use BACS and Check payments,all other user roles do not.
add_filter('woocommerce_available_payment_gateways','wpsh_disable_payment_for_logged_out_users',90,1);functionwpsh_disable_payment_for_logged_out_users($available_payment_gateways){$user=wp_get_current_user();$allowed_roles=array('customer','administrator');if(!array_intersect($allowed_roles,$user->roles)){if(isset($available_payment_gateways['bacs'])){unset($available_payment_gateways['bacs']);}if(isset($available_payment_gateways['cheque'])){unset($available_payment_gateways['cheque']);}}return$available_payment_gateways;}How to disable Woocommerce payment methods for a specific country?
Why would you need to disable Woocommerce payment methods for a specific country?Well,if my shop is in Europe,and you’re in USA then I don’t see any point to using Cash on delivery(COD)payment method.
Therefore,in this example,I will remove COD for USA(see line 12-15).Also,I will remove Paypal and Check payments for Estonia,Finland and Norway(see lines 19-24).
add_filter('woocommerce_available_payment_gateways','wpsh_hide_payment_for_countries',10,1);functionwpsh_hide_payment_for_countries($payment_gateways){if(is_admin())return$payment_gateways;$customer_country=WC()->customer->get_shipping_country()?WC()->customer->get_shipping_country():WC()->customer->get_billing_country();if(in_array($customer_country,array('US'))){if(isset($payment_gateways['cod'])){unset($payment_gateways['cod']);}}if(in_array($customer_country,array('EE','FI','NO'))){if(isset($payment_gateways['paypal'])){unset($payment_gateways['paypal']);}if(isset($payment_gateways['cheque'])){unset($payment_gateways['cheque']);}}return$payment_gateways;}How to add Payment Gateway Based Fees in Woocommerce?
Next part of our“How to display WooCommerce payment methods conditionally?”post is here.That means,I’ll show you how to add Payment Gateway Based Fees in Woocommerce.For example,let’s add two kinds of fees with the help of this code:
- Fixed fee(2 euros)for using Cash on delivery fee(see line 15)
- Percentage fee(5%)for using Paypal(see line 16).
Just add your own fees and payment methods,and you’re good to go.

add_action('woocommerce_cart_calculate_fees','wpsh_add_handling_fee');functionwpsh_add_handling_fee($cart){if(is_admin()&&!defined('DOING_AJAX'))return;$chosen_payment_id=WC()->session->get('chosen_payment_method');if(empty($chosen_payment_id))return;$subtotal=$cart->subtotal;$targeted_payment_ids=array('cod'=>2,'paypal'=>5*$subtotal/100,);foreach($targeted_payment_idsas$payment_id=>$fee_cost){if($chosen_payment_id===$payment_id){$cart->add_fee(__('Handling fee','woocommerce'),$fee_cost,!0);}}}add_action('woocommerce_checkout_init','wpsh_refresh_checkout_page');functionwpsh_refresh_checkout_page(){wc_enqueue_js("jQuery(function($){$('form.checkout').on('change','input[name=payment_method]',function(){$(document.body).trigger('update_checkout');});});");}How to add custom endpoints in Woocommerce?
Now,some explanations for the code below:
- Take a look at the comments inside the code
- You need to change your endpoint slug and title accordingly(see lines 8,18 and 46)
- Line 23 containswoocommerce_account_support_endpointand you need to change it accordingly.That is,if your endpoint slug isyour-coursesthen this line should look woocommerce_account_your-courses_endpoint
- After saving and activating your snippet you need to go to Settings>Permalinks and just push“Save Changes”button.Otherwise you end up with“Oops,that page cannot be found”error
add_filter('woocommerce_account_menu_items','wpsh_custom_endpoint',40);functionwpsh_custom_endpoint($menu_links){$menu_links=array_slice($menu_links,0,5,!0)+array('support'=>'Support')+array_slice($menu_links,5,NULL,!0);return$menu_links;}add_action('init','wpsh_new_endpoint');functionwpsh_new_endpoint(){add_rewrite_endpoint('support',EP_PAGES);}add_action('woocommerce_account_support_endpoint','wpsh_endpoint_content');functionwpsh_endpoint_content(){echo('<h3>Send us an email</h3><p>Lorem ipsum dolor sit amet consectetur adipiscing elit facilisis tincidunt,nisi sociosqu lacinia auctor inceptos libero conubia accumsan</p>');echodo_shortcode('');}add_filter('woocommerce_account_menu_items','wpsh_custom_endpoint_order');functionwpsh_custom_endpoint_order(){$myorder=array('dashboard'=>__('Dashboard','woocommerce'),'orders'=>__('Your orders','woocommerce'),'edit-account'=>__('Account details','woocommerce'),'edit-address'=>__('Edit address','woocommerce'),'woo-wish-list'=>__('Wishlist','woocommerce'),'support'=>__('Support','woocommerce'),'customer-logout'=>__('Log out','woocommerce'),);return$myorder;}How to display products name and quantity in a new column on Woocommerce“My account”page orders table?
Take a look at the“How to add“Cancel”button to Woocommerce my account page?”section above.There’s a screenshot and you’ll see that in it I display products name and quantity in a new column on Woocommerce“My account”page orders table.So,if you would like to accomplish the same result,just use this snippet here below.
add_filter('woocommerce_my_account_my_orders_columns','wpsh_product_column',10,1);functionwpsh_product_column($columns){$new_columns=[];foreach($columnsas$key=>$name){$new_columns[$key]=$name;if('order-status'===$key){$new_columns['order-items']=__('Product|Qty','woocommerce');}}return$new_columns;}add_action('woocommerce_my_account_my_orders_column_order-items','wpsh_product_column_content',10,1);functionwpsh_product_column_content($order){$details=array();foreach($order->get_items()as$item)$details[]=$item->get_name().' × '.$item->get_quantity();echocount($details)>0?implode('<br>',$details):'–';}


