WooCommerce

25+ Essential WooCommerce Checkout Snippets: The Master List (No Plugins)

Stop bloating your database with heavy plugins. Here is the ultimate collection of copy-paste PHP codes to customize every inch of your checkout page manually.

As a WordPress developer, I find myself writing the same code snippets over and over again for different clients. Instead of searching Google every time, I decided to compile a Master List.

Here are the top 25 most requested WooCommerce checkout customizations.

⚠️ Prerequisite: Add these codes to your Child Theme’s functions.php file. Don’t have a child theme? Create one instantly with my free generator.

1. Remove All Unnecessary Fields (The “Cleaner”)
This snippet allows you to remove any field you don’t need. I have commented them out; just uncomment the lines you want to remove.

add_filter( 'woocommerce_checkout_fields' , 'musa_remove_checkout_fields' );

function musa_remove_checkout_fields( $fields ) {
    // Billing Fields
    unset($fields['billing']['billing_company']);
    unset($fields['billing']['billing_address_2']);
    unset($fields['billing']['billing_postcode']); 
    // unset($fields['billing']['billing_phone']); // Be careful removing phone!

    // Order Fields
    unset($fields['order']['order_comments']); 

    return $fields;
}

 

2. Make “Phone Number” Optional
Force-requiring a phone number often kills conversions. Make it optional.

add_filter( 'woocommerce_billing_fields', 'musa_make_phone_optional');

function musa_make_phone_optional( $fields ) {
    $fields['billing_phone']['required'] = false;
    return $fields;
}

 

3. Move “Email Address” to the Top
For digital products, the email is the most important field. Move it to the very top (Priority 1).

add_filter( 'woocommerce_billing_fields', 'musa_move_email_top' );

function musa_move_email_top( $fields ) {
    $fields['billing_email']['priority'] = 1;
    return $fields;
}

 

4. Change “Place Order” Button Text
Change the generic button text to something more actionable like “Pay Now” or “Complete Order”.

add_filter( 'woocommerce_order_button_text', 'musa_custom_checkout_btn' ); 

function musa_custom_checkout_btn() {
    return __( 'Complete My Order', 'woocommerce' ); 
}

 

5. Set a “Minimum Order Amount”
Don’t want to ship items if the order is under $20? Use this.

add_action( 'woocommerce_checkout_process', 'musa_minimum_order_amount' );
add_action( 'woocommerce_before_cart' , 'musa_minimum_order_amount' );
 
function musa_minimum_order_amount() {
    $minimum = 20; // Set your minimum amount here

    if ( WC()->cart->total < $minimum ) {
        if( is_cart() ) {
            wc_print_notice( sprintf( 'Minimum order amount is $%s. Your current total is $%s.' , $minimum , WC()->cart->total ), 'error' );
        } else {
            wc_add_notice( sprintf( 'Minimum order amount is $%s. Please add more items.' , $minimum ), 'error' );
        }
    }
}

 

6. Add a Custom Message Before Checkout Form
Great for adding trust badges like “100% Secure Payment” or shipping notices.

add_action( 'woocommerce_before_checkout_form', 'musa_add_checkout_message', 5 );

function musa_add_checkout_message() {
    echo '<div class="woocommerce-info">🔒 All transactions are secured and encrypted. Shop with confidence.</div>';
}

 

7. Limit “Postcode/Zip” to Numbers Only
Stop users from entering random text in the Zip code field.

add_action('woocommerce_checkout_process', 'musa_validate_postcode');

function musa_validate_postcode() { 
    $postcode = $_POST['billing_postcode'];
    if( !preg_match('/^[0-9]+$/', $postcode) ){
        wc_add_notice( __( 'Please enter a valid numeric Postcode/ZIP.' ), 'error' );
    }
}

 

8. Redirect to a “Custom Thank You Page”
Want to send users to a special upsell page after purchase instead of the default receipt?

add_action( 'woocommerce_thankyou', 'musa_custom_redirect' );

