Skip to content

Instantly share code, notes, and snippets.

@danielbitzer
Last active September 14, 2022 11:04
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save danielbitzer/baffc5971e8c8a868a1f975fa9f617e5 to your computer and use it in GitHub Desktop.
Save danielbitzer/baffc5971e8c8a868a1f975fa9f617e5 to your computer and use it in GitHub Desktop.
Function to programmatically run a specific workflow for a specific order
<?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 );
}
@rayice
Copy link

rayice commented Jul 27, 2021

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment