1. Home
  2. Knowledge Base
  3. Advanced Coupons
  4. Cart Conditions
  5. How to Apply Coupon Coupon Based On Cart Item Meta

How to Apply Coupon Coupon Based On Cart Item Meta

With Advanced Coupons, you are able to create deals if a certain meta data is in the cart. You can do this using the Custom Cart Item Meta Cart Condition.

To use it simply set the Meta Key and Meta Value fields, from there it’ll check and if it matches the coupon can be used else an error message will be shown.

As an example, I’ll be targeting the data_hash meta key with the following meta value.

Which is stored on my test product, this makes it so when said product is in my cart the condition triggers and you can now use the coupon.

If everything goes well with the meta key and meta value matching, it should look something like this:

If you are unsure of the meta key and meta value, you may add the following to your child theme’s functions.php or the WPCode plugin.

// define the woocommerce_after_cart callback 
function action_woocommerce_after_cart() { 
    error_log(print_r(WC()->cart->get_cart_contents(), true));
// add the action 
add_action( 'woocommerce_after_cart', 'action_woocommerce_after_cart', 10, 1 );

This snippet will create a debug.log file that’s located in your WP Content directory. You can access this file via FTP access.

If you ever need to access nested metadata you may use the | text. As an example here we have a metadata list with the variation and a nested attribute_pa_color

To target that metadata you’ll want to set the Meta Key field as variation|attribute_pa_color, on the coupon’s cart condition section, it should look something like this:

If you have questions or need further clarification on using the cart item meta condition, reach out to us here: Submit Support Ticket – Advanced Coupons (advancedcouponsplugin.com)

Was this article helpful?

Related Articles

Need Support?

Can't find the answer you're looking for?
Contact Support