function musa_custom_redirect( $order_id ) {
    $order = wc_get_order( $order_id );
    if ( ! $order->has_status( 'failed' ) ) {
        wp_redirect( home_url( '/thank-you-special/' ) ); // Change URL here
        exit;
    }
}

 

9. Remove “Order Notes” Field Only
If you just want to kill the big notes box at the bottom.

add_filter( 'woocommerce_enable_order_notes_field', '__return_false', 9999 );

 

10. Auto-Check the “Terms & Conditions” Box
Improve UX by auto-checking the Terms box (check your local laws first).

add_filter( 'woocommerce_terms_is_checked_default', '__return_true' );

 

11. Remove the “Coupon Code” Field
Many store owners want to hide the coupon field at checkout to stop customers from leaving the site to Google “coupon codes”.

// Remove coupon from checkout (Keep it on cart page)
remove_action( 'woocommerce_before_checkout_form', 'woocommerce_checkout_coupon_form', 10 );

 

12. Force “Ship to a Different Address” to be Closed (or Open)
By default, this toggle might be open. Use this to force it closed by default.

add_filter( 'woocommerce_ship_to_different_address_checked', '__return_false' );

 

13. Disable Checkout for Specific Countries
If you want to sell globally but block specific high-risk countries programmatically.

add_filter( 'woocommerce_checkout_fields', 'musa_restrict_countries' );

function musa_restrict_countries( $fields ) {
    // Add country codes to block
    $blocked_countries = array( 'XX', 'YY' ); 
    
    $shipping_country = WC()->customer->get_shipping_country();
    
    if ( in_array( $shipping_country, $blocked_countries ) ) {
        // You can add logic here to empty cart or show error
    }
    return $fields;
}

 

(Note: WooCommerce has built-in country settings, but this code helps for conditional logic based on specific products).

14. Add a “Confirm Email Address” Field
Make sure users don’t mistype their email.

add_filter( 'woocommerce_checkout_fields', 'musa_add_confirm_email_field' );

function musa_add_confirm_email_field( $fields ) {
    $fields['billing']['billing_email']['class'] = array( 'form-row-first' );
    $fields['billing']['billing_email_confirm'] = array(
        'label' => __( 'Confirm Email Address', 'woocommerce' ),
        'required' => true,
        'class' => array( 'form-row-last' ),
        'clear' => true,
        'priority' => 999,
    );
    return $fields;
}

add_action( 'woocommerce_checkout_process', 'musa_validate_confirm_email' );

function musa_validate_confirm_email() {
    $email = $_POST['billing_email'];
    $confirm = $_POST['billing_email_confirm'];
    if ( $email !== $confirm ) {
        wc_add_notice( __( 'Email addresses do not match.', 'woocommerce' ), 'error' );
    }
}

 

15. Change “Billing Details” Heading Text
Customize the section header to sound friendlier.

add_filter( 'gettext', 'musa_change_billing_heading', 10, 3 );

function musa_change_billing_heading( $translated_text, $text, $domain ) {
    if ( $text === 'Billing details' ) {
        $translated_text = 'Your Information'; // Change text here
    }
    return $translated_text;
}

 

16. Show “You Saved $X” Message
Increase conversion by showing how much they are saving on sale items right above the payment button.

add_action( 'woocommerce_review_order_before_payment', 'musa_show_savings_message' );

function musa_show_savings_message() {
    $total_savings = 0;
    foreach ( WC()->cart->get_cart() as $cart_item ) {
        $product = $cart_item['data'];
        if ( $product->is_on_sale() ) {
            $regular_price = $product->get_regular_price();
            $sale_price = $product->get_sale_price();
            $total_savings += ( $regular_price - $sale_price ) * $cart_item['quantity'];
        }
    }
    if ( $total_savings > 0 ) {
        echo '<div class="woocommerce-message">🎉 You are saving <strong>$' . $total_savings . '</strong> on this order!</div>';
    }
}

 

17. Add a “Subscribe to Newsletter” Checkbox
Add a simple checkbox. Note: You need extra code to actually save this to Mailchimp/database, this just adds the UI.

