Some stores attach extra data to cart items, such as a custom field from a product add-on. You can restrict a coupon so it only applies when a cart item carries a particular meta key and value. This article shows you how to set the condition, how to find the meta you need, and how to target nested meta.
Before you start
- The Custom Cart Item Meta cart condition needs Advanced Coupons Premium.
- You need to know the meta key and meta value stored on the cart item. The steps below show you how to find them.
Set the cart condition
- Open the coupon and find the Cart Conditions section.
- Add the Custom Cart Item Meta condition.
- Enter the Meta Key.
- Enter the Meta Value.
- Update the coupon.

Advanced Coupons checks the cart against the key and value. If they match, the coupon can be used. If they do not match, the customer sees an error message.

In this example the condition targets the data_hash meta key with the value shown. The value is stored on a test product, so the condition passes whenever that product is in the cart.


Find the meta key and value
If you do not know what meta a cart item carries, log the cart contents. Add the snippet below to your child theme’s functions.php file, or to the WPCode plugin.
// Log the cart contents so you can read the item meta.
function action_woocommerce_after_cart() {
error_log( print_r( WC()->cart->get_cart_contents(), true ) );
}
add_action( 'woocommerce_after_cart', 'action_woocommerce_after_cart' );
Then load the cart page and read the log. The log is written to wp-content/debug.log, but only when WP_DEBUG_LOG is enabled in wp-config.php. If that constant is not enabled, no file is created. You can open the file over FTP or through your host’s file manager.
Target nested meta
To reach meta nested inside another value, join the levels with the pipe character (|). The example below has a variation with a nested attribute_pa_color value.

To target it, set Meta Key to variation|attribute_pa_color. The cart condition then looks like this on the coupon.

Troubleshooting
The coupon never applies. Check the meta key and value against the log output, including capitalisation and any prefix such as attribute_.
No log file appears. Enable WP_DEBUG_LOG in wp-config.php, then reload the cart page. Without it error_log() writes nothing to wp-content.
Nested meta does not match. Check that you joined the levels with the pipe character and that each level name matches the log exactly.
Need help?
If you have a question or run into any issues, we’re here to help.
- Premium users: Open a support ticket
- Free users: Visit our community forum
