Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix display of "empty cart" notices when using a shortcode cart and the checkout block #38738

Merged
merged 4 commits into from Jun 27, 2023
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
@@ -0,0 +1,4 @@
Significance: patch
Type: fix

Add wrapper to the content generated by wc_empty_cart_message
4 changes: 2 additions & 2 deletions plugins/woocommerce/client/legacy/js/frontend/cart.js
Expand Up @@ -110,7 +110,7 @@ jQuery( function( $ ) {
}

// No items to display now! Replace all cart content.
var $cart_html = $( '.cart-empty', $html ).closest( '.woocommerce' );
var $cart_html = $( '.wc-empty-cart-message', $html ).closest( '.woocommerce' );
$( '.woocommerce-cart-form__contents' ).closest( '.woocommerce' ).replaceWith( $cart_html );

// Display errors
Expand Down Expand Up @@ -157,7 +157,7 @@ jQuery( function( $ ) {
var show_notice = function( html_element, $target ) {
if ( ! $target ) {
$target = $( '.woocommerce-notices-wrapper:first' ) ||
$( '.cart-empty' ).closest( '.woocommerce' ) ||
$( '.wc-empty-cart-message' ).closest( '.woocommerce' ) ||
$( '.woocommerce-cart-form' );
}
$target.prepend( html_element );
Expand Down
24 changes: 21 additions & 3 deletions plugins/woocommerce/includes/wc-template-functions.php
Expand Up @@ -3696,10 +3696,28 @@ function wc_logout_url( $redirect = '' ) {
* @since 3.1.0
*/
function wc_empty_cart_message() {
$message = wp_kses_post( apply_filters( 'wc_empty_cart_message', __( 'Your cart is currently empty.', 'woocommerce' ) ) ); // phpcs:ignore WooCommerce.Commenting.CommentHooks.MissingHookComment
$notice = wc_print_notice( $message, 'notice', array(), true );
$notice = wc_print_notice(
wp_kses_post(
/**
* Filter empty cart message text.
*
* @since 3.1.0
* @param string $message Default empty cart message.
* @return string
*/
apply_filters( 'wc_empty_cart_message', __( 'Your cart is currently empty.', 'woocommerce' ) )
),
'notice',
array(),
true
);

// This adds the cart-empty classname to the notice to preserve backwards compatibility (for styling purposes etc).
$notice = str_replace( 'class="woocommerce-info"', 'class="cart-empty woocommerce-info"', $notice );
echo $notice; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped

// Return the notice within a consistent wrapper element. This is targetted by some scripts such as cart.js.
// phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
echo '<div class="wc-empty-cart-message">' . $notice . '</div>';
}

/**
Expand Down