Website Consultancy and Free Advice

WooCommerce Checkout Page Snippets and Hooks – 2017

Checkout

Quick Links:

  1. HIDE COUPON FILED FROM THE CHECKOUT PAGE
  2. REMOVE ORDER NOTES FROM CHECKOUT FORM
  3. REMOVE UNCESSASARY CHECKOUT FIELDS – PAYPAL USERS ONLY

Hide Coupon filed from the checkout page

Inorder to stip down the checkout process some clients want to remove any other form elements other than the “Checkout Button”, giving the user less options will only allow them to click checkout. The coupon field is already on the cart so we can remove it from the checkout form using the snippet below.
Instructions: Add to your Theme functions.php file


// hide coupon form checkout
function hide_coupon_field_chkout( $enabled ) {
	if ( is_checkout() ) {
		$enabled = false;
	}	
	return $enabled;
}
add_filter( 'woocommerce_coupons_enabled', 'hide_coupon_field_chkout' );

Remove order notes from checkout form

In some client cases Order Notes are not necessary and can distract the user and make the form longer and more daunting to the user. You can simply remove the field as its not a Required field using the snippter below.
Instructions: Add to your Theme functions.php file


// Remove the "Additional Info" order notes
add_filter( 'woocommerce_enable_order_notes_field', '__return_false' );

Remove uncessasary checkout fields – Paypal users ONLY

If you are only using PayPal as your payment gateway you do not require billing address fields. Please not if your taking payments from Credit/Debit Cards direct or using services such as Stripe DO NOT USE THIS CODE!

Instructions: Add to your Theme functions.php file


// Unset billing fields ONLY if using Pay Pal ONLY
function unset_billing_checkout_fields( $fields ) {
    
    // list of the billing field keys to remove
    $billing_keys = array(
        'billing_company',
        'billing_phone',
        'billing_address_1',
        'billing_address_2',
        'billing_city',
        'billing_postcode',
        'billing_country',
        'billing_state',
    );

    // unset billing fields
    foreach( $billing_keys as $key ) {
        unset( $fields['billing'][$key] );
    }
    
    return $fields;
}
add_filter( 'woocommerce_checkout_fields', 'unset_billing_checkout_fields' );