Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save helgatheviking/c54b5b40c0b3ce07c7784cdd19c044f3 to your computer and use it in GitHub Desktop.
Save helgatheviking/c54b5b40c0b3ce07c7784cdd19c044f3 to your computer and use it in GitHub Desktop.
Add Step to JC WooCommerce Multistep Checkout
/*
* Add new checkout fields
* See: https://www.kathyisawesome.com/woocommerce-customize-checkout-fields/ for saving/displaying order meta
*/
function kia_filter_checkout_fields( $fields ){
$fields['extra_fields'] = array(
'some_field' => array(
'type' => 'text',
'label' => __( 'Some field', 'your-plugin-textdomain' )
),
'another_field' => array(
'type' => 'checkbox',
'label' => __( 'Another field', 'your-plugin-textdomain' )
)
);
return $fields;
}
add_filter( 'woocommerce_checkout_fields', 'kia_filter_checkout_fields' );
/*
* Display the extra field on the checkout form by adding to a multistep checkout hook
* As long as the HTML markup is <h1>Step Title</h1<div>Your Fields Here</div>
* Your "step" will be added automatically by the jQuery Steps script
*/
function kia_extra_checkout_fields( $checkout ){
if( ! empty( $checkout->checkout_fields['extra_fields'] ) ){ ?>
<h1 class="title-extra"><?php _e( 'Additional Fields', 'your-plugin-textdomain' ); ?></h1>
<div class="extra-tab-contents">
<?php
// because of this foreach, everything added to the array in the previous function will display automagically
foreach ( $checkout->checkout_fields['extra_fields'] as $key => $field ) : ?>
<?php woocommerce_form_field( $key, $field, $checkout->get_value( $key ) ); ?>
<?php endforeach; ?>
</div>
<?php }
}
add_action( 'woocommerce_multistep_checkout_before_order_info', 'kia_extra_checkout_fields' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment