Better callback

This commit is contained in:
Mike Jolley 2018-04-19 18:37:07 +01:00
parent cd20ba0666
commit 8aa214bab5
3 changed files with 26 additions and 13 deletions

View File

@ -144,23 +144,14 @@ function wc_print_notices( $return = false ) {
wc_clear_notices();
$notices = ob_get_clean();
$notices = wp_kses_post( ob_get_clean() );
if ( $return ) {
return '<div class="woocommerce-notices-wrapper">' . $notices . '</div>';
} else {
echo '<div class="woocommerce-notices-wrapper">';
echo wp_kses_post( $notices );
echo '</div>';
return $notices;
}
echo $notices; // WPCS: XSS ok.
}
add_action( 'woocommerce_cart_is_empty', 'wc_print_notices', 10, 0 );
add_action( 'woocommerce_shortcode_before_product_cat_loop', 'wc_print_notices', 10, 0 );
add_action( 'woocommerce_before_shop_loop', 'wc_print_notices', 10, 0 );
add_action( 'woocommerce_before_single_product', 'wc_print_notices', 10, 0 );
add_action( 'woocommerce_before_cart', 'wc_print_notices', 10, 0 );
add_action( 'woocommerce_before_checkout_form', 'wc_print_notices', 10, 0 );
add_action( 'woocommerce_account_content', 'wc_print_notices', 10, 0 );
/**
* Print a single notice immediately.

View File

@ -3328,6 +3328,17 @@ function wc_get_cart_undo_url( $cart_item_key ) {
return apply_filters( 'woocommerce_get_undo_url', $cart_page_url ? wp_nonce_url( add_query_arg( $query_args, $cart_page_url ), 'woocommerce-cart' ) : '', $cart_item_key );
}
/**
* Outputs all queued notices on WC pages.
*
* @since 3.5.0
*/
function woocommerce_output_all_notices() {
echo '<div class="woocommerce-notices-wrapper">';
wc_print_notices();
echo '</div>';
}
/**
* Products RSS Feed.
*

View File

@ -288,3 +288,14 @@ add_action( 'woocommerce_account_payment-methods_endpoint', 'woocommerce_account
add_action( 'woocommerce_account_add-payment-method_endpoint', 'woocommerce_account_add_payment_method' );
add_action( 'woocommerce_account_edit-account_endpoint', 'woocommerce_account_edit_account' );
add_action( 'woocommerce_register_form', 'wc_privacy_policy_text', 20 );
/**
* Notices.
*/
add_action( 'woocommerce_cart_is_empty', 'woocommerce_output_all_notices', 10 );
add_action( 'woocommerce_shortcode_before_product_cat_loop', 'woocommerce_output_all_notices', 10 );
add_action( 'woocommerce_before_shop_loop', 'woocommerce_output_all_notices', 10 );
add_action( 'woocommerce_before_single_product', 'woocommerce_output_all_notices', 10 );
add_action( 'woocommerce_before_cart', 'woocommerce_output_all_notices', 10 );
add_action( 'woocommerce_before_checkout_form', 'woocommerce_output_all_notices', 10 );
add_action( 'woocommerce_account_content', 'woocommerce_output_all_notices', 10 );