Adding Timezone dropdown to vendor settings page

We're shifting our Forum based support to a more dedicated support system!

We'll be closing our Forum support from 10th June, 2020 and move to Email Support assistance.

  • If you are a WCFM premium add-ons user, contact us- here
  • Want to know more before buying our add-ons? Send Pre sale queries- here
  • If you are a WCFM free user, please open a support ticket at WordPress.org
  • For WCFM App related queries, reach us- here
From now the forum will be read-only!

Multi Vendor Marketplace Plugin | WCFM Marketplace Forums WCFM Adding Timezone dropdown to vendor settings page

Viewing 10 reply threads
  • Author
    Posts
    • #89959
      me
      Participant

      I’ve been trying to implement a Timezone setting for vendors, but I need some help with it.
      I have summarized what I have done so far below, but I’m open to any solution that lets vendors set and save their timezones.
      Can you help me on how to do that in any way?

      First, I tried placing it in general settings, like this:

      
      add_filter ( 'wcfm_marketplace_settings_fields_general', 'add_vendor_timezone_setting', 20 );
      function add_vendor_timezone_setting($settings_fields_general){
          $vendor_id = $settings_fields_general['vendor_id']['value'];
          $vendor_data = get_user_meta( $vendor_id, 'wcfmmp_profile_settings', true );
          if( !$vendor_data ) $vendor_data = array();
          $timezone_list = DateTimeZone::listIdentifiers(DateTimeZone::ALL);
          $vendor_timezone = isset( $vendor_data['timezone'] ) ? $vendor_data['timezone'] : '';
          $settings_fields_general['timezone']= array(
              'label' => __( 'Timezone', 'wc-frontend-manager' ),
              'type' => 'select',
              'options' => $timezone_list,
              'priority' => 50,
              'class' => 'wcfm-text wcfm_ele',
              'label_class' => 'wcfm_title wcfm_ele',
              'value' => $vendor_timezone,
          );
          return $settings_fields_general;
      }
      
      add_action( 'wcfm_vendor_settings_update', function( $vendor_id, $wcfm_settings_form ) {
      	global $WCFM, $WCFMmp;
      	if( isset( $wcfm_settings_form['timezone'] ) ) {
      	    update_user_meta( get_current_user_id(), 'vendor_timezone',  $wcfm_settings_form['timezone'] );
          }
      }, 500, 2 );
      

      If I do this, strangely it creates TWO dropdowns on the same page. (see screenshot)
      Also, saving the data doesn’t work at all.

      I also tried putting the dropdown on a separate tab, and using AJAX for saving:

      (js)

      
      $(document).on('click', '#wcfm_settings_save_button', function (e) {
                  e.preventDefault();
                  var user_timezone = jQuery('#vendor-timezone').val();
                  if ( user_timezone !== "" ) {
                      jQuery.post(
                              ajaxurl,
                              {
                                  'action': 'update_vendor_timezone',
                                  'user_timezone': user_timezone,
                              },
                              function(response) { alert(response); }
                      );
                  }
              });
      

      (php)

      
      add_action('wp_ajax_update_vendor_timezone', 'update_vendor_timezone');
      
      function update_vendor_timezone(){
              if(isset($_POST['user_timezone'])){        
                  update_user_meta(get_current_user_id(), 'vendor-timezone', $_POST['user_timezone']);
              }
              die();
          }
      

      Thanks a lot for your help in advance.

      Attachments:
      You must be logged in to view attached files.
    • #91745
      Eden Brownlee
      Participant

      Is anything happening on this, we really need this feature too so that appointments/bookings made with WCFM appear in shopper/user timezone (we use bookingWP), and that vendors can set availability for booking in their own timezone (and set that).

      Please help!

      • #91855
        me
        Participant

        Hi Eden,

        I have good news, I managed to get this done. The part discussed here is pretty straight-forward, things get tricky on the other side with wc-appointments.
        I’ll give you the code for the Timezone dropdown inside WCFM Vendor Settings, and we can discuss the rest in the BookingWP forum.
        Let me know how it works for you!

        
        add_action( 'end_wcfm_marketplace_settings', 'wcfm_vendor_timezone_settings' );
        
        function wcfm_vendor_timezone_settings() {
            global $WCFM, $WCFMu;
            ?>
            <div class="page_collapsible" id="wcfm_settings_form_timezone_head"><label class="wcfmfa fa-clock"></label>
        
                <?php _e('Timezone', 'wc-frontend-manager-ultimate'); ?>
        
                <span></span></div>
        		<div class="wcfm-container">
                <div id="wcfm_settings_form_timezone_expander" class="wcfm-content">
                <div class="wcfm-content">                
                        
                <p class="wcfm_title"><strong>
        
                <?php _e('Select your timezone', 'wc-frontend-manager-ultimate'); ?>
        
                </strong>
                <span class="img_tip wcfmfa fa-question" data-tip="This is important for clients outside your timezone." data-hasqtip="23" aria-describedby="qtip-23">
                </span>
                </p>
                <select id="spiral-vendor-timezone" name="spiral-vendor-timezone">
                    <?php
                    $timezone_list = DateTimeZone::listIdentifiers(DateTimeZone::ALL);
                    $user_data = get_user_meta( get_current_user_id(), 'wcfmmp_profile_settings', true );
                    if( !$user_data ) $user_data = array();
                    $user_timezone = isset( $user_data['spiral-vendor-timezone'] ) ? $user_data['spiral-vendor-timezone'] : '';
                    foreach($timezone_list as $key => $val) {
                        if ($user_timezone==$val) {
                            echo '<option selected value="' . $val . '" >' . $val . '</option>';
                        } else {
                        echo '<option value="' . $val . '">' . $val . '</option>';
                        }
                    }
                    ?>
                </select>
        
                        <br><br><i class="fa fa-exclamation-triangle" aria-hidden="true"></i> Experimental feature
                
                </div></div>
                </div>
            <?php
        }
        
    • #92706
      Eden Brownlee
      Participant

      Hi ME, we are now looking to implement this shortly.

      Did you happen to send the plugin (per last request from bookingWP)

      https://bookingwp.com/forums/topic/here-is-the-code-required-for-custom-timezones-to-work-pls-merge-w-official/

    • #93533
      WCFM Forum
      Member

      We are working on this.

      Well, this may cause other issues, so we are not released this!

    • #93807
      Eden Brownlee
      Participant

      WCFM, Any update on this?

      Would it be possible to even get this as a beta option added to core, and just let us know how to turn it on? This would be great if we can get it rolled out into release and just enable it as a setting. We can test it for you and let you know if we experience any issues.

    • #96106
      Eden Brownlee
      Participant

      Hi WCFM,

      Can we get a response on this? Can we get this added to core? (Again, even as a hidden beta feature so we do not have to edit core files and can continue to update wcfm etc)

    • #96431
      WCFM Forum
      Member

      Well, we have prepared that code.

      But, this setting is not enough to make this working. We have to show all dates in vendor dashboard according to this timezone setting!

    • #96812
      Eden Brownlee
      Participant

      Is there an ETA on this? Surely it would not be too difficult to update current function to use the timezone setting? 🙂 I hope we can get this actioned sometime in the near future 😀

    • #97159
      WCFM Forum
      Member

      Our team is working on this. Will update you soon.

    • #97187
      Eden Brownlee
      Participant

      Awesome thanks so much 🙂 looking forward to hearing back from you guys! 🙂

    • #105288
      Eden Brownlee
      Participant

      Hey there guys, another couple months down, any progress in rolling this out? 🙂 Really need this asap as core hacks are not cool 😀

Viewing 10 reply threads
  • The topic ‘Adding Timezone dropdown to vendor settings page’ is closed to new replies.