Created
February 10, 2023 18:03
-
-
Save clifgriffin/76c05fd8946bf2fa7864867e8d265197 to your computer and use it in GitHub Desktop.
CheckoutWC Side Cart & Order Minimum/Maximum Amount for WooCommerce
This file contains 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 | |
add_action( | |
'cfw_side_cart_notices', | |
function() { | |
// Catch any messages the hook creates | |
add_filter( 'woocommerce_add_error', 'catch_errors_and_queue_for_cfw' ); | |
add_filter( 'woocommerce_add_success', 'catch_success_and_queue_for_cfw' ); | |
add_filter( 'woocommerce_add_notice', 'catch_notices_and_queue_for_cfw' ); | |
// Prevent notices from being output/cleared on woocommerce_before_cart | |
remove_action( 'woocommerce_before_cart', 'woocommerce_output_all_notices', 10 ); | |
// Run hook for 'Before cart' action | |
// In Order Minimum/Maximum Amount for WooCommerce - WP Factory | |
// Discard output | |
ob_start(); | |
do_action( 'woocommerce_before_cart' ); | |
ob_end_clean(); | |
// Add back notice handling on woocommerce_before_cart | |
add_action( 'woocommerce_before_cart', 'woocommerce_output_all_notices', 10 ); | |
// Clean up the message catchers | |
remove_filter( 'woocommerce_add_error', 'catch_errors_and_queue_for_cfw' ); | |
remove_filter( 'woocommerce_add_success', 'catch_success_and_queue_for_cfw' ); | |
remove_filter( 'woocommerce_add_notice', 'catch_notices_and_queue_for_cfw' ); | |
} | |
); | |
function catch_errors_and_queue_for_cfw( $message ) { | |
remove_filter( 'woocommerce_add_error', 'catch_errors_and_queue_for_cfw' ); | |
wc_add_notice( $message, 'error' ); | |
add_filter( 'woocommerce_add_error', 'catch_errors_and_queue_for_cfw' ); | |
return $message; | |
} | |
function catch_success_and_queue_for_cfw( $message ) { | |
remove_filter( 'woocommerce_add_success', 'catch_success_and_queue_for_cfw' ); | |
wc_add_notice( $message, 'success' ); | |
add_filter( 'woocommerce_add_success', 'catch_success_and_queue_for_cfw' ); | |
return $message; | |
} | |
function catch_notices_and_queue_for_cfw( $message ) { | |
remove_filter( 'woocommerce_add_notice', 'catch_notices_and_queue_for_cfw' ); | |
wc_add_notice( $message, 'notice' ); | |
add_filter( 'woocommerce_add_notice', 'catch_notices_and_queue_for_cfw' ); | |
return $message; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment