GhostManSec
Server: LiteSpeed
System: Linux premium197.web-hosting.com 4.18.0-553.54.1.lve.el8.x86_64 #1 SMP Wed Jun 4 13:01:13 UTC 2025 x86_64
User: parhudrw (1725)
PHP: 7.4.33
Disabled: NONE
Upload Files
File: //home/parhudrw/ve.anqa.it/wp-content/plugins/depicter/app/src/Rules/Condition/WooCommerce/Cart.php
<?php

namespace Depicter\Rules\Condition\WooCommerce;

use Averta\Core\Utility\Arr;
use Depicter\Rules\Condition\Base as ConditionBase;

class Cart extends ConditionBase
{
	/**
	 * @inheritdoc
	 */
	public $slug = 'WooCommerce_Cart';

	/**
	 * @inheritdoc
	 */
	public $control = 'dropdown';

	/**
	 * @inheritdoc
	 */
	protected $belongsTo = 'WooCommerce';

	/**
	 * Default value
	 *
	 * @var array|string
	 */
	protected $defaultValue = 'is_not_empty';

	/**
	 * @inheritdoc
	 */
	public function getLabel(): ?string{
		return __('Cart', 'depicter' );
	}

	/**
	 * @inheritDoc
	 */
	public function getControlOptions(){
		$options = parent::getControlOptions();

		return Arr::merge( $options, [ 'options' => [
			[
				'label' => __( 'Cart Is Empty', 'depicter' ),
				'value' => 'is_empty'
			],
			[
				'label' => __( 'Cart Is Not Empty', 'depicter' ),
				'value' => 'is_not_empty'
			],
		]]);
	}

	/**
	 * @inheritdoc
	 */
	public function check( $value = null ): bool{

		$isIncluded = false;

		$value = $value ?? $this->value[0] ?? $this->defaultValue;

		if ( $value == 'is_empty') {
			if ( WC()->cart->is_empty() ) {
				$isIncluded = true;
			}
		} else if ( $value == 'is_not_empty') {
			if ( ! WC()->cart->is_empty() )  {
				$isIncluded = true;
			}
		}

		return $this->selectionMode === 'include' ? $isIncluded : !$isIncluded;
	}
}