modules
1 year ago
skins
1 year ago
template-blocks
1 year ago
templates
1 year ago
widgets
1 year ago
module.php
1 year ago
module.php
159 lines
| 1 | <?php |
| 2 | /** |
| 3 | * Class: Module |
| 4 | * Name: Woocommerce |
| 5 | * Slug: premium-woocommerce |
| 6 | * PA WooCommerce Module. |
| 7 | * |
| 8 | * @package PA |
| 9 | */ |
| 10 | |
| 11 | namespace PremiumAddons\Modules\Woocommerce; |
| 12 | |
| 13 | use PremiumAddons\Admin\Includes\Admin_Helper; |
| 14 | use PremiumAddons\Includes\Module_Base; |
| 15 | use PremiumAddons\Modules\Woocommerce\Modules\Products_Module; |
| 16 | use PremiumAddons\Modules\Woocommerce\Modules\CTA_Module; |
| 17 | use PremiumAddons\Modules\Woocommerce\Modules\categories_Module; |
| 18 | use PremiumAddons\Modules\Woocommerce\Modules\Mini_Cart_Module; |
| 19 | |
| 20 | if ( ! defined( 'ABSPATH' ) ) { |
| 21 | exit; // If this file is called directly, abort. |
| 22 | } |
| 23 | |
| 24 | /** |
| 25 | * Class Module. |
| 26 | */ |
| 27 | class Module extends Module_Base { |
| 28 | |
| 29 | /** |
| 30 | * Class object |
| 31 | * |
| 32 | * @var instance |
| 33 | */ |
| 34 | private static $instance = null; |
| 35 | |
| 36 | /** |
| 37 | * Module should load or not. |
| 38 | * |
| 39 | * @since 4.7.0 |
| 40 | * @access public |
| 41 | * |
| 42 | * @return bool true|false. |
| 43 | */ |
| 44 | public static function is_enable() { |
| 45 | return true; |
| 46 | } |
| 47 | |
| 48 | /** |
| 49 | * Get Module Name. |
| 50 | * |
| 51 | * @since 4.7.0 |
| 52 | * @access public |
| 53 | * |
| 54 | * @return string Module name. |
| 55 | */ |
| 56 | public function get_name() { |
| 57 | return 'woocommerce'; |
| 58 | } |
| 59 | |
| 60 | /** |
| 61 | * Get Widgets. |
| 62 | * |
| 63 | * @since 4.7.0 |
| 64 | * @access public |
| 65 | * |
| 66 | * @return array Widgets. |
| 67 | */ |
| 68 | public function get_widgets() { |
| 69 | return array( |
| 70 | 'Woo_Products', |
| 71 | 'Woo_Categories', |
| 72 | 'Mini_Cart', |
| 73 | 'Woo_CTA', |
| 74 | ); |
| 75 | } |
| 76 | |
| 77 | /** |
| 78 | * Constructor. |
| 79 | */ |
| 80 | public function __construct() { |
| 81 | parent::__construct(); |
| 82 | |
| 83 | // Load individual widget modules. |
| 84 | $this->load_modules(); |
| 85 | } |
| 86 | |
| 87 | /** |
| 88 | * Override Woocommerce default mini cart template. |
| 89 | * |
| 90 | * @param string $template_name Template name. |
| 91 | * @param string $template_path Template path. (default: ''). |
| 92 | * @param string $default_path Default path. (default: ''). |
| 93 | * @see https://woocommerce.github.io/code-reference/files/woocommerce-includes-wc-core-functions.html#source-view.381 |
| 94 | * @return string |
| 95 | */ |
| 96 | public function pa_locate_custom_mini_cart_template( $template, $template_name, $template_path ) { |
| 97 | |
| 98 | if ( 'cart/mini-cart.php' !== $template_name ) { |
| 99 | return $template; |
| 100 | } |
| 101 | |
| 102 | $plugin_path = plugin_dir_path( __DIR__ ) . 'woocommerce/templates/wc-templates/'; |
| 103 | |
| 104 | if ( file_exists( $plugin_path . 'mini-cart.php' ) ) { |
| 105 | $template = $plugin_path . 'mini-cart.php'; |
| 106 | } |
| 107 | |
| 108 | return $template; |
| 109 | } |
| 110 | |
| 111 | |
| 112 | /** |
| 113 | * Load individual widget modules. |
| 114 | * |
| 115 | * @since 4.7.0 |
| 116 | * @access public |
| 117 | */ |
| 118 | public function load_modules() { |
| 119 | |
| 120 | $enabled_elements = Admin_Helper::get_enabled_elements(); |
| 121 | |
| 122 | if ( isset( $enabled_elements['woo-products'] ) && $enabled_elements['woo-products'] ) { |
| 123 | Products_Module::get_instance(); |
| 124 | } |
| 125 | |
| 126 | if ( isset( $enabled_elements['woo-cta'] ) && $enabled_elements['woo-cta'] ) { |
| 127 | CTA_Module::get_instance(); |
| 128 | } |
| 129 | |
| 130 | if ( isset( $enabled_elements['woo-categories'] ) && $enabled_elements['woo-categories'] ) { |
| 131 | Categories_Module::get_instance(); |
| 132 | } |
| 133 | |
| 134 | $mc_custom_temp_enabled = isset( $enabled_elements['pa_mc_temp'] ) ? $enabled_elements['pa_mc_temp'] : false; |
| 135 | |
| 136 | if ( isset( $enabled_elements['mini-cart'] ) && $enabled_elements['mini-cart'] ) { |
| 137 | |
| 138 | if ( $mc_custom_temp_enabled ) { |
| 139 | add_filter( 'woocommerce_locate_template', array( $this, 'pa_locate_custom_mini_cart_template' ), 10, 3 ); |
| 140 | } |
| 141 | |
| 142 | Mini_Cart_Module::get_instance(); |
| 143 | } |
| 144 | } |
| 145 | |
| 146 | /** |
| 147 | * Instance |
| 148 | * |
| 149 | * @return object self::$instance |
| 150 | */ |
| 151 | public static function get_instance() { |
| 152 | if ( is_null( self::$instance ) ) { |
| 153 | self::$instance = new self(); |
| 154 | } |
| 155 | |
| 156 | return self::$instance; |
| 157 | } |
| 158 | } |
| 159 |