WordPress Custom Functions For WooCommerce Checkout Page

Customizing the WooCommerce checkout page is a relatively common thing that needs to be addressed.  This page is a collection of various ones I’ve used on projects. Most of them can simply be dropped-in to your functions.php file, but a few do require your to make small changes depending on your exact needs. For more information on using your theme’s function.php file, read this article first.

Define a Default Billing State

There are many shops tend to do the majority of their business in the State in which they are located. Let’s make things easier on the customer by setting that State as the default value. Simply replace the line that reads CA' => 'CALIFORNIA', to your State of preference. For example, Nevada would be NV' => 'NEVADA',.

// Define a default Billing State
add_filter( 'woocommerce_states', 'custom_woocommerce_states' );
function custom_woocommerce_states( $states ) {
  $states['US'] = array(
  return $states;

Custom Address Field Placeholder Text

By default, the placeholder text in the address field of the Checkout page reads “Street address”; however, you may need to have something a little more customized. For example, if you don’t ship to PO Boxes, you may want it to display “Street address (no PO Boxes)”. Simply add this function and replace the text between the single quotes to meet your specific needs.

// Custom Address Field Placeholder Text
add_filter( 'woocommerce_default_address_fields' , 'custom_override_default_address_fields' );
// Our hooked in function - $address_fields is passed via the filter!
function custom_override_default_address_fields( $address_fields ) {
     $address_fields['address_1']['placeholder'] = 'Street address (no PO Boxes)';
     return $address_fields;

Remove "Returning customer? Click here to login" From WooCommerce Checkout Page

There are times when you may need to remove the Login link from the WooCommerce Checkout page. Simply add the following code will remove it.

// Remove "Returning customer? Click here to login" From Checkout Page
remove_action( 'woocommerce_before_checkout_form', 'woocommerce_checkout_login_form', 10 );

Add Flat Fee To Checkout Cost

Adding a flat fee to your check-out can come in handy if you have a “Bill Pay” surcharge for example. To automatically add this to every order, use the following function and simply change the $flatfee value to the number that meets your specific needs. The 3.00 represents $3.00.

// Add Flat Fee To Checkout
add_action( 'woocommerce_cart_calculate_fees','woocommerce_custom_surcharge' );
function woocommerce_custom_surcharge() {
  global $woocommerce;
	if ( is_admin() && ! defined( 'DOING_AJAX' ) )
	$flatfee = 3.00;
	$woocommerce->cart->add_fee( 'Bill Pay Convenience Fee*', $flatfee, true, '' );
Code Recipes, WooCommerce Functions, WooCommerce Tips, WordPress functions.php
Previous Post
WordPress Custom Functions For WooCommerce Product Category Page

Related Posts

You must be logged in to post a comment.