# Product-discount PDF integration ## Native WooCommerce Sale price and coupons The commercial Free confirmation and Pro contract support the standard WooCommerce `regular_price` / `sale_price` path. New checkout evidence preserves the applicable regular and sale values before the original document is sealed. Later document reads must not use today's catalogue prices to invent a historical discount. A coupon recorded by WooCommerce is already part of the native order's discount calculation; do not add it again through an extension. This release does not bundle a connector for Discount Rules or another pricing add-on. An installed add-on can already change the effective Woo price before order creation. That effective price alone does not prove its original price, discount amount or percentage. The integrating developer must supply reliable order-time facts from that add-on's documented API or recorded result. A gift voucher represented as a normal Woo coupon follows the coupon path. A gift-card wallet or credit used as a payment method is not automatically a product discount; a separate integration must preserve that distinction. No general compatibility claim is made for gift-card plugins. ## Existing Pro API, not a new discount engine Use the installed **Document Extension API 1.0.0** described in `DOCUMENT-EXTENSION-API.md`. Register selected, typed `money` and/or `structured_block` fields. The existing Pro current-field bridge exposes operational fields in the full current order PDF configuration. These fields display recorded third-party information in an explicitly selected section. They **do not replace native item prices, recalculate Woo totals/tax, change a charge, or automatically participate in the native discount summary**. This is intentional: the same external reduction may already be included in Woo's amount. A developer must not count it twice or label a final effective price as an original price without evidence. For a discount to become a normal financial-table adjustment instead of a separate information section, additional explicitly validated pricing integration would be required. Do not bypass this boundary by editing the PDF model, patching Commerce Assistant or returning HTML. ## Developer responsibilities for Discount Rules and similar add-ons 1. Obtain the actual supported add-on version and its documented order-time discount output. Do not guess its private metadata names or read current product prices to backfill a past sale. 2. In your separate integration plugin, save a bounded, integrator-owned normalized record through Woo order CRUD before the selected document event. Use HPOS-compatible CRUD, not direct postmeta/SQL. Record gross/net/tax meanings explicitly. The example below uses positive gross **line discount amounts after quantity multiplication**, already calculated by the source add-on. 3. Register read-only fields with four-language labels and an explicit metadata-key allowlist. Resolve only those stored facts; no network, repricing, writes or mail in a resolver. 4. Enable the contract fields only for `FORMATION_SNAPSHOT` / `contract`, with `customer-visible` privacy. Select them in a template copy, preview, then publish/activate it. Unselected fields do not appear automatically. 5. For the current operational PDF, select separate `POST_ORDER_CURRENT` / `operational` fields in the Pro additional-PDF-data configuration. Contract and current fields are intentionally different IDs. 6. Verify the two renderers, HPOS/legacy, missing or malformed data, changed or removed source add-on, and unchanged existing original hashes. A current print can reflect subsequently recorded data; an already sealed original cannot. The API receives a read-only copied `OrderProjection`, not a mutable `WC_Order`. It includes only declared bounded order metadata and limited item facts. It does not expose arbitrary item metadata or run the source add-on for you. If the source records item-level data, your adapter must normalize the relevant approved facts into its own order-level record at the appropriate write event. ## Source-only example supplied with the development delivery `examples/ca-recorded-discount-provider/ca-recorded-discount-provider.php` in the **development delivery**, outside the commercial installer, registers four actual existing API fields. It contains no order writer or turnkey vendor connector. Install it only on an isolated synthetic test store. It expects this explicit integrator-owned metadata key: ```php // _example_recorded_product_discounts_v1 [ 'schema' => 1, 'currency' => 'BAM', 'total_discount_gross' => '13.96', 'rows' => [ ['reference' => 'SYNTHETIC-SKU-01', 'discount_gross' => '13.96'], ], ] ``` This schema and metadata key belong to the example, **not Discount Rules, WooCommerce or Commerce Assistant**. Values are canonical two-decimal, positive gross discount strings. Maximum 20 rows; the sum of row minor units must equal the stated total. Missing data, wrong currency, negative/exponent amounts, control characters, oversized or inconsistent records produce no available value. The sample is not suitable for products with more than 20 recorded rows without a separate deliberately bounded design. No arithmetic in the example derives tax or changes prices. | Field ID | Type | Phase | Selection | | --- | --- | --- | --- | | `example.discount.total` | money | FORMATION_SNAPSHOT | `{{EXT:example.discount.total}}` | | `example.discount.rows` | structured_block | FORMATION_SNAPSHOT | `{{EXT_BLOCK:example.discount.rows}}` | | `example.discount.currenttotal` | money | POST_ORDER_CURRENT | Enable in current-PDF settings | | `example.discount.currentrows` | structured_block | POST_ORDER_CURRENT | Enable in current-PDF settings | Choose the total or row presentation appropriate to your design. Showing both provides a breakdown and its total, not a second charge or second deduction. The example uses the same saved record for both phases; replacing that record later affects only newly resolved current output, never existing contract captures. In a new synthetic contract, the selected field values, provider version, language label and hash are frozen before seal. Subsequent original reads do not call the provider. Deactivating the example or updating its saved metadata must not change that original PDF SHA-256. This is a storage/display integration contract, not evidence of any real merchant or production pricing integration. ## Minimal self-contained registration The separately downloadable Document Extension API guide also contains the following compact contract example. It requires your adapter to save `_example_discount_gross` as a canonical nonnegative two-decimal amount and `_example_discount_currency` as the exact order currency before formation: ```php add_action('leanmerce_commerce_assistant_pro_register_document_extensions', static function ($registry) { $registry->register_field(new \Leanmerce\CommerceCompliance\Pro\DocumentExtension\FieldDefinition( 'example.discount.amount', '1.0.0', '1.0.0', ['bs'=>'Popust dodatka', 'hr'=>'Popust dodatka', 'sr'=>'Popust dodatka', 'en'=>'Add-on discount'], ['bs'=>'Sačuvani popust dodatka.', 'hr'=>'Sačuvani popust dodatka.', 'sr'=>'Sačuvani popust dodatka.', 'en'=>'Recorded add-on discount.'], 'money', 'FORMATION_SNAPSHOT', ['contract'], 'customer-visible', static function (\Leanmerce\CommerceCompliance\Pro\DocumentExtension\OrderProjection $order) { $amount = $order->metadata['_example_discount_gross'] ?? null; $currency = $order->metadata['_example_discount_currency'] ?? null; if (!is_string($amount) || !preg_match('/^(?:0|[1-9][0-9]{0,6})\.[0-9]{2}$/D', $amount) || $currency !== $order->currency || $amount === '0.00') { return null; } return ['amount'=>$amount, 'currency'=>$currency]; }, ['_example_discount_gross', '_example_discount_currency'] )); }); ``` Insert `{{EXT:example.discount.amount}}` in a template copy. This amount is additional recorded information, not another deduction from the payable total. The example metadata names are an integration-owned contract, never a claim about a third-party add-on's internal schema. ## Verification limits The source-only example can prove registration, declared metadata, typed validation, selected snapshot capture, escaping and current-field bridging locally. A synthetic example does not prove compatibility with an arbitrary version of Discount Rules, a merchant's rules or a production checkout. That requires the actual add-on and rule-specific functional evidence. Existing commercial licensing, ERP endpoints, WOFF2, legal clauses and historical originals are outside this integration's write scope.