Skip to content

Instantly share code, notes, and snippets.

@wplit
Last active January 30, 2026 05:55
Show Gist options
  • Select an option

  • Save wplit/4a6bec1e8843c0ae506f648ac171489b to your computer and use it in GitHub Desktop.

Select an option

Save wplit/4a6bec1e8843c0ae506f648ac171489b to your computer and use it in GitHub Desktop.
example code, queuing a toast on WooCommerce' redirect hook
<?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