// Make a draft from PHP (the same checks as the button: limits, masking, post-check); nothing is sent
$r = TQSD_Drafter::draft( $order_id, array( 'message' => $text, 'intent' => 'where', 'lang' => 'auto' ) );
// $r['draft'], $r['flags'] (amount, date, duration, promise, link, order, placeholder), $r['placeholders']
// The facts of an order, exactly as they are given to the AI
$facts = TQSD_Facts::build( $order_id ); // rows, prompt, tokens (kept on the site), sources, missing
// Tracking numbers of another shipment plugin
add_filter( 'tqsd_tracking_items', function ( $items, $order ) {
$n = $order->get_meta( '_my_tracking_number' );
if ( $n ) {
$items[] = array( 'number' => $n, 'carrier' => 'My Courier', 'link' => 'https://track.example/' . rawurlencode( $n ) );
}
return $items;
}, 10, 2 );
// Who may draft and who may send (on top of the roles in the settings)
add_filter( 'tqsd_can_send', function ( $ok, $user, $order_id ) { return $ok && user_can( $user, 'manage_woocommerce' ); }, 10, 3 );
// Add a shop rule to the instructions (the customer message stays data)
add_filter( 'tqsd_system_prompt', function ( $p ) { return $p . "\nNever mention our second warehouse."; } );
// The key can live in wp-config.php
define( 'TQSD_AI_KEY', 'sk-...' );