-
-
Save saas786/ceeac7a7c58902a22833fb6ceb637846 to your computer and use it in GitHub Desktop.
Function to programmatically run a specific workflow for a specific order
This file contains 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 | |
/** | |
* Run a specific workflow for a specific order. | |
* | |
* @param int $workflow_id | |
* @param int $order_id | |
* | |
* @throws \Exception | |
*/ | |
function automatewoo_run_order_workflow( int $workflow_id, int $order_id ) { | |
$order = wc_get_order( $order_id ); | |
if ( ! $order ) { | |
throw new \Exception; | |
} | |
$customer = \AutomateWoo\Customer_Factory::get_by_order( $order ); | |
// If the required data items for the trigger are not set here the workflow will not run | |
$workflow_data = new Data_Layer( | |
[ | |
\AutomateWoo\DataTypes\DataTypes::ORDER => $order, | |
\AutomateWoo\DataTypes\DataTypes::CUSTOMER => $customer | |
] | |
); | |
$workflow = \AutomateWoo\Workflows\Factory::get( $workflow_id ); | |
if ( ! $workflow ) { | |
throw new \Exception; | |
} | |
$workflow->maybe_run( $workflow_data ); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment