Last active
September 14, 2022 11:04
-
-
Save danielbitzer/baffc5971e8c8a868a1f975fa9f617e5 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
Is it possible to manually assign the credit to advokat with functions or workflow ?. Because one of our advokat reffered person outside of web network to our shop but we want to credit him store credit to his advokat account on website which he can use in web shop.