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