Skip to content

Instantly share code, notes, and snippets.

@wplit
Last active February 26, 2026 22:46
Show Gist options
  • Select an option

  • Save wplit/9bb06c1aa01d0fb34d1b441773a24527 to your computer and use it in GitHub Desktop.

Select an option

Save wplit/9bb06c1aa01d0fb34d1b441773a24527 to your computer and use it in GitHub Desktop.
FluentCart Product Transaction Hash Lookup, add to child theme functions.php
<?php
/**
* FluentCart Product Transaction Hash Lookup
*
* @param int $product_id The product ID to check for
* @return string The transaction hash if product was just purchased
*/
function get_fluentcart_product_trx_hash( $product_id ) {
if ( ! class_exists( '\FluentCart\App\Models\OrderTransaction' ) ) {
return 'no_purchase';
}
// Get transaction hash from URL
$trx_hash = sanitize_text_field( $_GET['trx_hash'] ?? '' );
if ( ! $trx_hash ) {
return 'no_purchase';
}
// Find transaction by UUID
$transaction = \FluentCart\App\Models\OrderTransaction::where( 'uuid', $trx_hash )->first();
if ( ! $transaction ) {
return 'no_purchase';
}
// Get the order associated with this transaction
$order = $transaction->orders()->first();
if ( ! $order ) {
return 'no_purchase';
}
// Get order items to check for the target product
$order_items = $order->order_items()->get();
$target_product_id = intval( $product_id );
foreach ( $order_items as $item ) {
if ( $item->post_id == $target_product_id ) {
return $trx_hash;
}
}
// Product not found in this order
return 'no_purchase';
}
/* remember to register the custom function with bricks */
add_filter( 'bricks/code/echo_function_names', function() {
return [
'get_fluentcart_product_trx_hash',
];
} );
@wplit
Copy link
Author

wplit commented Feb 26, 2026

Usage in Bricks, using the Current URL / contains

SCR-20260227-ixma

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment