【发布时间】:2022-10-01 20:09:54
【问题描述】:
我有一个问题,是否有人可以帮助我了解添加到购物车中的产品数量 - 例如,当我在数量 2 中添加产品 x 时,当我想添加任意数量的其他产品时,例如y,然后它在购物车中显示购物车中的 2 件商品。产品 x 的数量不会重置,好像只有当它“重置”自己时,我才能添加不同数量的不同产品。这就像我是一个客户,他标记了 2 件产品 x,但没有添加到购物篮就退出了,并选择了 1 件产品 y,然后我阅读了 2 件产品 x。有谁知道如何解决它?请帮忙。网站 - https://www.fabrykaprzypraw.com.pl/blog22/
/**
* Add quantity field on the archive page.
*/
function custom_quantity_field_archive() {
$product = wc_get_product( get_the_ID() );
//if ( ! $product->is_sold_individually() && \'variable\' != $product->product_type && $product->is_purchasable() ) { //niki. ako ne go iskash za variable products. az go iskam
if ( ! $product->is_sold_individually() && $product->is_purchasable() ) {
woocommerce_quantity_input( array( \'min_value\' => 1, \'max_value\' => $product->backorders_allowed() ? \'\' : $product->get_stock_quantity() ) );
}
}
add_action( \'woocommerce_after_shop_loop_item\', \'custom_quantity_field_archive\', 15, 9 );
function custom_add_to_cart_quantity_handler() {
wc_enqueue_js( \'
jQuery( \"body\" ).on( \"click\", \".quantity input\", function() {
return false;
});
jQuery( \"body\" ).on( \"change input\", \".quantity .qty\", function() {
var add_to_cart_button = jQuery( this ).parents( \".product\" ).find( \".add_to_cart_button\" );
// For AJAX add-to-cart actions
add_to_cart_button.attr( \"data-quantity\", jQuery( this ).val() );
// For non-AJAX add-to-cart actions
add_to_cart_button.attr( \"href\", \"?add-to-cart=\" + add_to_cart_button.attr( \"data-product_id\" ) + \"&quantity=\" + jQuery( this ).val() );
});
\' );
}
add_action( \'init\', \'custom_add_to_cart_quantity_handler\' );
标签: php wordpress woocommerce