Hide states when no states are shown

If you are runnig Joomla 3.x and Virtuemart 3.x please post to this forum your questions or support tickets about One Page Checkout

Hide states when no states are shown

Postby admin » Mon May 07, 2018 1:11 pm

Dear friends, if you'd like to hide state field when they are not used you may want to adjust your OPC theme this way:

modify: /components/com_onepage/themes/YOUR OPC THEME AS SELECTED AT THE DISPLAY TAB/tabcontent.js

add new code to the very bottom:

Code: Select all

function hideStates(prefix) {
  if (!(prefix != null)) prefix = '';
   
  var d = jQuery('#'+prefix+'virtuemart_state_id'+'_div');
  if (d.length > 0) {
    d.hide();
  }
  var d = jQuery('#'+prefix+'virtuemart_state_id'+'_input');
  if (d.length > 0) {
    d.hide();
  }
}

function showStates(prefix) {
  if (!(prefix != null)) prefix = '';
 
  var d = jQuery('#'+prefix+'virtuemart_state_id'+'_div');
  if (d.length > 0) {
    d.show();
  }
  var d = jQuery('#'+prefix+'virtuemart_state_id'+'_input');
  if (d.length > 0) {
    d.show();
  }
}
//var callWhenHasStates = new Array();
//var callWhenNoStates = new Array();
if (typeof addOpcTriggerer != 'undefined') {
  addOpcTriggerer('callWhenHasStates', 'showStates(prefix)');
  addOpcTriggerer('callWhenNoStates', 'hideStates(prefix)');
}

jQuery(document).ready(function() {
  if (typeof OPCStates == 'undefined') return;
  var elopc = document.getElementById('virtuemart_country_id');
  var value = '';
  if (elopc != null) {
  if (elopc.options != null) {
  value = elopc.options[elopc.selectedIndex].value;
  }
  else
  if (elopc.value != null) {
  value = elopc.value;
}

  var statefor = eval('OPCStates.state_for_'+value);   
  if (typeof statefor == 'undefined') {
    hideStates('');
  }
  }
 
  var elopc = document.getElementById('shipto_virtuemart_country_id');
  var value = '';
  if (elopc != null) {
  if (elopc.options != null) {
  value = elopc.options[elopc.selectedIndex].value;
  }
  else
  if (elopc.value != null) {
  value = elopc.value;
}

  var statefor = eval('OPCStates.state_for_'+value);   
  if (typeof statefor == 'undefined') {
    hideStates('shipto_');
  }
  }
 
 
});



best regards, stan
admin
Site Admin
 
Posts: 2593
Joined: Wed Jan 06, 2010 11:43 pm

Return to One Page Checkout for Virtuemart 3 on Joomla 3.x

cron