Last active
January 12, 2022 12:06
-
-
Save artikus11/8395c2d0bccd4c05925b4c9419f3894f to your computer and use it in GitHub Desktop.
Кнопка Очистить корзину
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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 ну если сильно надо - добавлю, хотя многие копипастить не умеют, будут на ошибки жаловаться
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
<?php бы добавлять в начало файла для раскраски синтаксиса)