У меня есть это действие в моих функциях. php:
add_action( 'woocommerce_before_calculate_totals', 'adding_custom_price', 10, 1);
function adding_custom_price( $cart ) {
global $current_user, $woocommerce, $wpdb;
// This is necessary for WC 3.0+
if ( is_admin() && ! defined( 'DOING_AJAX' ) )
return;
// Avoiding hook repetition (when using price calculations for example)
if ( did_action( 'woocommerce_before_calculate_totals' ) >= 2 )
return;
$quantity = 0;
foreach ( $cart->get_cart() as $cart_item ) {
$quantity += $cart_item['quantity'];
$product_id = $cart_item['data']->get_id();
$product_price = $cart_item['data']->get_price();
$categorie_id = $cart_item['data']->get_category_ids();
$korting_product = get_field( 'discount_points', $product_id );
//Zet prijs min benegas korting
$cart_item['data']->set_price($product_price - $korting_product);
}
echo "<script type='text/javascript'>alert('$quantity');</script>";
}
Но с этой строкой:
echo "<script type='text/javascript'>alert('$quantity');</script>";
Корзина продолжает загружаться после меняя количество так что я делаю не так. Я не получаю оповещение.