Skip to content

Instantly share code, notes, and snippets.

@xlplugins
Created December 23, 2024 08:30
Show Gist options
  • Save xlplugins/5a6dd673ffe776c336bb6131365acaa3 to your computer and use it in GitHub Desktop.
Save xlplugins/5a6dd673ffe776c336bb6131365acaa3 to your computer and use it in GitHub Desktop.
Checkout : landmark field in Shipping field
class WFACP_ADD_Custom_Fields_Under_Billing_Shipping {
public $custom_fields = [];
public function __construct() {
$this->assign_variables();
add_action( 'after_setup_theme', [ $this, 'setup_fields' ] );
}
public function assign_variables() {
$this->custom_fields = [
'shipping' => [
'nl1' => [
'type' => 'text',
'label' => __( 'Landmark', 'woocommerce' ),
'placeholder' => __( 'Landmark', 'woocommerce' ),
'class' => array( 'form-row-wide', 'wfacp-col-left-half' ),
'id' => 'landmark',
'field_type' => 'shipping',
'required' => true,
'priority' => 100,
],
]
];
}
public function setup_fields() {
if ( isset( $this->custom_fields['billing'] ) && is_array( $this->custom_fields['billing'] ) && count( $this->custom_fields['billing'] ) > 0 ) {
foreach ( $this->custom_fields['billing'] as $billing_key => $billing_value ) {
new WFACP_Add_Address_Field( $billing_key, $billing_value );
}
}
if ( isset( $this->custom_fields['shipping'] ) && is_array( $this->custom_fields['shipping'] ) && count( $this->custom_fields['shipping'] ) > 0 ) {
foreach ( $this->custom_fields['shipping'] as $shipping_key => $shipping_value ) {
new WFACP_Add_Address_Field( $shipping_key, $shipping_value, 'shipping' );
}
}
}
}
new WFACP_ADD_Custom_Fields_Under_Billing_Shipping();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment