Skip to content

Instantly share code, notes, and snippets.

@danielbitzer
Last active September 14, 2022 11:32
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save danielbitzer/7cf1ba89839f1bd70028 to your computer and use it in GitHub Desktop.
Save danielbitzer/7cf1ba89839f1bd70028 to your computer and use it in GitHub Desktop.
AutomateWoo Custom Validation Example
<?php
add_filter( 'automatewoo_custom_validate_workflow', 'my_custom_workflow_validation' );
/**
* @param bool $valid
* @param AW_Model_Workflow $workflow
*
* @return bool
*/
function my_custom_workflow_validation( $valid, $workflow )
{
$order = $this->get_data_item('order');
$target_workflow_id = '123';
// we only want to add the validation to a single workflow
// which we will target by its id (same as post id)
if ( $workflow->id != $target_workflow_id ) return $valid;
// we must have an order
if ( ! $order ) return $valid;
$custom_checkout_field = get_post_meta( $order->id, 'custom_checkout_field', true );
// if checkout field is empty then fail the validation
if ( ! $custom_checkout_field ) return false;
return $valid;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment