'string', 'default' => 'No' ); } return $attributes; } add_action( 'wppb_fb_enqueue_editor_assets_late', 'wppb_in_woo_fb_enqueue_editor_payload' ); function wppb_in_woo_fb_enqueue_editor_payload() { $allowed = array_intersect( wppb_in_woo_fb_checkout_field_types(), wppb_fb_all_field_type_labels() ); if ( ! empty( $allowed ) ) { $schema = array( 'woocommerce-checkout-field' => array( 'type' => 'string', 'default' => 'No' ) ); $extra = array(); foreach ( $allowed as $ft ) { $extra[ $ft ] = $schema; } wppb_fb_extra_attributes_inline_script( $extra ); } wppb_fb_register_extra_field_control( array( 'attribute' => 'woocommerce-checkout-field', 'label' => __( 'Display on WooCommerce Checkout', 'profile-builder' ), 'help' => __( 'Add this field to the WooCommerce checkout form.', 'profile-builder' ), 'control' => 'toggle', 'onValue' => 'Yes', 'offValue' => 'No', // Classic strips this from Repeater sub-fields; pair with stripped-attrs above. 'hideInsideRepeater' => true, ) ); $payload = array( 'billingFields' => wppb_in_woo_fb_field_list( 'billing' ), 'shippingFields' => wppb_in_woo_fb_field_list( 'shipping' ), ); wp_add_inline_script( 'wppb-form-editor-bundle', 'window.wppbFb = window.wppbFb || {}; window.wppbFb.woocommerce = ' . wp_json_encode( $payload ) . ';', 'before' ); } /* Convert legacy { key => [label, required] } to [ {key,label,required} ] for the editor. */ function wppb_in_woo_fb_field_list( $kind ) { $map = array(); if ( $kind === 'billing' && function_exists( 'wppb_in_woo_get_billing_fields' ) ) { $map = wppb_in_woo_get_billing_fields(); } elseif ( $kind === 'shipping' && function_exists( 'wppb_in_woo_get_shipping_fields' ) ) { $map = wppb_in_woo_get_shipping_fields(); } $out = array(); if ( is_array( $map ) ) { foreach ( $map as $key => $def ) { $out[] = array( 'key' => (string) $key, 'label' => isset( $def['label'] ) ? $def['label'] : (string) $key, 'required' => isset( $def['required'] ) ? $def['required'] : 'No', ); } } return $out; }