add_action( 'woocommerce_after_checkout_billing_form', 'musa_newsletter_checkbox' );

function musa_newsletter_checkbox( $checkout ) {
    woocommerce_form_field( 'subscriber_checkbox', array(
        'type' => 'checkbox',
        'class' => array('form-row-wide'),
        'label' => '&nbsp;Subscribe to our newsletter for updates.',
    ), $checkout->get_value( 'subscriber_checkbox' ) );
}

 

18. Block “PO Box” Shipping Addresses
Many courier services (like FedEx/UPS) don’t deliver to PO Boxes. Block them.

add_action( 'woocommerce_checkout_process', 'musa_block_pobox' );

function musa_block_pobox() {
    $address = $_POST['shipping_address_1'];
    if ( preg_match( '/(p\.?o\.?|post\s+office)\s+box/i', $address ) ) {
        wc_add_notice( __( 'Sorry, we do not ship to PO Boxes. Please use a physical address.' ), 'error' );
    }
}

 

19. Remove the “Privacy Policy” Text
If you want to simplify the footer area (make sure you still link to it somewhere else legally).

remove_action( 'woocommerce_checkout_terms_and_conditions', 'wc_checkout_privacy_policy_text', 20 );

 

20. Limit Checkout to One Product Only
Useful for membership sites or specific funnels where you only want 1 item per order.

add_filter( 'woocommerce_add_to_cart_validation', 'musa_only_one_item_in_cart', 10, 2 );

function musa_only_one_item_in_cart( $passed, $product_id ) {
    wc_empty_cart(); // Empties cart before adding new item
    return $passed;
}

 

21. Add Content/Banner Above Checkout Form
Insert a trust banner or urgent notice.

add_action( 'woocommerce_before_checkout_form', 'musa_add_content_above_checkout', 1 );

function musa_add_content_above_checkout() {
    echo '<img src="https://yourwebsite.com/wp-content/uploads/trust-badges.png" style="width:100%; margin-bottom:20px;">';
}

 

22. Make “State” Field Optional
In some countries, the State field is confusing or not needed.

add_filter( 'woocommerce_billing_fields', 'musa_optional_state_field' );

function musa_optional_state_field( $fields ) {
    $fields['billing_state']['required'] = false;
    return $fields;
}

 

23. Auto-Complete User Info (If Logged In)
Usually default behavior, but sometimes themes break it. This forces user info into fields.

add_filter( 'woocommerce_checkout_get_value', 'musa_autofill_checkout', 10, 2 );

function musa_autofill_checkout( $value, $input ) {
    if ( is_user_logged_in() && empty( $value ) ) {
        $current_user = wp_get_current_user();
        if ( 'billing_first_name' === $input ) {
            return $current_user->user_firstname;
        }
    }
    return $value;
}

 

24. Add a Custom Fee (e.g., Handling Fee)
Add a flat $5 fee to every order.

add_action( 'woocommerce_cart_calculate_fees', 'musa_add_custom_surcharge' );

function musa_add_custom_surcharge() {
    if ( is_admin() && ! defined( 'DOING_AJAX' ) ) return;
    $fee = 5.00; // Fee amount
    WC()->cart->add_fee( 'Handling Fee', $fee );
}

 

25. Disable “Order Notes” Field completely (Alternative method)
Another robust way to remove the notes field if the unset method doesn’t work for your theme.

add_filter( 'woocommerce_enable_order_notes_field', '__return_false', 9999 );

These 25 snippets cover 95% of the customization requests I get from clients. Using these instead of plugins will keep your database clean and your site fast.

Need a custom logic that isn’t listed here? I write custom PHP solutions for WooCommerce. Hire me and let’s build the perfect checkout flow for your business.

⚠️ Important Note for New WooCommerce Users: These code snippets work best with the Classic Checkout shortcode [woocommerce_checkout]. If you are using the new WooCommerce Blocks, these snippets might not function visually. I highly recommend switching to the Classic Checkout for full control over your design and logic.

Leave a Reply

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

Back to top button