| 1 |
<?php |
| 2 |
|
| 3 |
namespace UltimateStoreKit\Modules\MiniCart; |
| 4 |
|
| 5 |
use UltimateStoreKit\Base\Ultimate_Store_Kit_Module_Base; |
| 6 |
|
| 7 |
if (!defined('ABSPATH')) exit; // Exit if accessed directly |
| 8 |
|
| 9 |
class Module extends Ultimate_Store_Kit_Module_Base { |
| 10 |
|
| 11 |
|
| 12 |
const TEMPLATE_MINI_CART = 'cart/mini-cart.php'; |
| 13 |
const OPTION_NAME_USE_MINI_CART = 'use_mini_cart_template'; |
| 14 |
|
| 15 |
public function __construct() { |
| 16 |
|
| 17 |
parent::__construct(); |
| 18 |
|
| 19 |
wp_enqueue_script( 'wc-cart-fragments' ); |
| 20 |
|
| 21 |
// add_filter('woocommerce_add_to_cart_fragments', [$this, 'ultimate_store_kit_mini_cart_fragment']); |
| 22 |
// add_filter('woocommerce_locate_template', [$this, 'woocommerce_locate_template'], 12, 3); |
| 23 |
} |
| 24 |
|
| 25 |
public function render_markup() { |
| 26 |
?> |
| 27 |
<div class="toolset"> |
| 28 |
<div class="ts-container"> |
| 29 |
<div class="ts-nav-container"></div> |
| 30 |
<div class="ts-content-container"> |
| 31 |
<div id="first" class="ts-content-item"> |
| 32 |
<div class="widget_shopping_cart_content"></div> |
| 33 |
</div> |
| 34 |
</div> |
| 35 |
</div> |
| 36 |
</div> |
| 37 |
<?php |
| 38 |
} |
| 39 |
|
| 40 |
public function get_name() { |
| 41 |
return 'usk-mini-cart'; |
| 42 |
} |
| 43 |
|
| 44 |
public function get_widgets() { |
| 45 |
|
| 46 |
$widgets = ['Mini_Cart']; |
| 47 |
|
| 48 |
return $widgets; |
| 49 |
} |
| 50 |
|
| 51 |
public function woocommerce_locate_template($template, $template_name, $template_path) { |
| 52 |
|
| 53 |
if (self::TEMPLATE_MINI_CART !== $template_name) { |
| 54 |
return $template; |
| 55 |
} |
| 56 |
|
| 57 |
$plugin_path = BDTUSK_MODULES_PATH . 'mini-cart/templates/'; |
| 58 |
|
| 59 |
if (file_exists($plugin_path . $template_name)) { |
| 60 |
$template = $plugin_path . $template_name; |
| 61 |
} |
| 62 |
|
| 63 |
// if(class_exists('\UltimateStoreKit\Modules\MiniCart\Templates\Cart\Mini_Cart')) { |
| 64 |
// unset($template['cart/mini-cart.php']); |
| 65 |
// } |
| 66 |
|
| 67 |
return $template; |
| 68 |
} |
| 69 |
|
| 70 |
public function ultimate_store_kit_mini_cart_fragment($fragments) { |
| 71 |
global $woocommerce; |
| 72 |
|
| 73 |
ob_start(); |
| 74 |
|
| 75 |
?> |
| 76 |
<span class="bdt-mini-cart-inner"> |
| 77 |
<span class="bdt-cart-button-text"> |
| 78 |
<span class="bdt-mini-cart-price-amount"> |
| 79 |
<?php echo WC()->cart->get_cart_subtotal(); ?> |
| 80 |
</span> |
| 81 |
</span> |
| 82 |
<span class="bdt-mini-cart-button-icon"> |
| 83 |
<span class="bdt-cart-badge"> |
| 84 |
<?php echo WC()->cart->get_cart_contents_count(); ?> |
| 85 |
</span> |
| 86 |
<span class="bdt-cart-icon"> |
| 87 |
<i class="eicon" aria-hidden="true"></i> |
| 88 |
</span> |
| 89 |
</span> |
| 90 |
</span> |
| 91 |
|
| 92 |
<?php |
| 93 |
$fragments['a.bdt-mini-cart-button .bdt-mini-cart-inner'] = ob_get_clean(); |
| 94 |
|
| 95 |
return $fragments; |
| 96 |
} |
| 97 |
} |
| 98 |
|