Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save wplaunchify/29305f1546c4ad7e4dde8be2a7733aff to your computer and use it in GitHub Desktop.
Save wplaunchify/29305f1546c4ad7e4dde8be2a7733aff to your computer and use it in GitHub Desktop.
LaunchFlows - Pluggable functions to unset, reorder, make not-required, or style into full width, first column or second column position
// adds inline style for leadmagnet
add_action('woocommerce_before_checkout_form', 'lf_leadmagnet_style');
if (! function_exists ('lf_leadmagnet_style') ) { // make pluggable
function lf_leadmagnet_style() {
?>
<style id="lf-leadmagnet">
.woocommerce-billing-fields h3 {
display: none;
}
.woocommerce-shipping-fields {
display: none;
}
.woocommerce-additional-fields {
display: none;
}
#order_review {
border-width: 0;
width: 100%;
float: none;
margin-right: 0;
padding: 0;
clear: none;
}
#order_review table {
display: none;
}
#order_review_heading {
display: none;
}
</style>
<?php
}
}
// remove the Coupon Toggle
remove_action( 'woocommerce_before_checkout_form', 'woocommerce_checkout_coupon_form', 10 );
// remove the "Additional Info" order notes
add_filter( 'woocommerce_enable_order_notes_field', '__return_false' );
// unset billing fields
add_filter( 'woocommerce_checkout_fields' , 'lf_remove_checkout_fields' );
if (! function_exists ('lf_remove_checkout_fields') ) { // make pluggable
function lf_remove_checkout_fields( $fields ) {
if ( lf_leadmagnet_is_in_the_cart() ) {
unset( $fields['billing']['billing_company'] );
unset( $fields['billing']['billing_state'] );
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'] );
// remove shipping fields
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']);
// remove order comment fields
unset($fields['order']['order_comments']);
}
return $fields;
}
}
// non-required, reorder, add class
add_filter( 'woocommerce_billing_fields' , 'lf_remove_billing_fields' );
if (! function_exists ('lf_remove_billing_fields') ) { // make pluggable
function lf_remove_billing_fields( $fields ) {
if ( lf_leadmagnet_is_in_the_cart() ) {
// reorder
$fields['billing_company']['required'] = false;
$fields['billing_phone']['required'] = false;
$fields['billing_state']['required'] = false;
$fields['billing_address_1']['required'] = false;
$fields['billing_address_2']['required'] = false;
$fields['billing_city']['required'] = false;
$fields['billing_postcode']['required'] = false;
$fields['billing_country']['required'] = false;
// reorder
$fields['billing_first_name']['priority'] = 9;
$fields['billing_last_name']['priority'] = 9;
$fields['billing_email']['priority'] = 10;
$fields['billing_phone']['priority'] = 11;
// class
$fields['billing_email']['class'] = array('form-row-first');
$fields['billing_phone']['class'] = array('form-row-last');
}
return $fields;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment