Have “Virtual” and “Downloadable” options required and checked by default

WCMp Core

Resolved
Viewing 5 reply threads
  • Author
    Posts
    • #214143
      embpri
      Participant

      Hi,

      All products on my marketplace are virtual and downloadable, but when Vendors upload their products they sometimes get confused because they first need to check those boxes (see attached) before they can upload a file.

      Could you please tell me a way I can have those boxes be checked by default? If there is a way to have them be checked by default, I will even use CSS to hide them so that Vendors are not confused.

      Please take a look at the attached screenshot and tell me how I can make these two checkboxes be checked by default, and the “Downloadable files” section always visible.

      Thank you. 🙂

    • #214155

      Hello @embpri, You can add the below code in the functions.php file of your current active theme to have the virtual and downloadable box be checked by default.

      
      add_filter( 'mvx_product_type_options', 'autocheck');
      function autocheck( $options ){
          $options ['virtual']['default'] = "yes";
          $options ['downloadable']['default'] = "yes";
          return $options;
      }
      
      Copy
    • #214171
      embpri
      Participant

      Thank you very much, this works perfectly!

      I just had one last question: is there a way for me to make adding at least one download to the product compulsory? I don’t want vendors to be able to save/publish their products without adding at least one download to it.

      Thanks. 🙂

    • #214228

      Greetings @embpri!
      The modification you are looking for is not supported by our default flow. You will have to implement your desired flow on your end by adding custom code.
      If you need help with reference hooks/filters please let us know.

    • #214591
      embpri
      Participant

      Hi,

      The filter that you provided was perfect, with some additional JS I was able to solve the issue, so please mark this ticket as closed.

      For anyone that has the same or a similar requirement, here’s how I solved it on my site.

      
      jQuery(document).ready(function() {
        jQuery.when(jQuery('a.btn:nth-child(1)').trigger('click')).done(() => {
          document.querySelector('.file_name > input:nth-child(1)').required = true;
          document.querySelector('tbody.ui-sortable > tr:nth-child(1) > td:nth-child(3) > input:nth-child(1)').required = true;
        });
      });
      
      Copy

      I used jQuery to automatically click the “Add File” button in the download section and make the resulting “File Name” and “File Link” fields required by the browser.

    • #214620

      Thanks @embpri, for helping out the community.

Viewing 5 reply threads

The topic ‘Have “Virtual” and “Downloadable” options required and checked by default’ is closed to new replies.