HEX
Server: Apache/2.4.65 (Ubuntu)
System: Linux ielts-store-v2 6.8.0-1036-gcp #38~22.04.1-Ubuntu SMP Thu Aug 14 01:19:18 UTC 2025 x86_64
User: root (0)
PHP: 7.2.34-54+ubuntu20.04.1+deb.sury.org+1
Disabled: pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_get_handler,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,pcntl_async_signals,
Upload Files
File: //proc/self/cwd/wp-content/plugins/automatewoo/includes/Triggers/Wishlist_Item_Goes_On_Sale.php
<?php
// phpcs:ignoreFile

namespace AutomateWoo;

use AutomateWoo\Jobs\WishlistItemOnSale;

if ( ! defined( 'ABSPATH' ) ) exit;

/**
 * @class Trigger_Wishlist_Item_Goes_On_Sale
 */
class Trigger_Wishlist_Item_Goes_On_Sale extends Trigger {

	public $supplied_data_items = [ 'customer', 'product', 'wishlist' ];

	const SUPPORTS_QUEUING = false;


	function load_admin_details() {
		$this->title = sprintf( __( 'Wishlist Item On Sale (%s)', 'automatewoo' ), Wishlists::get_integration_title() );
		$this->group = __( 'Wishlists', 'automatewoo' );
		$this->description = __(
			"This trigger doesn't fire instantly when a product goes on sale. Instead, it performs a check for new on-sale products every 30 minutes. "
			. "Please note this doesn't work for guests because their wishlist data only exists in their session data.",
			'automatewoo' );
	}


	function register_hooks() {
		$integration = Wishlists::get_integration();
		if ( ! $integration ) {
			return;
		}

		add_action( 'automatewoo/products/gone_on_sale', [ $this, 'handle_products_on_sale' ] );
	}


	/**
	 * @param array $products
	 */
	public function handle_products_on_sale( $products ) {
		if ( ! $this->has_workflows() || empty( $products ) ) {
			return;
		}

		try {
			/** @var WishlistItemOnSale $job */
			$job = AW()->job_service()->get_job( 'wishlist_item_on_sale' );
			$job->start( [ 'products' => $products ] );
		} catch ( \Exception $e ) {
			Logger::error(
				'jobs',
				sprintf(
					'Exception thrown when attempting to start the wishlist item on sale job: %s',
					$e->getMessage()
				)
			);
		}
	}


	/**
	 * @param $workflow Workflow
	 * @return bool
	 */
	function validate_workflow( $workflow ) {
		// Only trigger once per user, per product, per workflow, check logs
		if ( $workflow->has_run_for_data_item( [ 'product', 'user' ] ) ) {
			return false;
		}

		return true;
	}


	/**
	 * @param Workflow $workflow
	 * @return bool
	 */
	function validate_before_queued_event( $workflow ) {
		$product = $workflow->data_layer()->get_product();

		if ( ! $product->is_on_sale() ) {
			return false; // check product is still on sale
		}

		return true;
	}

}