Hide shopper field per country change

Please post your issues and questions about One Page Checkout for Virtuemart 2 to this forum.

Hide shopper field per country change

Postby admin » Wed Oct 29, 2014 1:26 pm

Hello friends, this short code here will enable you to change the visibility of any of your shopper fields per change of the ajaxified fields (country, zip, state, email, etc..)

This code hides OPC VAT field for Belgium customers and display it for everybody else. You can add this code you your tabcontent.js of your theme, or at the bottom of your onepage.unlogged.tpl.php file. This code works only for anonymous users and explains how to use OPC triggerrs:

Code: Select all

function alterShopperFields()
{
     // requires jquery
    if (typeof jQuery === 'undefined') return;
    var country = Onepage.op_getSelectedCountry();
    //belgium has id 21, netherlands have id 150
    // name of your field per VM config opc_vat
   var d = jQuery('#opc_vat_div');
  if (d != null)
  if (typeof d.parent != 'undefined')
  {
  var parent = d.parent();
  {
  // country 21 is belgium
   if (country == 21)
      {
        //hide opc vat field
       // will hide the element
       if (typeof parent.fadeOut != 'undefined')
        parent.fadeOut();
      else
      parent.css('display', 'none');
      }
     else
     {
       if (typeof parent.fadeIn != 'undefined')
       parent.fadeIn();
      else
      parent.css('display', 'block');
     }
  }
  }
}

if (typeof addOpcTriggerer != 'undefined')
addOpcTriggerer("callBeforeAjax",  "alterShopperFields()");



This is just an example of an easy modification of the logic of your checkout.

Best Regards, Stan
admin
Site Admin
 
Posts: 2708
Joined: Wed Jan 06, 2010 11:43 pm

Return to One Page Checkout for Virtuemart 2