将《清除购物车按钮》添加到购物车页面和迷你购物车

代码:

<?php

// adds the button to the cart page
add_action( 'woocommerce_cart_actions', 'woocommerce_empty_cart_button' );
function woocommerce_empty_cart_button() {
    echo '<a href="' . esc_url( add_query_arg( 'empty_cart', 'yes' ) ) . '" style="background-color: rgba(224, 32, 32,1);"; class="btn btn-scheme-light btn-scheme-hover-light btn-style-default btn-style-round btn-size-default" title="' . esc_attr( 'Svuota il carrello', 'woocommerce' ) . '">' . esc_html( 'Svuota il carrello', 'woocommerce' ) . '</a>';
}

// empty the cart and refresh the page (redirects to the cart page)
add_action( 'wp_loaded', 'woocommerce_empty_cart_action', 20 );
function woocommerce_empty_cart_action() {
    if ( isset( $_GET['empty_cart'] ) && 'yes' === esc_html( $_GET['empty_cart'] ) ) {
        WC()->cart->empty_cart();
    
        $referer = wc_get_cart_url();
        wp_safe_redirect( $referer );
    }
}


add_action( 'woocommerce_before_mini_cart', 'minicart_count_after_content' );
function minicart_count_after_content() {
	if ( WC()->cart->get_cart_contents_count() > 0 )
     echo '<a href="' . esc_url( add_query_arg( 'empty_cart', 'yes' ) ) . '" style="background-color: rgba(224, 32, 32,1);"; class="btn btn-scheme-light btn-scheme-hover-light btn-style-default btn-style-rectangle btn-size-default" title="' . esc_attr( 'Svuota il carrello', 'woocommerce' ) . '">' . esc_html( 'Svuota il carrello', 'woocommerce' ) . '</a>';
}
© 版权声明
THE END
喜欢就支持一下吧
点赞11 分享