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 / functions / cart.php

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

53 lines 1.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 // Ensure the file is not accessed directly.
4 if ( ! defined( 'ABSPATH' ) ) {
5 exit;
6 }
7
8 // Set Cart Items discounts.
9 use Disco\App\Disco;
10
11 if ( ! function_exists( 'disco_set_cart_item_price_test' ) ) {
12
13 /**
14 * Set Cart Items discounts.
15 *
16 * @param object $cart Cart object.
17 * @return object
18 * @throws \Exception Error message.
19 */
20 function disco_set_cart_item_price_test( $cart ) {
21 return ( new Disco )->get_cart_items_discount( $cart );
22 }
23
24 add_action( 'woocommerce_cart_calculate_fees', 'disco_set_cart_item_price_test', 1, 1 );
25 }
26
27 if ( ! function_exists( 'disco_cart_item_price_html' ) ) {
28
29 /**
30 * Display Cart Item Sale Price & Regular Price html
31 *
32 * @param \WC_Cart $cart Cart Object.
33 */
34 function disco_cart_item_price_html( $cart ) {
35 $page_name = Disco::get_page_name();
36
37 // Check ONCE outside loop - if strike-through is applicable, skip entire function
38 if ( Disco::is_strike_through_applicable( $page_name ) ) {
39 return;
40 }
41
42 foreach ( $cart->get_cart() as $cart_item_key => $cart_item ) {
43 if ( ! isset( $cart_item['data'] ) || ! is_a( $cart_item['data'], 'WC_Product' ) ) {
44 continue;
45 }
46
47 $cart_item['data']->set_regular_price( '' );
48 }
49 }
50
51 add_action( 'woocommerce_before_calculate_totals', 'disco_cart_item_price_html', 999, 1 );
52 }
53