Created
May 9, 2023 11:08
-
-
Save xlplugins/01ecd91001b230247072a8556f840614 to your computer and use it in GitHub Desktop.
Display VAT (TVA )Custom field on checkout for WholeSale User
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class WFACP_woocommerce_checkout_fields { | |
public $new_fields = []; | |
public function __construct() { | |
/* Create Advance Field */ | |
add_filter( 'wfacp_advanced_fields', [ $this, 'add_fields' ] ); | |
add_filter( 'wfacp_forms_field', [ $this, 'hide_field' ], 99, 2 ); | |
} | |
private function is_b2b_roles() { | |
if ( ! is_user_logged_in() ) { | |
return false; | |
} | |
$user = wp_get_current_user(); | |
if ( ! $user instanceof WP_User ) { | |
return false; | |
} | |
return in_array( 'wholesale_customer', $user->roles ); | |
} | |
public function add_fields( $fields ) { | |
$fields['wwlc_cf_siret_field'] = [ | |
'id' => 'wwlc_cf_siret_field', | |
'type' => 'text', | |
'label' => 'Numéro SIRET', | |
'palaceholder' => 'TVA', | |
'data_label' => 'Numéro SIRET', | |
'required' => false, | |
'default' => '', | |
'field_type' => 'advanced', | |
'class' => [ 'wfacp-col-full', 'wfacp-form-control-wrapper', 'wfacp_date_field' ], | |
]; | |
return $fields; | |
} | |
public function hide_field( $field, $id ) { | |
if ( $id == 'wwlc_cf_siret_field' && false == $this->is_b2b_roles() ) { | |
return []; | |
} | |
return $field; | |
} | |
} | |
new WFACP_woocommerce_checkout_fields(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment