Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- add_filter('wcfm_profile_fields_general', function($fields, $user_id) {
- $birth_month = get_user_meta($user_id, 'user_birth_month', true);
- $birth_date = get_user_meta($user_id, 'user_birth_date', true);
- $month_options = ['Select month', 'January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'];
- $days = ['Select date', 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31];
- $birthday = array(
- "birth_month" => array('label' => __('Birthday', 'wc-frontend-manager') , 'type' => 'select', 'options' => $month_options, 'class' => 'wcfm-select wcfm_ele birth_field', 'label_class' => 'wcfm_title wcfm_ele', 'value' => $birth_month ),
- "birth_date" => array('type' => 'select', 'options' => $days, 'class' => 'wcfm-select wcfm_ele birth_field', 'label_class' => 'wcfm_title wcfm_ele', 'value' => $birth_date ),
- );
- if(!$birth_date) {
- $birthday['birth_date']['attributes'] = array( 'disabled' => 'disabled' );
- }
- return array_merge($fields, $birthday);
- }, 10, 2);
- add_action('end_wcfm_user_profile', function() {
- ?>
- <style>
- #wcfm_profile_personal_expander select.birth_field {
- width: 29%;
- }
- #wcfm_profile_personal_expander select.birth_field:first-of-type {
- margin-right: 2%;
- }
- </style>
- <script>
- jQuery(function($) {
- $('#wcfm_profile_personal_expander select#birth_month').change(function() {
- var monthSelection = $(this).val();
- var $dateDropdown = $('#wcfm_profile_personal_expander select#birth_date');
- if(monthSelection > 0) {
- var month_total_days = [31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];
- var monthDays = month_total_days[monthSelection-1];
- $dateDropdown.find('option').css('display', '');
- for(i = monthDays+1; i<=31; i++) {
- $dateDropdown.find('option').eq(i).css('display', 'none');
- }
- $dateDropdown.prop('disabled', false);
- } else {
- $dateDropdown[0].selectedIndex = 0;
- $dateDropdown.prop('disabled', true);
- }
- });
- });
- </script>
- <?php
- });
- add_action('wcfm_profile_update', function($user_id, $wcfm_profile_form) {
- if(!empty($wcfm_profile_form['birth_month']) && !empty($wcfm_profile_form['birth_date'])) {
- update_user_meta($user_id, 'user_birth_month', $wcfm_profile_form['birth_month']);
- update_user_meta($user_id, 'user_birth_date', $wcfm_profile_form['birth_date']);
- } else {
- delete_user_meta($user_id, 'user_birth_month');
- delete_user_meta($user_id, 'user_birth_date');
- }
- }, 10, 2);
- add_shortcode('vendor_birthday', function($attr) {
- global $post;
- $store_id = '';
- if ( isset( $attr['id'] ) && ! empty( $attr['id'] ) ) {
- $store_id = absint( $attr['id'] );
- }
- if ( wcfm_is_store_page() ) {
- $wcfm_store_url = get_option( 'wcfm_store_url', 'store' );
- $store_name = apply_filters( 'wcfmmp_store_query_var', get_query_var( $wcfm_store_url ) );
- $store_id = 0;
- if ( ! empty( $store_name ) ) {
- $store_user = get_user_by( 'slug', $store_name );
- $store_id = $store_user->ID;
- }
- }
- if ( is_product() ) {
- $store_id = $post->post_author;
- }
- if( !$store_id ) return;
- $month_options = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'];
- $birth_month = get_user_meta($store_id, 'user_birth_month', true);
- $birth_date = get_user_meta($store_id, 'user_birth_date', true);
- $birth_date_str = $birth_date;
- if($birth_date % 10 == 0 || $birth_date % 10 > 3 || in_array($birth_date, [11, 12, 13])) $birth_date_str .= 'th ';
- elseif($birth_date % 10 == 1 ) $birth_date_str .= 'st ';
- elseif($birth_date % 10 == 2 ) $birth_date_str .= 'nd ';
- elseif($birth_date % 10 == 3 ) $birth_date_str .= 'rd ';
- $birth_date_str .= $month_options[$birth_month - 1];
- return "<p>{$birth_date_str}</p>";
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement