Advertisement
palsushobhan

wcfm-vendor-age-from-custom-field-dob

Jun 2nd, 2024
747
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.22 KB | None | 0 0
  1. add_action('wcfmmp_store_list_after_store_info', function($store_id) {
  2.     $wcfmmp_addition_info_fields = wcfm_get_option( 'wcfmvm_registration_custom_fields', array() );
  3.     if( empty( $wcfmmp_addition_info_fields ) ) return;
  4.     $has_addition_field = false;
  5.     if( !empty( $wcfmmp_addition_info_fields ) ) {
  6.         foreach( $wcfmmp_addition_info_fields as $wcfmvm_registration_custom_field ) {
  7.             if( !isset( $wcfmvm_registration_custom_field['enable'] ) ) continue;
  8.             if( !$wcfmvm_registration_custom_field['label'] ) continue;
  9.             $has_addition_field = true;
  10.             break;
  11.         }
  12.     }
  13.     if( !$has_addition_field ) return;
  14.     $wcfmvm_custom_infos = (array) get_user_meta( $store_id, 'wcfmvm_custom_infos', true );
  15.     if( !empty( $wcfmmp_addition_info_fields ) ) {
  16.         $label = 'DOB';
  17.         $name = sanitize_title( $label );
  18.         $field = $wcfmvm_custom_infos[$name] ?? '';
  19.         if($field) {
  20.             $age = DateTime::createFromFormat('d/m/Y', $field);
  21.             $currentDate = new DateTime();
  22.             echo '<p class="store-phone"><i class="wcfmfa fa-birthday-cake" aria-hidden="true"></i> Age: ' . $currentDate->diff($age)->y . ' years</p>';
  23.         }
  24.     }
  25. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement