Advertisement
Guest User

Untitled

a guest
Mar 24th, 2019
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.34 KB | None | 0 0
  1. <?php
  2. add_filter( 'wfacp_billing__field', 'check_wc_validations', 10, 2 );
  3.  
  4. function check_wc_validations( $address_fields, $type ) {
  5. $woocommerce_checkout_address_2_field = get_option( 'woocommerce_checkout_address_2_field', 'optional' );
  6. $woocommerce_checkout_company_field = get_option( 'woocommerce_checkout_company_field', 'optional' );
  7.  
  8.  
  9. if ( 'required' === $woocommerce_checkout_address_2_field ) {
  10. $requiredFor = true;
  11. } else {
  12. $requiredFor = false;
  13. }
  14.  
  15. if ( 'required' === $woocommerce_checkout_company_field ) {
  16. $requiredForCompany = true;
  17. } else {
  18. $requiredForCompany = false;
  19. }
  20.  
  21.  
  22. if ( isset( $address_fields['billing_address_2'] ) || isset( $address_fields['shipping_address_2'] ) ) {
  23. if ( ( isset( $address_fields['billing_address_2']['required'] ) && false === $requiredFor ) || ( isset( $address_fields['shipping_address_2']['required'] ) && false === $requiredFor ) ) {
  24. unset( $address_fields['billing_address_2']['required'] );
  25. }
  26.  
  27. }
  28.  
  29. if ( isset( $address_fields['billing_company'] ) || isset( $address_fields['shipping_company'] ) ) {
  30. if ( ( isset( $address_fields['billing_company']['required'] ) && false === $requiredForCompany ) || ( isset( $address_fields['shipping_company']['required'] ) && false === $requiredForCompany ) ) {
  31. unset( $address_fields['billing_company']['required'] );
  32. }
  33.  
  34. }
  35.  
  36.  
  37. return $address_fields;
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement