jQuery(function($){
  // console.debug('cart_ajax_myinfo iniciando...', cart_ajax_myinfo);
  var elKey = '.wpr-mini-cart-toggle-btn .wpr-mini-cart-icon-count span';
  $(elKey).parent().addClass('wpr-mini-cart-icon-count-hidden');
  
  $.ajax({
    type: 'POST',
    url: cart_ajax_myinfo.url,
    data: {
      action: 'cart_ajax_myinfo',
      hello: 'my',
    },
    success: function(response) {
      try {
        var resp = JSON.parse(response.replace(/0$/g,''));
        // console.debug('cart_ajax_myinfo success:', resp);
        var totalQtd = 0;
        for(var key in resp.cart_qtd) {
          totalQtd += resp.cart_qtd[key];
        }

        var elQtd = $(elKey);
        elQtd.text( totalQtd );
        if( totalQtd > 0 ) elQtd.parent().removeClass('wpr-mini-cart-icon-count-hidden');
        else elQtd.parent().addClass('wpr-mini-cart-icon-count-hidden');
      } catch(ex) {
        console.error('Erro ao buscar dados do carrinho:', ex);
      }
    }
  });
});