Şu anda bir web mağazası yapmakta olan WooCommerce ve bu sepete sizin istediğiniz zaman herhangi bir sayfada erişebilmeniz için yapılabilen bir ürünün sepeti ürün sepeti içindeki miktarını değiştirebilirsiniz. Sorun her ne zaman olursa olsun, bazı şeyler berbat olur. Örneğin, WC()->cart->total
'u almayı denediğimde 0WooCommerce ajax güncellemesi bozuluyor
Ancak, ödeme sayfasına gittiğimde tüm doğru kart verilerini gösterir, bu yüzden bana bir şey ayarladıktan sonra çalıştırmam gerektiğini düşündüğümü düşünürüm action
arabada. set_quantity()
işlevlerini inceledim ve otomatik olarak toplamı $this->calculate_totals();
(elle de denedim) ile yeniliyor.
Ajax fonksiyonu:
public function set_quantity($direction = false, $product_id) {
$response = array();
$justOne = false;
if($_GET['data']['direction'] && $_GET['data']['product_id']) {
$direction = $_GET['data']['direction'];
$product_id = $_GET['data']['product_id'];
$justOne = true;
}
foreach (WC()->cart->get_cart() as $cart_item_key => $values) {
$_product = $values['data'];
if ($product_id == $_product->id) {
if($justOne && $direction == 'minus') {
WC()->cart->set_quantity($cart_item_key, $values['quantity'] - 1, true);
$response['success']['quantity'] = $values['quantity'] - 1;
} else if($justOne && $direction == 'plus') {
WC()->cart->set_quantity($cart_item_key, $values['quantity'] + 1, true);
$response['success']['quantity'] = $values['quantity'] + 1;
} else {
WC()->cart->set_quantity($cart_item_key, $values['quantity'] + $direction, true);
}
$response['success']['line_total'] = '€ '.number_format((float)$response['success']['quantity'] * $_product->price, 2, '.', '');
$response['success']['cart_count'] = WC()->cart->get_cart_contents_count();
$response['success']['total'] = number_format((float)WC()->cart->total, 2, '.', '');
die(json_encode($response));
}
}
return false;
}
Eğer bu prosedür $ denedin mi woocommerce-> sepeti-> get_total(); WC() -> cart-> get_total(); ? – Gopalakrishnan
sağladığınız bu işlevi ne zaman ve nasıl çağırıyorsunuz? – Reigel
@Gopalakrishnan Sanırım bunu hatırlayamadım, zamanım olduğunda test edeceğim, cevabınız için teşekkürler – LVDM