Skip to content

Instantly share code, notes, and snippets.

@artikus11
Last active January 12, 2022 12:06
Show Gist options
  • Save artikus11/8395c2d0bccd4c05925b4c9419f3894f to your computer and use it in GitHub Desktop.
Save artikus11/8395c2d0bccd4c05925b4c9419f3894f to your computer and use it in GitHub Desktop.
Кнопка Очистить корзину
<?php
/**
* Добавление кнопки Очистить корзину зарзу после кнопки Добавить купон
*/
function art_add_empty_cart_button() {
printf(
'<a href="%s" class="button" title="Очистить корзину">Очистить корзину</a>',
esc_url( add_query_arg( 'empty_cart', 'yes' ) )
);
}
add_action( 'woocommerce_cart_coupon', 'art_add_empty_cart_button' );
/**
* Очистка коризны
*/
function art_empty_cart_action() {
if ( isset( $_GET['empty_cart'] ) && 'yes' === esc_html( $_GET['empty_cart'] ) ) {
WC()->cart->empty_cart();
$referer = wp_get_referer() ? esc_url( remove_query_arg( 'empty_cart' ) ) : wc_get_cart_url();
wp_safe_redirect( $referer );
}
}
add_action( 'init', 'art_empty_cart_action', 20 );
@ildarkhasanshin
Copy link

ildarkhasanshin commented Dec 24, 2021

<?php бы добавлять в начало файла для раскраски синтаксиса)

@artikus11
Copy link
Author

@ildarkhasanshin ну если сильно надо - добавлю, хотя многие копипастить не умеют, будут на ошибки жаловаться

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment