DocumentationDevelopersOrder-item meta

Order-item meta

Every fee line this plugin writes carries `_pay4payment_fee_gateway` and `_pay4payment_fee_source`; product lines add `_pay4payment_fee_taxable`. They tell an export which payment method the fee was for, and where the line came from.

Free and ProUpdated for 3.0.0

The keys

Pay for Payment tags every fee line it writes onto an order with these order-item meta keys:

KeyValueOn
_pay4payment_fee_gatewayThe payment method id the fee was charged for: cod, bacs, stripe, …every line
_pay4payment_fee_sourceWhere the line was written — see belowevery line
_pay4payment_fee_taxableyes / no: whether the fee was taxable, since a product line has no fee-line tax flag of its ownproduct lines only (Pro)

Source values

ValueWritten by
checkoutThe classic or block checkout — the cart fee, as core created it
order_payThe pay-for-order page (Pro’s off-checkout charge)
adminAn order created or edited in wp-admin (Pro)
convertedA checkout fee line rewritten as a product line once the order existed (Pro, fee as a product line)

Reading them

foreach ( $order->get_items( array( 'fee', 'line_item' ) ) as $item ) {
    if ( $item->get_meta( '_pay4payment_fee_gateway' ) ) {
        // $item is this plugin's fee for that gateway.
        $gateway = $item->get_meta( '_pay4payment_fee_gateway' );
        $source  = $item->get_meta( '_pay4payment_fee_source' );
    }
}

The keys start with an underscore, so WooCommerce hides them from the customer-facing order screens and emails; they are visible in the admin’s order-item meta box and to any export that reads item meta.

The pay4payment_is_plugin_fee_item filter lets you tell the plugin that a line is its fee when the meta is missing — see the hooks list.

Orders from 2.x

Orders placed before 3.0 have no meta. The plugin recognises its own lines on those orders by their title: it matches the fee label configured for each rule, and the payment method’s own name where a rule has no label. That is what the order-pay logic and the watchdog fall back to.

Need a hook that isn't here? Open an issue — filters get added when there's a real case for them.

Suggest a feature