| 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 |
|