Skip to content

Instantly share code, notes, and snippets.

@ctrlaltdylan
Last active December 24, 2025 20:48
Show Gist options
  • Select an option

  • Save ctrlaltdylan/77f148633c541cbbb9c8b07f2c92f861 to your computer and use it in GitHub Desktop.

Select an option

Save ctrlaltdylan/77f148633c541cbbb9c8b07f2c92f861 to your computer and use it in GitHub Desktop.
Implements ID verification as a shortcode, but only for orders >$200 and using the Unlimit gateway
/**
* Real ID verification shortcode for custom thank-you page
*
* Triggers ID verification for orders over $200 with specific payment gateways.
* Usage: [real_id_custom_verification]
*/
add_shortcode('real_id_custom_verification', function() {
$logger = wc_get_logger();
$context = ['source' => 'real_id_custom_verification'];
// Payment gateways that require ID verification (add more as needed)
$required_gateways = [
'woo-unlimit-custom',
'custom_254a077438c40ac'
];
// Minimum order total to trigger verification
$minimum_order_total = 200;
// Get order key from query params (e.g., ?key=wc_order_b6kYqc0dSCgt4)
$order_key = isset($_GET['key']) ? sanitize_text_field($_GET['key']) : null;
if (!$order_key) {
$logger->warning('No order key found in URL query params', $context);
return '';
}
// Look up order by order key
$order_id = wc_get_order_id_by_order_key($order_key);
if (!$order_id) {
$logger->error('Failed to find order by key', array_merge($context, [
'order_key' => $order_key,
]));
return '';
}
$order = wc_get_order($order_id);
if (!$order) {
$logger->error('Failed to load order object', array_merge($context, [
'order_id' => $order_id,
'order_key' => $order_key,
]));
return '';
}
// Check conditions: order total > $200 AND payment gateway in list
$order_total = (float) $order->get_total();
$payment_method = $order->get_payment_method();
if ($order_total <= $minimum_order_total) {
$logger->debug('Order total below threshold, skipping verification', array_merge($context, [
'order_id' => $order_id,
'order_total' => $order_total,
'minimum_required' => $minimum_order_total,
]));
return '';
}
if (!in_array($payment_method, $required_gateways)) {
$logger->debug('Payment method not in required list, skipping verification', array_merge($context, [
'order_id' => $order_id,
'payment_method' => $payment_method,
'required_gateways' => $required_gateways,
]));
return '';
}
// Conditions met - create ID verification check
$logger->info('Creating ID verification check', array_merge($context, [
'order_id' => $order_id,
'order_total' => $order_total,
'payment_method' => $payment_method,
]));
$result = real_id_create_check(['order_id' => $order_id]);
if (is_wp_error($result)) {
$logger->error('Failed to create ID check', array_merge($context, [
'order_id' => $order_id,
'error' => $result->get_error_message(),
]));
return '';
}
$logger->info('ID verification check created successfully', array_merge($context, [
'order_id' => $order_id,
'check_id' => $result['check_id'],
]));
return $result['widget_html'];
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment