PluginProbe
Discount Rules for WooCommerce – Disco | Dynamic Pricing, Conditions, Bulk, Bundle, BOGO / 1.1.9
Discount Rules for WooCommerce – Disco | Dynamic Pricing, Conditions, Bulk, Bundle, BOGO v1.1.9
1.4.15 1.4.14 1.4.13 1.4.12 1.4.11 1.4.10 1.4.9 1.4.8 1.4.7 1.4.6 1.4.5 1.4.4 1.4.3 1.4.2 1.4.1 1.4.0 1.3.54 1.3.53 1.3.52 1.3.51 1.3.50 1.3.49 1.3.48 1.3.47 1.3.46 All 178 releases
disco / app / Utility / Helper.php

Helper.php in Discount Rules for WooCommerce – Disco | Dynamic Pricing, Conditions, Bulk, Bundle, BOGO 1.1.9, at app/Utility/Helper.php

129 lines 4.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Search Utility
4 *
5 * @package Disco
6 * @subpackage App\Utility
7 * @since 1.0.0
8 * @category Utility
9 */
10
11 namespace Disco\App\Utility;
12
13 use WC_Cart;
14
15 /**
16 * Class Helper
17 *
18 * @package Disco
19 * @subpackage App\Utility
20 * @author Ohidul Islam <wahid0003@gmail.com>
21 * @link https://webappick.com
22 * @license https://opensource.org/licenses/gpl-license.php GNU Public License
23 * @category Utility
24 */
25 class Helper {
26
27 /**
28 * Get Cart Info.
29 *
30 * @param \WC_Cart $cart Cart Object.
31 * @param string $item_id Item ID.
32 * @return array
33 */
34 public static function cart_info( $cart, $item_id = '' ) {
35 $cart_info = array();
36
37 if ( $cart instanceof WC_Cart ) {
38 $cart_info['total']['line_items_count'] = $cart->get_cart_contents_count();
39 $cart_info['total']['cart_items_quantity'] = array_sum( $cart->get_cart_item_quantities() );
40 $cart_info['total']['cart_total_weight'] = $cart->get_cart_contents_weight();
41 $cart_info['total']['cart_subtotal'] = $cart->get_subtotal();
42
43 foreach ( $cart->get_cart() as $item ) {
44 $id = $item['product_id'];
45
46 if ( $item['variation_id'] ) {
47 $id = $item['variation_id'];
48 }
49
50 $item_info = array(
51 'product_id' => $item['product_id'],
52 'variation_id' => $item['variation_id'],
53 'cart_line_item_quantity' => $item['quantity'],
54 'cart_line_item_subtotal' => $item['line_subtotal'],
55 'cart_line_item_id' => $item['data']->get_id(),
56 'cart_line_item_sku' => $item['data']->get_sku(),
57 'cart_line_item_title' => $item['data']->get_name(),
58 'cart_line_item_attributes' => $item['data']->get_attributes(),
59 'cart_line_item_category' => wp_strip_all_tags( $item['data']->get_categories() ),
60 'cart_line_item_tags' => $item['data']->get_tags(),
61 'cart_line_item_weight_unit' => $item['data']->get_meta( '_unit' ),
62 'cart_line_item_weight' => $item['data']->get_weight(),
63 'cart_line_item_width' => $item['data']->get_width(),
64 'cart_line_item_height' => $item['data']->get_height(),
65 'cart_line_item_length' => $item['data']->get_length(),
66 'cart_line_item_type' => $item['data']->get_type(),
67 'product' => $item['data'],
68 );
69
70 if ( $item_id && $item_id === $id ) {
71 return $item_info;
72 }
73
74 $cart_info['items'][ $id ] = $item_info;
75 }//end foreach
76 }//end if
77
78 return $cart_info;
79 }
80
81 /**
82 * Check product discount has any date limit.
83 *
84 * @param \Disco\App\Utility\Config $config Campaign Configuration.
85 * @return bool
86 */
87 public static function is_in_valid_date( $config ) {
88 if ( empty( $config->discount_valid_from ) && empty( $config->discount_valid_to ) ) {
89 return true;
90 }
91
92 if (
93 isset( $config->discount_valid_from )
94 && strtotime( $config->discount_valid_from )
95 && empty( $config->discount_valid_to )
96 ) {
97 $today = gmdate( 'Y-m-d H:i:s' );
98 $start_date = gmdate( 'Y-m-d H:i:s', strtotime( $config->discount_valid_from ) );
99
100 return $today >= $start_date;
101 }
102
103 if ( isset( $config->discount_valid_from, $config->discount_valid_to )
104 && strtotime( $config->discount_valid_from )
105 && strtotime( $config->discount_valid_to )
106 ) {
107 $today = gmdate( 'Y-m-d H:i:s' );
108 $start_date = gmdate( 'Y-m-d H:i:s', strtotime( $config->discount_valid_from ) );
109 $end_date = gmdate( 'Y-m-d H:i:s', strtotime( $config->discount_valid_to ) );
110
111 return ( $today >= $start_date ) && ( $today <= $end_date );
112 }
113
114 return false;
115 }
116
117 /**
118 * Check if the product is passed the filter
119 *
120 * @param \Disco\App\Utility\Config $config Campaign Configuration.
121 * @param array $product Product Info.
122 * @return bool
123 */
124 public static function is_filter_passed( $config, $product ) {
125 return ( new Conditions( $config, $product ) )->is_passed();
126 }
127
128 }
129