Last active
February 26, 2026 22:46
-
-
Save wplit/9bb06c1aa01d0fb34d1b441773a24527 to your computer and use it in GitHub Desktop.
FluentCart Product Transaction Hash Lookup, add to child theme functions.php
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 | |
| /** | |
| * 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', | |
| ]; | |
| } ); |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Usage in Bricks, using the Current URL / contains