| 1 |
<?php |
| 2 |
/** |
| 3 |
* Module: Drawer. |
| 4 |
* |
| 5 |
* @package Orderable/Classes |
| 6 |
*/ |
| 7 |
|
| 8 |
defined( 'ABSPATH' ) || exit; |
| 9 |
|
| 10 |
/** |
| 11 |
* Drawer module class. |
| 12 |
*/ |
| 13 |
class Orderable_Drawer { |
| 14 |
/** |
| 15 |
* Init. |
| 16 |
*/ |
| 17 |
public static function run() { |
| 18 |
self::load_classes(); |
| 19 |
|
| 20 |
add_action( 'wp_footer', array( __CLASS__, 'add' ) ); |
| 21 |
add_filter( 'woocommerce_add_to_cart_fragments', array( __CLASS__, 'cart_count_fragments' ), 10, 1 ); |
| 22 |
add_filter( 'woocommerce_cart_item_permalink', '__return_false' ); |
| 23 |
add_filter( 'wc_get_template', array( __CLASS__, 'mini_cart_template' ), 100, 5 ); |
| 24 |
} |
| 25 |
|
| 26 |
/** |
| 27 |
* Load classes for this module. |
| 28 |
*/ |
| 29 |
public static function load_classes() { |
| 30 |
$classes = array( |
| 31 |
'drawer-settings' => 'Orderable_Drawer_Settings', |
| 32 |
'drawer-ajax' => 'Orderable_Drawer_Ajax', |
| 33 |
); |
| 34 |
|
| 35 |
foreach ( $classes as $file_name => $class_name ) { |
| 36 |
require_once ORDERABLE_MODULES_PATH . 'drawer/class-' . $file_name . '.php'; |
| 37 |
|
| 38 |
$class_name::run(); |
| 39 |
} |
| 40 |
} |
| 41 |
|
| 42 |
/** |
| 43 |
* Add drawer and overlay. |
| 44 |
*/ |
| 45 |
public static function add() { |
| 46 |
if ( is_admin() || is_cart() || is_checkout() ) { |
| 47 |
return; |
| 48 |
} |
| 49 |
|
| 50 |
include ORDERABLE_MODULES_PATH . 'drawer/templates/overlay.php'; |
| 51 |
include ORDERABLE_MODULES_PATH . 'drawer/templates/drawer.php'; |
| 52 |
include ORDERABLE_MODULES_PATH . 'drawer/templates/floating-cart.php'; |
| 53 |
} |
| 54 |
|
| 55 |
/** |
| 56 |
* Update cart count after adding to cart. |
| 57 |
* |
| 58 |
* @param array $fragments Array of HTML fragments. |
| 59 |
* |
| 60 |
* @return mixed |
| 61 |
*/ |
| 62 |
public static function cart_count_fragments( $fragments ) { |
| 63 |
ob_start(); |
| 64 |
|
| 65 |
include ORDERABLE_MODULES_PATH . 'drawer/templates/floating-cart.php'; |
| 66 |
|
| 67 |
$fragments['.orderable-floating-cart'] = ob_get_clean(); |
| 68 |
|
| 69 |
return $fragments; |
| 70 |
} |
| 71 |
|
| 72 |
/** |
| 73 |
* Replace mini cart template. |
| 74 |
* |
| 75 |
* @param string $template |
| 76 |
* @param string $template_name |
| 77 |
* @param array $args |
| 78 |
* @param string $template_path |
| 79 |
* @param string $default_path |
| 80 |
* |
| 81 |
* @return string |
| 82 |
*/ |
| 83 |
public static function mini_cart_template( $template, $template_name, $args, $template_path, $default_path ) { |
| 84 |
if ( 'cart/mini-cart.php' !== $template_name ) { |
| 85 |
return $template; |
| 86 |
} |
| 87 |
|
| 88 |
return ORDERABLE_PATH . 'woocommerce/cart/mini-cart.php'; |
| 89 |
} |
| 90 |
} |