1. Home
  2. Knowledge Base
  3. WooCommerce Product Add-Ons Ultimate
  4. Trigger action when order is processed
  1. Home
  2. Knowledge Base
  3. Orders
  4. Trigger action when order is processed
  1. Home
  2. Knowledge Base
  3. Advanced
  4. Trigger action when order is processed

Trigger action when order is processed

If you would like to trigger an action, e.g. sending a custom email, depending on the value of a specific field, you can do something like this:

<?php
/**
* Trigger an action if a field has a specific value
* @param $add_on_id ID of Add-On
* @param $order WooCommerce order object
* @param $field Add-On field object
*/
function prefix_pewc_after_create_product_extra( $add_on_id, $order, $field ) {
// Check specific field ID is checked
if( $field['field_id'] == 1234 && $field['value'] == '__checked__' ) {
// Do our action here
}
}
add_action( 'pewc_after_create_product_extra', 'prefix_pewc_total_only_text', 10, 3 );

The code above checks each field in an order for a specific ID and a specific value. In this example, the field ID is 1234, the field type is a checkbox, so we’re checking for ‘__checked__’ as the field value. You can modify this as you wish.

Was this article helpful?

Related Articles