Banner Logo

Be a part of the family: Connect, Receive Support,
Contribute, and Reap Abundant Rewards

how to show checkbox value from vendor dashboard

MultivendorX

Resolved
Viewing 10 reply threads
  • Author
    Posts
    • #190023
      l.gan
      Participant

      Hello

      Thanks for your help

      Please tell me, I’m new to php, and I’m having difficulty with the output of the checkbox.

      My task – when setting the checkbox to the “yes” position – is to show on the page of any product of the vendor “Express delivery”.

      Below is the code – the value of the checkbox is saved, but unfortunately the value is not displayed.

      Please tell me what am I doing wrong?

      /*form for vendor dashboard set field*/
      add_action( ‘mvx_after_shop_front’, ‘extra_delivery_express’ );
      /*form for vendor dashboard set field*/
      function extra_delivery_express() {
      global $MVX;
      $vendor_id = get_current_vendor_id();
      $vendor_delivery_express = ”;
      $vendor_delivery_express = get_user_meta($vendor_id, ‘_vendor_delivery_express’, true) ? get_user_meta($vendor_id, ‘_vendor_delivery_express’, true) : $vendor_delivery_express;
      /*$vendor_delivery_express = get_post_meta($product->get_id() , ‘_vendor_delivery_express’, true );*/
      ?>

      <div class=”panel panel-default pannel-outer-heading”>
      <div class=”panel-heading d-flex”>
      <h3><?php _e(‘Express’, ‘multivendorx’); ?></h3>
      </div>
      <div class=”panel-body panel-content-padding form-horizontal”>
      <div class=”mvx_media_block”>
      <div class=”form-group”>
      <label class=”control-label col-sm-3 col-md-3″ for=”_vendor_delivery_express”>Express – 2 hour</label>
      <div class=”col-md-6 col-sm-9″>
      <input type=”hidden” name=”_vendor_delivery_express” value=”no”>
      <input type=”checkbox” id=”_vendor_delivery_express” name=”_vendor_delivery_express” value=”yes” <?php echo ($vendor_delivery_express==’yes’ ? ‘checked’ : ”);?>>
      </div>
      </div>

      </div>
      </div>
      </div>
      <?php
      }

      //save the field in database
      add_action(‘mvx_save_custom_store’, ‘save_field_delivery_express’, 10, 1);
      function save_field_delivery_express($user_id){

      $vendor_delivery_express = $_POST[‘_vendor_delivery_express’];
      update_user_meta($user_id, ‘_vendor_delivery_express’, $vendor_delivery_express);

      }

      //display
      add_action(‘woocommerce_single_product_summary’, ‘display_field_delivery_express’, 0);
      function display_field_delivery_express (){
      global $post;
      echo ‘code’;
      $vendor_delivery_express_display = get_user_meta($vendor->id, ‘_vendor_delivery_express’, true );
      if ( $vendor_delivery_express_display ) {
      /*echo ”;*/
      if ( $vendor_delivery_express_display === ‘yes’ ) {
      echo ‘Express delivery- 2 hour!’;
      } else {
      echo ‘No Express’;
      }
      echo ”;
      }

      }

      Thank your

    • #190032
      Anonymous
      Inactive

      It seems like the issue might be with the variable $vendor not being defined in the display_field_delivery_express() function. Try defining it using $vendor = get_userdata(get_the_author_meta(‘ID’)); before using it in the get_user_meta() function.

      • #190062
        l.gan
        Participant

        Hello
        thanks for the help
        please tell me what do you mean by this?

        add_action(‘woocommerce_single_product_summary’, ‘display_field_delivery_express’, 0);
        function display_field_delivery_express (){

        $vendor = get_userdata(get_the_author_meta(‘ID’));
        $vendor_delivery_express_display = get_user_meta($vendor->id, ‘_vendor_delivery_express’, true );
        if ( $vendor_delivery_express_display ) {

        if ( $vendor_delivery_express_display === ‘yes’ ) {
        echo ‘Express delivery- 2 hour!’;
        } else {
        echo ‘No Express’;
        }
        echo ”;
        }
        }

        unfortunately it doesn’t work…

      • #190067
        l.gan
        Participant

        sorry everything works fine
        Many thanks for the help @langnerfrancesco!

    • #190095
      l.gan
      Participant

      Hello

      sorry to bother you again, but could you help me with the code again? How to save the “selected” field correctly? I tried several options that I know but nothing worked for me, my code is below

      add_action( ‘mvx_after_shop_front’, ‘extra_delivery_express’ );
      /*form for vendor dashboard set field*/
      function extra_delivery_express() {
      global $MVX;
      $vendor_id = get_current_vendor_id();
      $vendor_delivery_express = ”;
      $vendor_delivery_express = get_user_meta($vendor_id, ‘_vendor_delivery_express’, true) ? get_user_meta($vendor_id, ‘_vendor_delivery_express’, true) : $vendor_delivery_express;
      $express_delivery_hour_vendor = ”;
      $express_delivery_hour_vendor = get_user_meta($vendor_id,’global_ex_hour_vendor’ );

      ?>

      <div class=”panel panel-default pannel-outer-heading”>
      <div class=”panel-heading d-flex”>
      <h3><?php _e(”, ‘multivendorx’); ?></h3>
      </div>
      <div class=”panel-body panel-content-padding form-horizontal”>
      <div class=”mvx_media_block”>

      <div class=”form-group”>
      <label class=”control-label col-sm-3 col-md-3″ for=”_vendor_delivery_express”></label>
      <div class=”col-md-6 col-sm-9″>
      <input type=”hidden” name=”_vendor_delivery_express” value=”no”>
      <input type=”checkbox” id=”myCheck” onclick=”myFunction()” name=”_vendor_delivery_express” value=”yes” <?php echo ($vendor_delivery_express==’yes’ ? ‘checked’ : ”);?>>
      </div>
      </div>

      <div class=”form-group” id=”text” style=”” >
      <label class=”control-label col-sm-3 col-md-3″></label>
      <div class=”col-md-6 col-sm-9″>
      <select name=”global_ex_hour_vendor” class=”form-control” value=””>
      <option selected value=””> — — </option>

      <?php if($express_delivery_hour_vendor){?>
      <option selected value=”<?php echo $express_delivery_hour_vendor; ?>”><?php echo $express_delivery_hour_vendor; ?></option>
      <?php }
      ?>

      <option>1</option>
      <option>2</option>
      <option>3</option>
      <option>4</option>
      <option>6</option>
      </select>
      </div>
      </div>

      </div>
      </div>
      </div>

      <script>
      function myFunction() {
      var checkBox = document.getElementById(“myCheck”);
      var text = document.getElementById(“text”);
      if (checkBox.checked == true){
      text.style.display = “block”;
      text2.style.display = “block”;
      } else {
      text.style.display = “none”;
      text2.style.display = “none”;
      }
      }
      </script>

      <?php
      }

      //save the field in database
      add_action(‘mvx_save_custom_store’, ‘save_field_delivery_express’, 10, 1);
      function save_field_delivery_express($user_id){

      $vendor_delivery_express = $_POST[‘_vendor_delivery_express’];
      update_user_meta($user_id, ‘_vendor_delivery_express’, $vendor_delivery_express);

      //?? how to save $express_delivery_hour_vendor

      }

    • #190127

      Hello , kindly add the below code to save field in database
      //save the field in database
      add_action(‘mvx_save_custom_store’, ‘save_field_delivery_express’, 10, 1);
      function save_field_delivery_express($user_id){
      $vendor_delivery_express = $_POST[‘_vendor_delivery_express’];
      update_user_meta($user_id, ‘_vendor_delivery_express’, $vendor_delivery_express);
      $express_delivery_hour_vendor = $_POST[‘global_ex_hour_vendor’];
      update_user_meta($user_id, ‘_express_delivery_hour_vendor’, $express_delivery_hour_vendor);
      }
      if you still face issue please let us know.

    • #190200
      l.gan
      Participant

      Hello
      please check your spam, i sent 2 messages but i can’t see them in the support forum.

    • #190133
      l.gan
      Participant
      This reply has been marked as private.
    • #190191
      l.gan
      Participant
      This reply has been marked as private.
    • #190262

      Our dev team will check and get back to you.
      Kindly provide them some time.

    • #190316
      promita
      Moderator

      Hi l.gan, add this code in functions.php of your current active theme:

      
      add_action( 'mvx_after_shop_front', 'extra_delivery_express' );
      /*form for vendor dashboard set field*/
      function extra_delivery_express() {
          $vendor_id = get_current_vendor_id();
          $vendor_delivery_express = '';
          $vendor_delivery_express = get_user_meta($vendor_id, '_vendor_delivery_express', true) ? get_user_meta($vendor_id, '_vendor_delivery_express', true) : $vendor_delivery_express;
          $express_delivery_hour_vendor = '';
          $express_delivery_hour_vendor = get_user_meta($vendor_id, '_express_delivery_hour_vendor', true );
      
          ?>
      
          <div class="panel panel-default pannel-outer-heading">
          <div class="panel-heading d-flex">
          <h3><?php _e('Express', 'multivendorx'); ?></h3>
          </div>
          <div class="panel-body panel-content-padding form-horizontal">
          <div class="mvx_media_block">
      
          <div class="form-group">
          <label class="control-label col-sm-3 col-md-3" for="_vendor_delivery_express"></label>
          <div class="col-md-6 col-sm-9">
          <input type="hidden" name="_vendor_delivery_express" value="no">
          <input type="checkbox" id="myCheck" onclick="myFunction()" name="_vendor_delivery_express" value="yes" <?php echo ($vendor_delivery_express=='yes' ? 'checked' : '');?>>
          </div>
          </div>
      
          <div class="form-group" id="text" style="" >
          <label class="control-label col-sm-3 col-md-3"></label>
          <div class="col-md-6 col-sm-9">
          <select name="global_ex_hour_vendor" class="form-control" value="">
              <option selected value=""> — — </option>
      
              <?php if($express_delivery_hour_vendor){?>
              <option selected value="<?php echo $express_delivery_hour_vendor; ?>"><?php echo $express_delivery_hour_vendor; ?></option>
              <?php }
              ?>
              <option value="1">1</option>
              <option value="2">2</option>
              <option value="3">3</option>
              <option value="4">4</option>
              <option value="6">6</option>
          </select>
          </div>
          </div>
      
          </div>
          </div>
          </div>
      
          <script>
          function myFunction() {
              var checkBox = document.getElementById("myCheck");
              var text = document.getElementById("text");
              if (checkBox.checked == true){
              text.style.display = "block";
              text2.style.display = "block";
              } else {
              text.style.display = "none";
              text2.style.display = "none";
              }
          }
          </script>
      
      <?php
      }
      
      //save the field in database
      add_action('mvx_save_custom_store', 'save_field_delivery_express', 10, 1);
      function save_field_delivery_express($user_id){
          $vendor_delivery_express = $_POST['_vendor_delivery_express'];
          update_user_meta($user_id, '_vendor_delivery_express', $vendor_delivery_express);
          $express_delivery_hour_vendor = $_POST['global_ex_hour_vendor'];
          update_user_meta($user_id, '_express_delivery_hour_vendor', $express_delivery_hour_vendor);
      }
      
      //display the field
      add_action('woocommerce_single_product_summary', 'display_field_delivery_express', 25);
      function display_field_delivery_express (){
          $vendor = get_userdata(get_the_author_meta('ID'));
          $vendor_delivery_express_display = get_user_meta($vendor->id, '_vendor_delivery_express', true );
          $express_delivery_hour_vendor = get_user_meta($vendor->id, '_express_delivery_hour_vendor', true );
          if ( $vendor_delivery_express_display ) {
              if ( $vendor_delivery_express_display && $express_delivery_hour_vendor ) {
                  echo '<div class="expressdelivery">express - ' . $express_delivery_hour_vendor .'</div>';
              } else {
                  echo '';
              }
              echo '';
          }
      }
      
      Copy
    • #190328
      l.gan
      Participant

      thanks a lot, everything works great!
      please mark the question as completed

    • #190373

      Thanks for the update . It would be really great if you can give us 5/5 review here: https://wordpress.org/support/plugin/dc-woocommerce-multi-vendor/reviews/#new-post
      This would motivate the team further to do their job more efficiently.

Viewing 10 reply threads

The topic ‘how to show checkbox value from vendor dashboard’ is closed to new replies.