PluginProbe
Product Labels, Quick View, Buy Now, Pre-Orders, Frequently Bought Together & More for WooCommerce – Merchant / 1.8.1
Product Labels, Quick View, Buy Now, Pre-Orders, Frequently Bought Together & More for WooCommerce – Merchant v1.8.1
2.3.2 2.3.1 2.3.0 2.2.8 2.2.7 trunk 1.10.0 1.10.1 1.10.2 1.10.3 1.10.4 1.10.5 1.11.0 1.11.1 1.11.2 1.6 1.7 1.8 1.8.1 1.8.2 1.8.3 1.9.0 1.9.1 1.9.10 1.9.11 All 60 releases
merchant / inc / functions.php

functions.php in Product Labels, Quick View, Buy Now, Pre-Orders, Frequently Bought Together & More for WooCommerce – Merchant 1.8.1, at inc/functions.php

135 lines 3.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 /**
4 * Essential functions.
5 *
6 * @package Merchant
7 */
8
9 if ( ! defined( 'ABSPATH' ) ) {
10 exit; // Exit if accessed directly
11 }
12
13 /**
14 * Get template part.
15 *
16 */
17 function merchant_get_template_part( $folder_path = '', $name = '', $args = array(), $return_results = false ) {
18 if ( ! empty( $args ) && is_array( $args ) ) {
19 extract( $args );
20 }
21
22 $folder_path = ! empty( $folder_path ) ? "/$folder_path/" : '';
23
24 $template = '';
25
26 // Look in yourtheme/merchant/folder-path/name.php and yourtheme/merchant/folder-path/name.php.
27 if ( $name ) {
28 $template = locate_template( array( "merchant{$folder_path}{$name}.php" ) );
29 }
30
31 // Get default.
32 if ( ! $template && $name ) {
33 // Try to get it from the PRO dir if it exists.
34 if ( defined( 'MERCHANT_PRO_DIR' ) && file_exists( MERCHANT_PRO_DIR . "templates{$folder_path}{$name}.php" ) ) {
35 $template = MERCHANT_PRO_DIR . "templates{$folder_path}{$name}.php";
36 // Otherwise take it from the base dir.
37 } elseif ( file_exists( MERCHANT_DIR . "templates{$folder_path}{$name}.php" ) ) {
38 $template = MERCHANT_DIR . "templates{$folder_path}{$name}.php";
39 }
40 }
41
42 /**
43 * Hook: 'merchant_get_template_part'
44 *
45 * @since 1.0
46 */
47 $template = apply_filters( 'merchant_get_template_part', $template, $folder_path, $name );
48
49
50 if ( $template ) {
51 // Whether to return template HTML as string or to echo it
52 if ( $return_results ) {
53 ob_start();
54 include( $template );
55
56 return ob_get_clean();
57 }
58
59 return include( $template );
60 }
61 }
62
63 /**
64 * Check if Botiga theme is installed and active.
65 *
66 * @return bool
67 */
68 if ( ! function_exists( 'merchant_is_botiga_active' ) ) {
69 function merchant_is_botiga_active() {
70 return defined( 'BOTIGA_VERSION' );
71 }
72 }
73
74 /**
75 * Check if Kadence theme is installed and active.
76 *
77 * @return bool
78 */
79 if ( ! function_exists( 'merchant_is_kadence_active' ) ) {
80 function merchant_is_kadence_active() {
81 return class_exists( '\Kadence\Theme' );
82 }
83 }
84
85 /**
86 * Check if OceanWP theme is installed and active.
87 *
88 * @return bool
89 */
90 if ( ! function_exists( 'merchant_is_oceanwp_active' ) ) {
91 function merchant_is_oceanwp_active() {
92 return class_exists( 'OCEANWP_Theme_Class' );
93 }
94 }
95
96 /**
97 * Check if any shortcode starts with merchant.
98 * If the shortcode is not registered, register it with return null to guarantee it exists.
99 */
100 if ( ! function_exists( 'merchant_modules_shortcode_exists' ) ) {
101 function merchant_modules_shortcode_exists() {
102 /**
103 * Filter the shortcodes.
104 *
105 * @param array $shortcodes modules shortcodes
106 *
107 * @since 1.8
108 */
109 $shortcodes = apply_filters( 'merchant_modules_shortcodes',
110 array(
111 'merchant_module_stock_scarcity',
112 'merchant_module_wait_list',
113 'merchant_module_volume_discounts',
114 'merchant_module_payment_logos',
115 'merchant_module_cart_reserved_timer',
116 'merchant_module_product_brand_image',
117 'merchant_module_size_chart',
118 'merchant_module_reasons_to_buy',
119 'merchant_module_recently_viewed_products',
120 'merchant_module_trust_badges',
121 'merchant_module_advanced_reviews',
122 'merchant_module_frequency_bought_together',
123 'merchant_module_buy_x_get_y',
124 )
125 );
126
127 // Loop through the shortcodes and register them if they don't exist.
128 array_map( static function ( $shortcode ) {
129 if ( ! shortcode_exists( $shortcode ) ) {
130 add_shortcode( $shortcode, '__return_null' );
131 }
132 }, $shortcodes );
133 }
134 }
135 add_action( 'init', 'merchant_modules_shortcode_exists' );