Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- add_filter( 'wfacp_billing__field', 'check_wc_validations', 10, 2 );
- function check_wc_validations( $address_fields, $type ) {
- $woocommerce_checkout_address_2_field = get_option( 'woocommerce_checkout_address_2_field', 'optional' );
- $woocommerce_checkout_company_field = get_option( 'woocommerce_checkout_company_field', 'optional' );
- if ( 'required' === $woocommerce_checkout_address_2_field ) {
- $requiredFor = true;
- } else {
- $requiredFor = false;
- }
- if ( 'required' === $woocommerce_checkout_company_field ) {
- $requiredForCompany = true;
- } else {
- $requiredForCompany = false;
- }
- if ( isset( $address_fields['billing_address_2'] ) || isset( $address_fields['shipping_address_2'] ) ) {
- if ( ( isset( $address_fields['billing_address_2']['required'] ) && false === $requiredFor ) || ( isset( $address_fields['shipping_address_2']['required'] ) && false === $requiredFor ) ) {
- unset( $address_fields['billing_address_2']['required'] );
- }
- }
- if ( isset( $address_fields['billing_company'] ) || isset( $address_fields['shipping_company'] ) ) {
- if ( ( isset( $address_fields['billing_company']['required'] ) && false === $requiredForCompany ) || ( isset( $address_fields['shipping_company']['required'] ) && false === $requiredForCompany ) ) {
- unset( $address_fields['billing_company']['required'] );
- }
- }
- return $address_fields;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement