Last active
September 14, 2022 11:32
-
-
Save danielbitzer/7cf1ba89839f1bd70028 to your computer and use it in GitHub Desktop.
AutomateWoo Custom Validation Example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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