PluginProbe
Discount Rules for WooCommerce – Disco | Dynamic Pricing, Conditions, Bulk, Bundle, BOGO / 1.4.14
Discount Rules for WooCommerce – Disco | Dynamic Pricing, Conditions, Bulk, Bundle, BOGO v1.4.14
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 1.3.45 All 177 releases
disco / app / Intents / BuyXGetYIntent.php

BuyXGetYIntent.php in Discount Rules for WooCommerce – Disco | Dynamic Pricing, Conditions, Bulk, Bundle, BOGO 1.4.14, at app/Intents/BuyXGetYIntent.php

93 lines 2.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * @package Disco
4 * @subpackage \App\Intents
5 */
6
7 namespace Disco\App\Intents;
8
9 /**
10 * Class Cart
11 *
12 * @package Disco
13 * @subpackage \App\Intents
14 * @author Ohidul Islam <wahid0003@gmail.com>
15 * @link https://webappick.com
16 * @license https://opensource.org/licenses/gpl-license.php GNU Public License
17 * @category Intention
18 */
19 class BuyXGetYIntent extends Intent {
20
21 /**
22 * Intent constructor.
23 *
24 * @param \Disco\App\Utility\Config $campaign Campaign Config.
25 * @param \Disco\App\Utility\Settings $settings Global Settings.
26 */
27 public function __construct( $campaign, $settings ) {
28 parent::__construct( $campaign, $settings );
29
30 $this->campaign = $campaign;
31 $this->settings = $settings;
32 }
33
34 /**
35 * Apply BuyXGetY intention.
36 *
37 * @param array $items Discount Applicable Cart Items.
38 * @param \WC_Cart $cart Cart.
39 * @return array
40 */
41 public function get_discounts( $items, $cart ) {//phpcs:ignore
42 return $this->get_item_discounts( $this->campaign, $items, $cart );
43 }
44
45
46 /**
47 * Get offers for Cart intention.
48 *
49 * @param array $items Discount Applicable Cart Items.
50 * @param \WC_Cart $cart Cart.
51 * @return array|bool
52 */
53 public function get_offers( $items, $cart ) { //phpcs:ignore
54 if ( empty( $items ) ) {
55 return false;
56 }
57
58 $offers = array();
59 $rules = $this->campaign->get_discount_rules();
60
61 if ( is_array( $rules ) && ! empty( $rules ) ) {
62 foreach ( $rules as $rule ) {
63 $rule = (array) $rule;
64
65 $bogo_type = $this->campaign->get_bogo_type();
66 $ul = '<ul style="margin: 10px 1px 10px 10px;">';
67
68 foreach ( $rule['get_ids'] as $product ) {
69 $ul .= '<li>' . $product['name'] . '</li>';
70 }
71
72 $ul .= '</ul>';
73
74 if ( 'free' === $rule['discount_type'] ) {
75 $discount = 'Get ' . $rule['get_quantity'] . ' of bellow ' . $bogo_type . " \n" . $ul . 'For Free';
76 } elseif ( 'percent' === $rule['discount_type'] ) {
77 $discount = 'Get ' . $rule['get_quantity'] . ' of bellow ' . $bogo_type . " \n" . $ul . ' With ' . $rule['discount_value'] . '% off';
78 } else {
79 $discount = 'Get ' . $rule['get_quantity'] . ' of bellow ' . $bogo_type . " \n" . $ul . ' With ' . wc_price( $rule['discount_value'] ) . ' off';
80 }
81
82 $offers[] = array(
83 'condition' => $rule['min'] . ' - ' . $rule['max'],
84 'discount' => '<b>' . $discount . '</b>',
85 );
86 }//end foreach
87 }//end if
88
89 return $offers;
90 }
91
92 }
93