Skip to content

Instantly share code, notes, and snippets.

@xlplugins
Last active June 11, 2026 09:04
Show Gist options
  • Select an option

  • Save xlplugins/4b4d23110cd0e3d597e806b4c83d83eb to your computer and use it in GitHub Desktop.

Select an option

Save xlplugins/4b4d23110cd0e3d597e806b4c83d83eb to your computer and use it in GitHub Desktop.
Relocate billing_company
/**
* Relocate billing_company / shipping_company on FunnelKit Checkout —
* ONLY on the checkout IDs you list below.
*/
add_filter( 'wfacp_get_fieldsets', function ( $fieldsets ) {
/* ---- EDIT THIS ----------------------------------------------------
* 1) Which checkouts should this run on? Put their checkout IDs here.
* Find the ID in the editor URL: admin.php?page=wfacp&wfacp_id=123
*/
$enabled_checkout_ids = array( 123, 456 ); // <-- your checkout IDs
/* 2) Where each company field should go (anchor + before/after). */
$placement = array(
'billing_company' => array( 'anchor' => 'billing_email', 'position' => 'after' ),
'shipping_company' => array( 'anchor' => 'shipping_address_1', 'position' => 'after' ),
);
/* ---- STOP EDITING -------------------------------------------------- */
if ( ! is_array( $fieldsets ) || ! class_exists( 'WFACP_Common' ) ) {
return $fieldsets;
}
// Only act on the selected checkouts.
$current_id = absint( WFACP_Common::get_id() );
if ( ! in_array( $current_id, array_map( 'absint', $enabled_checkout_ids ), true ) ) {
return $fieldsets;
}
foreach ( $fieldsets as $step => $sections ) {
if ( ! is_array( $sections ) ) {
continue;
}
// 1) Capture the real company field objects and remove them from wherever they sit.
$captured = array();
foreach ( $sections as $s_index => $section ) {
if ( empty( $section['fields'] ) || ! is_array( $section['fields'] ) ) {
continue;
}
foreach ( $section['fields'] as $f_index => $field ) {
$fid = isset( $field['id'] ) ? $field['id'] : '';
if ( isset( $placement[ $fid ] ) ) {
$captured[ $fid ] = $field;
unset( $fieldsets[ $step ][ $s_index ]['fields'][ $f_index ] );
}
}
$fieldsets[ $step ][ $s_index ]['fields'] = array_values( $fieldsets[ $step ][ $s_index ]['fields'] );
}
if ( empty( $captured ) ) {
continue;
}
// 2) Drop each captured field next to its anchor (before/after).
foreach ( $captured as $company_id => $company_field ) {
$anchor = $placement[ $company_id ]['anchor'];
$position = ( isset( $placement[ $company_id ]['position'] ) && 'before' === $placement[ $company_id ]['position'] ) ? 'before' : 'after';
$inserted = false;
foreach ( $fieldsets[ $step ] as $s_index => $section ) {
if ( empty( $section['fields'] ) || ! is_array( $section['fields'] ) ) {
continue;
}
foreach ( $section['fields'] as $f_index => $field ) {
if ( isset( $field['id'] ) && $field['id'] === $anchor ) {
$offset = ( 'before' === $position ) ? $f_index : $f_index + 1;
array_splice( $fieldsets[ $step ][ $s_index ]['fields'], $offset, 0, array( $company_field ) );
$inserted = true;
break 2;
}
}
}
if ( ! $inserted && isset( $fieldsets[ $step ][0]['fields'] ) ) {
$fieldsets[ $step ][0]['fields'][] = $company_field;
}
}
}
return $fieldsets;
}, 20 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment