[fix] Handle notices without outputting outside of template files
Fixes #11112
This commit is contained in:
parent
815e9774a3
commit
a0d14d0baf
|
@ -47,9 +47,14 @@ class WC_Shortcode_My_Account {
|
|||
wc_get_template( 'myaccount/form-login.php' );
|
||||
}
|
||||
} else {
|
||||
wc_print_notices();
|
||||
ob_start();
|
||||
self::my_account( $atts );
|
||||
// Start output buffer since the html may need discarding for BW compatibility
|
||||
ob_start();
|
||||
|
||||
// Collect notices before output
|
||||
$notices = wc_get_notices();
|
||||
|
||||
// Output the new account page
|
||||
self::my_account( $atts );
|
||||
|
||||
/**
|
||||
* Deprecated my-account.php template handling. This code should be
|
||||
|
@ -64,7 +69,9 @@ class WC_Shortcode_My_Account {
|
|||
continue;
|
||||
}
|
||||
if ( has_action( 'woocommerce_account_' . $key . '_endpoint' ) ) {
|
||||
ob_clean();
|
||||
ob_clean(); // Clear previous buffer
|
||||
wc_set_notices( $notices );
|
||||
wc_print_notices();
|
||||
do_action( 'woocommerce_account_' . $key . '_endpoint', $value );
|
||||
break;
|
||||
}
|
||||
|
@ -73,6 +80,7 @@ class WC_Shortcode_My_Account {
|
|||
_deprecated_function( 'Your theme version of my-account.php template', '2.6', 'the latest version, which supports multiple account pages and navigation, from WC 2.6.0' );
|
||||
}
|
||||
|
||||
// Send output buffer
|
||||
ob_end_flush();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -90,6 +90,19 @@ function wc_add_notice( $message, $notice_type = 'success' ) {
|
|||
WC()->session->set( 'wc_notices', $notices );
|
||||
}
|
||||
|
||||
/**
|
||||
* Set all notices at once.
|
||||
* @since 2.6.0
|
||||
*/
|
||||
function wc_set_notices( $notices ) {
|
||||
if ( ! did_action( 'woocommerce_init' ) ) {
|
||||
_doing_it_wrong( __FUNCTION__, __( 'This function should not be called before woocommerce_init.', 'woocommerce' ), '2.6' );
|
||||
return;
|
||||
}
|
||||
WC()->session->set( 'wc_notices', $notices );
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Unset all notices.
|
||||
*
|
||||
|
@ -163,10 +176,10 @@ function wc_get_notices( $notice_type = '' ) {
|
|||
|
||||
$all_notices = WC()->session->get( 'wc_notices', array() );
|
||||
|
||||
if ( empty ( $notice_type ) ) {
|
||||
if ( empty( $notice_type ) ) {
|
||||
$notices = $all_notices;
|
||||
} elseif ( isset( $all_notices[$notice_type] ) ) {
|
||||
$notices = $all_notices[$notice_type];
|
||||
} elseif ( isset( $all_notices[ $notice_type ] ) ) {
|
||||
$notices = $all_notices[ $notice_type ];
|
||||
} else {
|
||||
$notices = array();
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue