The WooCommerce Cart, Checkout and Mini-Cart blocks get their data from the Store API. Pricepep's prices, cart discounts and fees are in the cart response like any others: product pricing rules change the item prices, each cart discount is a coupon whose code is the rule ID (it starts with rp_wcdpd_, or is rp_wcdpd_combined for combined discounts), and checkout fees are in fees. On top of that, Pricepep adds two sets of data to the cart response and one update callback. Its own scripts use them in the blocks; a headless store or a custom checkout can use them the same way.
| Name | Kind | Used for |
|---|---|---|
rp_wcdpd_virtual_coupon_data | Cart data under extensions | Cart discount titles instead of coupon codes |
rp_wcdpd_total_saved | Cart data under extensions | The You Saved row |
rp_wcdpd_payment_method | Update callback (extensionCartUpdate) | Payment method conditions in the Checkout block |
All three are registered on woocommerce_blocks_loaded, except in WP-CLI.
rp_wcdpd_virtual_coupon_data
Labels for Pricepep's cart discounts, read from extensions.rp_wcdpd_virtual_coupon_data in the cart response.
"extensions": {
"rp_wcdpd_virtual_coupon_data": {
"labels": {
"rp_wcdpd_combined": "Discount"
}
}
}
| Field | Type | Description |
|---|---|---|
labels | object | Coupon code → label, for every Pricepep cart discount in the cart. Empty when there are none or there is no cart. |
The label is plain text: the cart discount's Title - Public, or the combined title when If multiple discounts are applicable is set to combine them, with HTML tags removed and characters such as & and ' as typed. The rule's Description - Public isn't part of it; the hover tip with the description is shown in the classic cart only.
Pricepep's script assets/js/cart-checkout-block-interop.js puts these labels on the blocks' discount lines with registerCheckoutFilters('rp-wcdpd-virtual-coupon-labels', { coupons }).
rp_wcdpd_total_saved
The You Saved row, read from extensions.rp_wcdpd_total_saved in the cart response.
"extensions": {
"rp_wcdpd_total_saved": {
"enabled": true,
"label": "You Saved",
"formatted": "$12.50",
"amount": 1250,
"cart": true,
"checkout": true
}
}
| Field | Type | Description |
|---|---|---|
enabled | boolean | true when the row should show: the tool is enabled, there is a cart, and the amount is above zero and at least the Discount amount threshold. |
label | string | The Label setting, as plain text. |
formatted | string | The amount with currency, as plain text. |
amount | integer | The amount in the currency's smallest unit, using the store's number of decimals (1250 for 12.50). |
cart | boolean | Show the row in the Cart block (Position in cart isn't Disabled). |
checkout | boolean | Show the row in the Checkout block (Position in checkout isn't Disabled). |
When enabled is false, the other fields are empty, 0 or false. The filters rp_wcdpd_promotion_total_saved_display, rp_wcdpd_promotion_total_saved_label and rp_wcdpd_promotion_total_saved_formatted_amount apply here too, with $hook set to store_api; see the filter reference. Pricepep's extensions/promotion-total-saved/assets/blocks.js shows the row on pages with a Cart or Checkout block.
rp_wcdpd_payment_method
An update callback for cart discounts and checkout fees with the Payment method condition. The classic checkout sends the selected payment method with every update; the Checkout block doesn't, so Pricepep's script sends it:
window.wc.blocksCheckout.extensionCartUpdate({
namespace: 'rp_wcdpd_payment_method',
data: { payment_method: 'cod' }
});
| Data | Type | Description |
|---|---|---|
payment_method | string | ID of the selected payment method, such as cod or bacs. |
Pricepep saves the ID as the session's chosen payment method if that method is available for the cart, and ignores it otherwise. WooCommerce then recalculates the cart and returns it, so the discounts and fees follow the method. Without extensionCartUpdate, send the same body to the Store API route POST /wp-json/wc/store/v1/cart/extensions: {"namespace": "rp_wcdpd_payment_method", "data": {"payment_method": "cod"}}.
Pricepep's script sends the update only when a cart discount or checkout fee rule uses the Payment method condition (window.rp_wcdpd_blocks.sync_payment_method is then true). When the order is placed, Pricepep uses the method the order is placed with in any case; see fee or discount by payment method.
Do the Store API product routes return Pricepep prices?
Yes, when Change display prices in shop is set to Change - Include simple adjustments or Change - Include all adjustment types (WooCommerce > Pricepep > Settings). The product routes (GET /wp-json/wc/store/v1/products and single products), used by the All Products block, headless shops and apps, then return the prices product pages show, following the same setting. Variable products included: prices.price is the lowest variation price after the rules, and prices.price_range gives the lowest and highest when the variations' prices differ (null when they don't), as WooCommerce does. With Do not change they return the products' own prices.
The WooCommerce REST API product endpoints (/wp-json/wc/v3/products) return the products' own prices when they're called over HTTP: WooCommerce loads no cart for REST requests, and Pricepep changes shop prices only once the cart is loaded. WP-CLI's wp wc product commands run the same endpoints inside WordPress, like a storefront visit, so with a Change option they return Pricepep's shop prices for their --user (which wp wc commands need): that user's role, cart and address. To keep the products' own prices in the Store API product routes too, return false from rp_wcdpd_store_api_product_prices; see the filter reference.
How do I leave Pricepep's data out of REST API orders?
The WooCommerce REST API order endpoints (/wp-json/wc/v3/orders) return all meta of each line item, so a product line that a pricing rule changed carries _rp_wcdpd_product_pricing_data (what the rules did to its price). If an integration doesn't need it, remove it from the response with WooCommerce's woocommerce_rest_prepare_shop_order_object filter; the order itself keeps the data:
// Leave Pricepep's rule data out of the line items in REST API order responses
add_filter('woocommerce_rest_prepare_shop_order_object', function ($response, $order, $request) {
$data = $response->get_data();
if (!empty($data['line_items'])) {
foreach ($data['line_items'] as $i => $item) {
if (!empty($item['meta_data'])) {
$data['line_items'][$i]['meta_data'] = array_values(array_filter($item['meta_data'], function ($meta) {
return $meta['key'] !== '_rp_wcdpd_product_pricing_data';
}));
}
}
$response->set_data($data);
}
return $response;
}, 10, 3);
Put it in a small plugin or your child theme's functions.php; see where do I put this code?.
Frequently asked questions
Can a headless store show Pricepep's cart discount titles?
Yes. Read extensions.rp_wcdpd_virtual_coupon_data.labels in the Store API cart response. It maps the code of each Pricepep cart discount (codes start with rp_wcdpd_) to its label.
How do payment method discounts update in a custom checkout?
Send the selected payment method ID with extensionCartUpdate, namespace rp_wcdpd_payment_method, data { payment_method }. Pricepep makes it the chosen payment method and WooCommerce returns the recalculated cart.
Does Pricepep add its own REST routes?
No. It adds data to the Store API cart endpoint and one update callback, both registered through WooCommerce's extension functions.
Why do REST API orders contain _rp_wcdpd_product_pricing_data?
It's the line item meta where Pricepep saves what its rules did to the item's price. To leave it out of REST API order responses, remove it with WooCommerce's woocommerce_rest_prepare_shop_order_object filter, as in the example on this page.