
Добрый день! Меняю стоимость товара с помощью кода, но все равно не выдает правильную цену, не могу понять где ошибка.
<input type='hidden' name='price' class="price" id='price'>
<!-- Выбор только одного-->
<script>
ff=function(t){
price.value = t.parentElement.parentElement.parentElement.parentElement.lastElementChild.innerText;
}
</script>
<?php
global $woocommerce;
$woocommerce->cart->empty_cart(); //чистим
$custom_price = $price; //$price - переменная с ценой
$product_id = 623; //id любого товара
$quantity = 1; //кол-во
$cart_item_data = array('custom_price' => $custom_price);
$woocommerce->cart->add_to_cart( $product_id, $quantity, $variation_id, $variation, $cart_item_data );
$woocommerce->cart->calculate_totals();
$woocommerce->cart->set_session();
$woocommerce->cart->maybe_set_cart_cookies();
?>
<input type='hidden' name='price' class="price" id='price'>
<!-- Выбор только одного-->
<script>
ff=function(t){
price.value = t.parentElement.parentElement.parentElement.parentElement.lastElementChild.innerText;
}
</script>
<?php
global $woocommerce;
$woocommerce->cart->empty_cart(); //чистим
$custom_price = $price; //$price - переменная с ценой
$product_id = 623; //id любого товара
$quantity = 1; //кол-во
$cart_item_data = array('custom_price' => $custom_price);
$woocommerce->cart->add_to_cart( $product_id, $quantity, $variation_id, $variation, $cart_item_data );
$woocommerce->cart->calculate_totals();
$woocommerce->cart->set_session();
$woocommerce->cart->maybe_set_cart_cookies();
?>