• You MUST read the Babiato Rules before making your first post otherwise you may get permanent warning points or a permanent Ban.

    Our resources on Babiato Forum are CLEAN and SAFE. So you can use them for development and testing purposes. If your are on Windows and have an antivirus that alerts you about a possible infection: Know it's a false positive because all scripts are double checked by our experts. We advise you to add Babiato to trusted sites/sources or disable your antivirus momentarily while downloading a resource. "Enjoy your presence on Babiato"

Help with custom code woocommerce

& >> /dev/null

New member
Jul 31, 2018
26
12
3
sigma-spot.com
Hi fellas,

I am trying to create a custom check out dropdown fields on the Woocomerse checkout page. When the field is selected I want to show the HTML code to the user where they can fill out the details for invoce. I have the following coded added the function.php:

Code:
<?php

// add fields
add_action( 'woocommerce_after_checkout_billing_form', 'vasko_select_field' );

// save fields to order meta
add_action( 'woocommerce_checkout_update_order_meta', 'vasko_save_what_we_added' );
 

// select
function vasko_select_field( $checkout ){
 
    // you can also add some custom HTML here
 
    woocommerce_form_field( 'contactmethod', array(
        'type'          => 'checkbox', // text, textarea, select, radio, checkbox, password, about custom validation a little later
        'required'    => false, // actually this parameter just adds "*" to the field
        'class'         => array('vasko-field', 'form-row-wide'), // array only, read more about classes and styling in the previous step
        'label'         => 'Желая да ми бъде издадена фактура',
        'label_class'   => array('woocommerce-form__label woocommerce-form__label-for-checkbox checkbox') // sometimes you need to customize labels, both string and arrays are supported

        ), $checkout->get_value( 'contactmethod' ) );

 
    // you can also add some custom HTML here
    echo '<label>
    <span>* Фирма</span>
    <input id="company" type="text" name="client[company]" value="" placeholder="Фирма" class="required">
</label>
<label>
    <span>* ЕИК</span>
    <input id="tax_num" type="text" name="client[tax_num]" value="" placeholder="ЕИК" class="required">
</label>
<label>
    <span>ИН по ЗДДС</span>
    <input id="vat_num" class="" type="text" name="client[vat_num]" value="" placeholder="ИН по ЗДДС">
</label>
<label class="">
    <span>* Град</span>
    <input id="city_company" type="text" name="client[company_cityName]" value="" placeholder="Град" class="ui-autocomplete-input required" autocomplete="off">
    <input id="city_companyId" type="hidden" name="client[company_cityId]" value="" class="">
</label>
<label>
    <span>* Адрес</span>
    <input id="company_address" type="text" name="client[company_address]" value="" placeholder="Адрес" class="required">
</label>';
 
function bbloomer_conditionally_hide_show_new_field() {
    
  wp_enqueue_script( "
      jQuery('input#contactmethod').change(function(){
          
         if (this.checked) {
            jQuery('#contactmethod').slideDown);
            jQuery('#contactmethod input').val('');         
         } else {
            jQuery('#contactmethod').slideUp
         }
          
      });
  ");
      
    }

}

however, the jQuery function is no working and when the checkbox is clicked it does not slide the HTML code up or down. I am trying to integrate for two days but no aval. Any help is much appreciated!
 
AdBlock Detected

We get it, advertisements are annoying!

However in order to keep our huge array of resources free of charge we need to generate income from ads so to use the site you will need to turn off your adblocker.

If you'd like to have an ad free experience you can become a Babiato Lover by donating as little as $5 per month. Click on the Donate menu tab for more info.

I've Disabled AdBlock