Well, I'm adding a new feed to the checkout in woocommerce, now it adds it when I put the value manually but when I add the real value it puts it in zero, part of the code:
function llamar($total_pagar,$acum_empas)
$v["precio_total"]=$total_pagar;
$v["acumulador_empasta"]=$acum_empas;
do_action( 'woocommerce_cart_calculate_fees', $v );
}
add_action( 'woocommerce_cart_calculate_fees','endo_handling_fee', 10, 1);
function endo_handling_fee($valores) {
$precio_total=0;
$precio_empas=0;
static $cont = 0;
static $ent=0;
foreach ($valores as $key => $value)
{
if (strcmp($key, "precio_total")==0)
{
$precio_total=$value;
$ent++;
}
if (strcmp($key, "acumulador_empasta")==0)
{
$precio_empas=$value;
$ent++;
}
}
//echo $cont."-_-".$precio_empas;
$cont++;
{
$fee = floatval($precio_empas);
$fee = 5.0;
global $woocommerce;
if ( is_admin() && ! defined( 'DOING_AJAX' ) )
return;
$woocommerce->cart->add_fee( 'Empastado: ', $cont, true, 'standard' );
echo $cont."-_-_".$precio_empas;
}
}
the code like this one is saved 5 without any problem, but when I save $eprecio_empas it saves the value of 0, $precio_empas has a value because I can visualize it in: echo $cont."--".$precio_empas ;
that counter I put it to know if I was not overwriting, calling again to the action but I detected that it enters twice, once from the call when loading the page and another with the do_action( 'woocommerce_cart_calculate_fees', $v ); but although the second time it enters it does not write the value. what I did was to create a function that loads woocommerce_cart_calculate_fees once.
function llamar($total_pagar,$acum_empas)
{
$v["precio_total"]=$total_pagar;
$v["acumulador_empasta"]=$acum_empas;
llamado($v);
}
function llamado($v)
{
add_action( 'woocommerce_cart_calculate_fees','endo_handling_fee', 10, 1);
do_action( 'woocommerce_cart_calculate_fees', $v );
}
function endo_handling_fee($valores) {
$precio_total=0;
$precio_empas=0;
static $cont = 0;
static $ent=0;
foreach ($valores as $key => $value)
{
if (strcmp($key, "precio_total")==0)
{
$precio_total=$value;
$ent++;
}
if (strcmp($key, "acumulador_empasta")==0)
{
$precio_empas=$value;
$ent++;
}
}
//echo $cont."-_-".$precio_empas;
$cont++;
{
$fee = floatval($precio_empas);
$fee = 5.0;
global $woocommerce;
//if ( is_admin() && ! defined( 'DOING_AJAX' ) )
// return;
$woocommerce->cart->add_fee( 'Empastado: ', $cont, true, 'standard' );
echo $cont."-_-_".$precio_empas;
}
}
I know that the function enters endo_handling_fee with the do_action but I don't know why it doesn't store the value with $woocommerce->cart->add_fee( 'Filling: ', $cont, true, 'standard' );
Thank you
Aucun commentaire:
Enregistrer un commentaire