Documentation

Scheduling actions

Since version 2.1 ShopMagic utilizes Action Scheduler to process all actions triggered by events in WooCommerce. This means that when the event occurs (i.e. the order is placed), the action (i.e. sending customer email) is added to the Action Scheduler queue and is slightly delayed.
We decided to use Action Scheduler to get better reliability and speed up WooCommerce events, for example, the checkout process or order fulfillment. However, this means that the actions will be processed with a slight delay when they get through the Action Scheduler process.
This delay will be less than a minute, but can also result in a longer time depending on your WP-Cron configuration.

Skipping the queue#

Although this delay is small, in certain events this can still cause some user concerns. For example user registration or some other transactional events.
That's why we've also prepared a filter that you can use to skip the queue and process the actions immediately when the event happens. For all or selected events according to your needs.

All events#

In order to skip the queue for all events and perform the actions immediately use the following code:
add_filter( 'shopmagic/core/queue/avoid_queue', '__return_true' );

Specific automation#

The following example will skip the queue for automation with ID 99. Replace "99" with your automation ID.

add_filter( 'shopmagic/core/queue/avoid_queue', 'sm_avoid_queue_for_automation', 10, 2 );
/**
 * Skip ShopMagic queue for specific automation
 *
 * @param $avoid_queue
 * @param $automation
 *
 * @return bool
 */
function sm_avoid_queue_for_automation( $avoid_queue, $automation ) {

   $automation_id = 99; // Replace 99 with your automation ID

   if ( $automation->get_id() === $automation_id ) {
      return true;
   }

   return $avoid_queue;
}

You can find your automation ID in the URL when you edit it.
Automation Id

Specific events/actions#

We will provide these code examples in the future.

Custom schedule with Delayed Actions extension#

If you are using Delayed Actions, you can utilize another WordPress filter to set a custom schedule time for items added to the queue.
This way you can use some custom metadata from i.e. ordered product to use it as delay time (which is not possible normally, through ShopMagic placeholders).

add_filter('shopmagic/delayed_actions/delay_timestamp', function (
  int $timestamp,
  \Psr\Container\ContainerInterface $action_data,
  array $provided_data
): int {
  // Use custom timestamp only for actions with email subject 'Hello, new customer'.
  if ($action_data->get('subject_value') === 'Hello, new customer') {
    // Get meta from ordered item.
      $product_meta = $provided_data[ WC_Order::class ]->get_item_meta('my_custom_product_meta');
      // Return meta value as date timestamp.
      return (new DateTime($product_meta))->getTimestamp();
    }

  return $timestamp;
  }
 );

THe above example is just an illustration. Do not use this code in production, as it doesn't use enough type checks and data malformation.

Not the solution you are looking for?

Please check other articles or open a support ticket.

Cookies preferences

Others

Other uncategorized cookies are those that are being analyzed and have not been classified into a category as yet.

Necessary

Necessary
Necessary cookies are absolutely essential for the website to function properly. These cookies ensure basic functionalities and security features of the website, anonymously.

Advertisement

Advertisement cookies are used to provide visitors with relevant ads and marketing campaigns. These cookies track visitors across websites and collect information to provide customized ads.

Analytics

Analytical cookies are used to understand how visitors interact with the website. These cookies help provide information on metrics the number of visitors, bounce rate, traffic source, etc.

Functional

Functional cookies help to perform certain functionalities like sharing the content of the website on social media platforms, collect feedbacks, and other third-party features.

Performance

Performance cookies are used to understand and analyze the key performance indexes of the website which helps in delivering a better user experience for the visitors.