Вот часть кода плагина, который я нашел, думаю, он отражает функциональность плагина.
// Only if WooCommerce is active (doesn't work for Github installations which have version number in folder name).
if ( in_array( 'woocommerce/woocommerce.php', apply_filters( 'active_plugins', get_option( 'active_plugins' ) ) ) || ( get_site_option('active_sitewide_plugins') && array_key_exists( 'woocommerce/woocommerce.php', get_site_option('active_sitewide_plugins') ) ) ) {
// Remove plugin prefix and dash "_" from argument keys.
function acau_replaceArrayKeys( $array ) {
$replacedKeys = str_replace('acau_', null, array_keys( $array ));
return array_combine( $replacedKeys, $array );
}
$args = acau_replaceArrayKeys ( $acau_settings_page->acau_get_settings() );
// Run plugin.
add_action( 'template_redirect', function() use ( $args ) { ajax_cart_autoupdate( $args ); });
function ajax_cart_autoupdate( $args ) {
if (! is_cart() ) return; // Only if it's a cart page.
// Enqueue js script inline using wc_enqueue_js.
add_action( 'template_redirect', function() use ( $args ) { acau_enqueue_script ( $args ); }, 20);
/*don't display default "Update cart" button, its behavior can still be triggered automatically,
in WooCommerce 3.4.0 input element type was changed to button,
class .button is present in all versions (at least from 2.6 when AJAX cart appeared in WooCommerce core)
change spinning wheel color*/
add_action( 'wp_head', function() use ( $args ) { acau_apply_styles ( $args ); }, 20);
// Cart page minimum qty = 1 instead of 0.
if (1 == $args['positive_qty'] ) {
add_filter( 'woocommerce_quantity_input_args', 'acau_cart_min_qty', 10, 2 );
}
/* Don't display any notices, it includes:
- "Cart updated."
- removed cart item notice
- the one when checkout session expires and cart items disappear (it duplicates no items in cart standard message).
*/
if (1 == $args['cart_notices_off'] ) {
WC()->session->set( 'wc_notices', null );
}
}
function acau_apply_styles( $args ) {
$my_style = "
[name='update_cart'] {
display: none!important;
}" .
(( 1 == $args['custom_spinning_wheel'] ) ?
".woocommerce .blockUI.blockOverlay:before,.woocommerce .loader:before {
color: " . $args['spinning_wheel_color'] . ";
}" : "");
echo '' . acau_minify($my_style) . '';
}
function acau_enqueue_script( $args ) {
wc_enqueue_js( '
var timeout;
jQuery("div.woocommerce").on("change keyup mouseup", "input.qty, select.qty", function(){ // keyup and mouseup for Firefox support
if (timeout != undefined) clearTimeout(timeout); //cancel previously scheduled event
if (jQuery(this).val() == "") return; //qty empty, instead of removing item from cart, do nothing
timeout = setTimeout(function() {
jQuery("[name=\"update_cart\"]").trigger("click");
}, ' . $args["update_delay"] . ' ); // schedule update cart event with delay in miliseconds specified in plugin settings
});
' );
}
function acau_cart_min_qty( $args, $product ) {
$args['min_value'] = 1;
return $args;
}
}
function acau_minify( $input ) {
$output = $input;
// Remove whitespace
$output = preg_replace('/\s*([{}|:;,])\s+/', '$1', $output);
// Remove trailing whitespace at the start
$output = preg_replace('/\s\s+(.*)/', '$1', $output);
// Remove comments
// $output = preg_replace('#/\*.*?\*/#s', '', $output);
$output = preg_replace('/(?:(?:\/\*(?:[^*]|(?:\*+[^*\/]))*\*+\/)|(?:(?
Вот код JQuery, который я добавил в блок кода Oxygen.
var timeout;
jQuery("div.woocommerce").on("change keyup mouseup", "input.qty, select.qty", function(){ // keyup and mouseup for Firefox support
if (timeout != undefined) clearTimeout(timeout); //cancel previously scheduled event
if (jQuery(this).val() == "") return; //qty empty, instead of removing item from cart, do nothing
timeout = setTimeout(function() {
jQuery("[name=\"update_cart\"]").trigger("click");
},1000 ); // schedule update cart event with delay in miliseconds specified in plugin settings
});
Подробнее здесь: https://stackoverflow.com/questions/666 ... rom-0-to-1
Обновление корзины Woocommerce Ajax: изменение минимального количества с 0 на 1 ⇐ Jquery
Программирование на jquery
1729222140
Anonymous
Вот часть кода плагина, который я нашел, думаю, он отражает функциональность плагина.
// Only if WooCommerce is active (doesn't work for Github installations which have version number in folder name).
if ( in_array( 'woocommerce/woocommerce.php', apply_filters( 'active_plugins', get_option( 'active_plugins' ) ) ) || ( get_site_option('active_sitewide_plugins') && array_key_exists( 'woocommerce/woocommerce.php', get_site_option('active_sitewide_plugins') ) ) ) {
// Remove plugin prefix and dash "_" from argument keys.
function acau_replaceArrayKeys( $array ) {
$replacedKeys = str_replace('acau_', null, array_keys( $array ));
return array_combine( $replacedKeys, $array );
}
$args = acau_replaceArrayKeys ( $acau_settings_page->acau_get_settings() );
// Run plugin.
add_action( 'template_redirect', function() use ( $args ) { ajax_cart_autoupdate( $args ); });
function ajax_cart_autoupdate( $args ) {
if (! is_cart() ) return; // Only if it's a cart page.
// Enqueue js script inline using wc_enqueue_js.
add_action( 'template_redirect', function() use ( $args ) { acau_enqueue_script ( $args ); }, 20);
/*don't display default "Update cart" button, its behavior can still be triggered automatically,
in WooCommerce 3.4.0 input element type was changed to button,
class .button is present in all versions (at least from 2.6 when AJAX cart appeared in WooCommerce core)
change spinning wheel color*/
add_action( 'wp_head', function() use ( $args ) { acau_apply_styles ( $args ); }, 20);
// Cart page minimum qty = 1 instead of 0.
if (1 == $args['positive_qty'] ) {
add_filter( 'woocommerce_quantity_input_args', 'acau_cart_min_qty', 10, 2 );
}
/* Don't display any notices, it includes:
- "Cart updated."
- removed cart item notice
- the one when checkout session expires and cart items disappear (it duplicates no items in cart standard message).
*/
if (1 == $args['cart_notices_off'] ) {
WC()->session->set( 'wc_notices', null );
}
}
function acau_apply_styles( $args ) {
$my_style = "
[name='update_cart'] {
display: none!important;
}" .
(( 1 == $args['custom_spinning_wheel'] ) ?
".woocommerce .blockUI.blockOverlay:before,.woocommerce .loader:before {
color: " . $args['spinning_wheel_color'] . ";
}" : "");
echo '' . acau_minify($my_style) . '';
}
function acau_enqueue_script( $args ) {
wc_enqueue_js( '
var timeout;
jQuery("div.woocommerce").on("change keyup mouseup", "input.qty, select.qty", function(){ // keyup and mouseup for Firefox support
if (timeout != undefined) clearTimeout(timeout); //cancel previously scheduled event
if (jQuery(this).val() == "") return; //qty empty, instead of removing item from cart, do nothing
timeout = setTimeout(function() {
jQuery("[name=\"update_cart\"]").trigger("click");
}, ' . $args["update_delay"] . ' ); // schedule update cart event with delay in miliseconds specified in plugin settings
});
' );
}
function acau_cart_min_qty( $args, $product ) {
$args['min_value'] = 1;
return $args;
}
}
function acau_minify( $input ) {
$output = $input;
// Remove whitespace
$output = preg_replace('/\s*([{}|:;,])\s+/', '$1', $output);
// Remove trailing whitespace at the start
$output = preg_replace('/\s\s+(.*)/', '$1', $output);
// Remove comments
// $output = preg_replace('#/\*.*?\*/#s', '', $output);
$output = preg_replace('/(?:(?:\/\*(?:[^*]|(?:\*+[^*\/]))*\*+\/)|(?:(?
Вот код JQuery, который я добавил в блок кода Oxygen.
var timeout;
jQuery("div.woocommerce").on("change keyup mouseup", "input.qty, select.qty", function(){ // keyup and mouseup for Firefox support
if (timeout != undefined) clearTimeout(timeout); //cancel previously scheduled event
if (jQuery(this).val() == "") return; //qty empty, instead of removing item from cart, do nothing
timeout = setTimeout(function() {
jQuery("[name=\"update_cart\"]").trigger("click");
},1000 ); // schedule update cart event with delay in miliseconds specified in plugin settings
});
Подробнее здесь: [url]https://stackoverflow.com/questions/66619768/woocommerce-ajax-cart-update-change-min-qty-from-0-to-1[/url]
Ответить
1 сообщение
• Страница 1 из 1
Перейти
- Кемерово-IT
- ↳ Javascript
- ↳ C#
- ↳ JAVA
- ↳ Elasticsearch aggregation
- ↳ Python
- ↳ Php
- ↳ Android
- ↳ Html
- ↳ Jquery
- ↳ C++
- ↳ IOS
- ↳ CSS
- ↳ Excel
- ↳ Linux
- ↳ Apache
- ↳ MySql
- Детский мир
- Для души
- ↳ Музыкальные инструменты даром
- ↳ Печатная продукция даром
- Внешняя красота и здоровье
- ↳ Одежда и обувь для взрослых даром
- ↳ Товары для здоровья
- ↳ Физкультура и спорт
- Техника - даром!
- ↳ Автомобилистам
- ↳ Компьютерная техника
- ↳ Плиты: газовые и электрические
- ↳ Холодильники
- ↳ Стиральные машины
- ↳ Телевизоры
- ↳ Телефоны, смартфоны, плашеты
- ↳ Швейные машинки
- ↳ Прочая электроника и техника
- ↳ Фототехника
- Ремонт и интерьер
- ↳ Стройматериалы, инструмент
- ↳ Мебель и предметы интерьера даром
- ↳ Cантехника
- Другие темы
- ↳ Разное даром
- ↳ Давай меняться!
- ↳ Отдам\возьму за копеечку
- ↳ Работа и подработка в Кемерове
- ↳ Давай с тобой поговорим...
Мобильная версия