Skip to content

Instantly share code, notes, and snippets.

@helgatheviking
Created December 12, 2019 15:12
Show Gist options
  • Save helgatheviking/6776bf4c67e43c0012cb76cc996a17b1 to your computer and use it in GitHub Desktop.
Save helgatheviking/6776bf4c67e43c0012cb76cc996a17b1 to your computer and use it in GitHub Desktop.
Reduce WooCommerce checkout to the bare minimum
<?php
/**
* Plugin Name: WC Minimalize Checkout Settings
* Plugin URI: https://woocommerce.com/
* Description: Reduce checkout to the bare minimum.
* Version: 1.0.0
* Author: Kathy Darling
* Author URI: http://kathyisawesome.com/*
* Requires at least: 5.3.0
* Tested up to: 5.3.0
*
* WC requires at least: 3.7.0
* WC tested up to: 3.8.0
*
* Copyright: © 2019 Kathy Darling
* License: GNU General Public License v3.0
* License URI: http://www.gnu.org/licenses/gpl-3.0.html
*/
// Exit if accessed directly.
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
/**
* Minimize required checkout fields for local testing
*/
function kia_checkout_simplification() {
add_filter( 'woocommerce_checkout_fields', 'kia_checkout_fields' );
add_filter( 'woocommerce_default_address_fields', 'kia_modify_default_address_fields' );
add_filter( 'woocommerce_billing_fields', 'kia_remove_billing_fields' );
add_filter( 'woocommerce_cart_needs_shipping_address', '__return_false' );
add_filter( 'woocommerce_enable_order_notes_field', '__return_false' );
}
add_action( 'woocommerce_init', 'kia_checkout_simplification' );
function kia_checkout_fields( $fields ){
if( isset( $fields['shipping'] ) ){
$fields['shipping'] = array();
}
return $fields;
}
function kia_modify_default_address_fields( $fields ){
if( isset( $fields['country'] ) ) unset( $fields['country'] );
if( isset( $fields['address_1'] ) ) unset( $fields['address_1'] );
if( isset( $fields['address_2'] ) ) unset( $fields['address_2'] );
if( isset( $fields['city'] ) ) unset( $fields['city'] );
if( isset( $fields['state'] ) ) unset( $fields['state'] );
if( isset( $fields['postcode'] ) ) unset( $fields['postcode'] );
return $fields;
}
function kia_remove_billing_fields( $fields ){
if( isset( $fields['billing_phone'] ) ) unset( $fields['billing_phone'] );
if( isset( $fields['billing_last_name'] ) ) unset( $fields['billing_last_name'] );
if( isset( $fields['billing_company'] ) ) unset( $fields['billing_company'] );
if( isset( $fields['billing_first_name'] ) ) $fields['billing_first_name']['class'] = array( 'form-row-wide' );
if( isset( $fields['billing_email'] ) ) $fields['billing_email']['class'] = array( 'form-row-wide' );
return $fields;
}
function kia_remove_related_products_and_tabs(){
remove_action( 'woocommerce_after_single_product_summary', 'woocommerce_output_product_data_tabs', 10 );
remove_action( 'woocommerce_after_single_product_summary', 'woocommerce_upsell_display', 15 );
remove_action( 'woocommerce_after_single_product_summary', 'woocommerce_output_related_products', 20 );
}
add_action( 'woocommerce_before_single_product_summary', 'kia_remove_related_products_and_tabs' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment