acf-boolean.php
4 years ago
acf-choice.php
4 years ago
acf-text.php
4 years ago
browser.php
4 years ago
condition.php
4 years ago
date-range.php
4 years ago
date.php
4 years ago
day.php
4 years ago
device.php
4 years ago
ip-location.php
4 years ago
lang.php
4 years ago
login-status.php
4 years ago
operating-system.php
4 years ago
page.php
4 years ago
post-type.php
4 years ago
post.php
4 years ago
time-range.php
4 years ago
url-referer.php
4 years ago
user-role.php
4 years ago
woo-cat-page.php
4 years ago
woo-category.php
4 years ago
woo-last-purchase.php
4 years ago
woo-orders.php
4 years ago
woo-product-cat.php
4 years ago
woo-product-price.php
4 years ago
woo-product-stock.php
4 years ago
woo-total-price.php
4 years ago
woo-orders.php
115 lines
| 1 | <?php |
| 2 | /** |
| 3 | * Woocommerce Orders Condition Handler. |
| 4 | */ |
| 5 | |
| 6 | namespace PremiumAddons\Includes\PA_Display_Conditions\Conditions; |
| 7 | |
| 8 | // Elementor Classes. |
| 9 | use Elementor\Controls_Manager; |
| 10 | |
| 11 | // PA Classes. |
| 12 | use PremiumAddons\Includes\Helper_Functions; |
| 13 | |
| 14 | if ( ! defined( 'ABSPATH' ) ) { |
| 15 | exit; // Exit if accessed directly. |
| 16 | } |
| 17 | |
| 18 | /** |
| 19 | * Class Woo_Orders. |
| 20 | */ |
| 21 | class Woo_Orders extends Condition { |
| 22 | |
| 23 | /** |
| 24 | * Get Controls Options. |
| 25 | * |
| 26 | * @access public |
| 27 | * @since 4.7.0 |
| 28 | * |
| 29 | * @return array|void controls options |
| 30 | */ |
| 31 | public function get_control_options() { |
| 32 | |
| 33 | return array( |
| 34 | 'label' => __( 'Number of Items', 'premium-addons-for-elementor' ), |
| 35 | 'type' => Controls_Manager::NUMBER, |
| 36 | 'min' => 0, |
| 37 | 'description' => __( 'Enter 0 to check if empty. Any other value will be the minimum number of items to check.', 'premium-addons-for-elementor' ), |
| 38 | 'condition' => array( |
| 39 | 'pa_condition_key' => 'woo_orders', |
| 40 | ), |
| 41 | ); |
| 42 | |
| 43 | } |
| 44 | |
| 45 | |
| 46 | /** |
| 47 | * Get Value Controls Options. |
| 48 | * |
| 49 | * @access public |
| 50 | * @since 4.7.0 |
| 51 | * |
| 52 | * @return array controls options. |
| 53 | */ |
| 54 | public function add_value_control() { |
| 55 | |
| 56 | return array( |
| 57 | 'label' => __( 'Status', 'premium-addons-for-elementor' ), |
| 58 | 'type' => Controls_Manager::SELECT, |
| 59 | 'default' => 'in-cart', |
| 60 | 'label_block' => true, |
| 61 | 'options' => array( |
| 62 | 'in-cart' => __( 'In Cart', 'premium-addons-for-elementor' ), |
| 63 | 'purchased' => __( 'Purchased', 'premium-addons-for-elementor' ), |
| 64 | ), |
| 65 | 'condition' => array( |
| 66 | 'pa_condition_key' => 'woo_orders', |
| 67 | ), |
| 68 | ); |
| 69 | |
| 70 | } |
| 71 | |
| 72 | /** |
| 73 | * Compare Condition Value. |
| 74 | * |
| 75 | * @access public |
| 76 | * @since 4.7.0 |
| 77 | * |
| 78 | * @param array $settings element settings. |
| 79 | * @param string $operator condition operator. |
| 80 | * @param string $value condition value. |
| 81 | * @param string $compare_val compare value. |
| 82 | * @param string|bool $tz time zone. |
| 83 | * |
| 84 | * @return bool|void |
| 85 | */ |
| 86 | public function compare_value( $settings, $operator, $compare_val, $value, $tz ) { |
| 87 | |
| 88 | if ( '' === $compare_val ) { |
| 89 | return true; |
| 90 | } |
| 91 | |
| 92 | if ( 'in-cart' === $value ) { |
| 93 | $item_count = WC()->cart->get_cart_contents_count(); |
| 94 | } else { |
| 95 | |
| 96 | $args = array( |
| 97 | 'customer_id' => get_current_user_id(), |
| 98 | 'status' => array( 'wc-completed' ), |
| 99 | ); |
| 100 | |
| 101 | $item_count = count( wc_get_orders( $args ) ); |
| 102 | } |
| 103 | |
| 104 | if ( 0 === (int) $compare_val ) { |
| 105 | $condition_result = (int) $compare_val === $item_count ? true : false; |
| 106 | |
| 107 | } else { |
| 108 | $condition_result = (int) $compare_val <= $item_count ? true : false; |
| 109 | } |
| 110 | |
| 111 | return Helper_Functions::get_final_result( $condition_result, $operator ); |
| 112 | } |
| 113 | |
| 114 | } |
| 115 |