Last active
January 30, 2026 05:55
-
-
Save wplit/4a6bec1e8843c0ae506f648ac171489b to your computer and use it in GitHub Desktop.
example code, queuing a toast on WooCommerce' redirect hook
This file contains hidden or 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_filter( 'woocommerce_add_to_cart_redirect', 'show_add_to_cart_toast', 10, 1 ); | |
| function show_add_to_cart_toast( $url ) { | |
| $product_id = absint( $_REQUEST['add-to-cart'] ?? 0 ); | |
| if ( $product_id ) { | |
| $product = wc_get_product( $product_id ); | |
| if ( $product ) { | |
| /* using BricksExtras helper function to show toast with id mfhden, swapping content to include product name */ | |
| bricksextras_queue_toast( 'mfhden', $product->get_name() . ' added to cart!' ); | |
| } | |
| } | |
| return $url; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment