PluginProbe
Swatchly – Product Variation Swatches for WooCommerce / trunk
Swatchly – Product Variation Swatches for WooCommerce vtrunk
1.4.16 1.4.15 1.4.14 trunk 1.0.5 1.0.7 1.0.9 1.1.0 1.1.1 1.1.2 1.1.4 1.1.5 1.1.6 1.1.7 1.1.8 1.2.0 1.2.1 1.2.2 1.2.3 1.2.4 1.2.5 1.2.6 1.2.7 1.2.8 1.2.9 All 49 releases
swatchly / includes / Frontend.php

Frontend.php in Swatchly – Product Variation Swatches for WooCommerce trunk, at includes/Frontend.php

137 lines 6.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 namespace Swatchly;
3
4 /**
5 * Frontend class.
6 */
7 class Frontend {
8
9 public $version = '';
10
11 /**
12 * Constructor.
13 */
14 public function __construct() {
15 // Set time as the version for development mode.
16 if( defined('WP_DEBUG') && WP_DEBUG ){
17 $this->version = time();
18 } else {
19 $this->version = SWATCHLY_VERSION;
20 }
21 // frontend assets
22 add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_frontend_assets' ) );
23
24 // generate blank notice wrapper for ajax add to cart
25 if(swatchly_get_option('enable_swatches', null, 'pl')){
26 add_action('wp_footer', array( $this, 'popup_notice_blank_div') );
27 }
28
29 // add body class
30 add_filter( 'body_class', array( $this, 'custom_body_class') );
31 }
32
33 /**
34 * Detect if Oxygen Builder is active
35 *
36 * @return bool
37 */
38 private function is_oxygen_builder_active() {
39 return defined( 'CT_VERSION' ) || class_exists( 'CT_Component' );
40 }
41
42 /**
43 * Enqueue frontend assets
44 */
45 public function enqueue_frontend_assets() {
46 // Thickbox.
47 add_thickbox();
48
49 wp_register_style( 'swatchly-frontend', SWATCHLY_ASSETS . '/css/frontend.css', array(), $this->version );
50 wp_register_script( 'swatchly-frontend', SWATCHLY_ASSETS . '/js/frontend.js', array('jquery'), $this->version, true );
51
52 $enable_swatches = swatchly_get_option('enable_swatches', null, 'pl');
53
54 if( is_product() ){
55 $enable_swatches = swatchly_get_option('enable_swatches', null, 'sp');
56 }
57
58 if($enable_swatches){
59 wp_enqueue_style( 'swatchly-frontend' );
60 wp_enqueue_script( 'swatchly-frontend' );
61 }
62
63 $enable_swatches = swatchly_get_option('enable_swatches', null, 'pl');
64 $auto_convert_dropdowns_to_label = swatchly_get_option('auto_convert_dropdowns_to_label', null, 'pl');
65 $tooltip = swatchly_get_option('tooltip', null, 'pl');
66 $deselect_on_click = swatchly_get_option('deselect_on_click', null, 'pl');
67 $show_selected_attribute_name = swatchly_get_option('show_selected_attribute_name', null, 'pl');
68 $enable_out_of_stock_swatch_selection = swatchly_get_option('enable_out_of_stock_swatch_selection', null, 'pl');
69 $variation_label_separator = swatchly_get_option('variation_label_separator', null, 'pl');
70 $product_thumbnail_selector = swatchly_get_option('pl_product_thumbnail_selector');
71 $hide_wc_forward_button = swatchly_get_option('pl_hide_wc_forward_button');
72 $enable_cart_popup_notice = swatchly_get_option('pl_enable_cart_popup_notice');
73 $sp_override_global = swatchly_get_option('sp_override_global');
74 $pl_override_global = swatchly_get_option('pl_override_global');
75 $enable_variation_url = swatchly_get_option('variation_url');
76 $enable_rv_variations = swatchly_get_option('recently_viewed_variations');
77 $enable_pl_variation_url = swatchly_get_option('pl_variation_url');
78 $enable_pl_rv_variations = swatchly_get_option('pl_recently_viewed_variations');
79 $enable_sp_variation_url = swatchly_get_option('sp_variation_url');
80 $enable_sp_rv_variations = swatchly_get_option('sp_recently_viewed_variations');
81
82 $variation_label_separator = swatchly_get_option('sp_variation_label_separator');
83 if(is_product()){
84 $enable_swatches = swatchly_get_option('enable_swatches', null, 'sp');
85 $auto_convert_dropdowns_to_label = swatchly_get_option('auto_convert_dropdowns_to_label', null, 'sp');
86 $tooltip = swatchly_get_option('tooltip', null, 'sp');
87 $deselect_on_click = swatchly_get_option('deselect_on_click', null, 'sp');
88 $show_selected_attribute_name = swatchly_get_option('show_selected_attribute_name', null, 'sp');
89 $enable_out_of_stock_swatch_selection = swatchly_get_option('enable_out_of_stock_swatch_selection', null, 'sp');
90 }
91
92 $localize_vars = array(
93 'is_product' => is_product(),
94 'enable_swatches' => $enable_swatches,
95 'auto_convert_dropdowns_to_label' => $auto_convert_dropdowns_to_label,
96 'tooltip' => $tooltip,
97 'deselect_on_click' => $deselect_on_click,
98 'show_selected_attribute_name' => $show_selected_attribute_name,
99 'enable_out_of_stock_swatch_selection' => $enable_out_of_stock_swatch_selection,
100 'variation_label_separator' => $variation_label_separator,
101 'product_thumbnail_selector' => $product_thumbnail_selector,
102 'hide_wc_forward_button' => $hide_wc_forward_button,
103 'enable_cart_popup_notice' => $enable_cart_popup_notice,
104 'sp_override_global' => $sp_override_global,
105 'pl_override_global' => $pl_override_global,
106 'enable_variation_url' => $enable_variation_url,
107 'enable_rv_variations' => $enable_rv_variations,
108 'enable_pl_variation_url' => $enable_pl_variation_url,
109 'enable_pl_rv_variations' => $enable_pl_rv_variations,
110 'enable_sp_variation_url' => $enable_sp_variation_url,
111 'enable_sp_rv_variations' => $enable_sp_rv_variations,
112 'is_oxygen_builder' => $this->is_oxygen_builder_active(),
113 );
114 wp_localize_script( 'swatchly-frontend', 'swatchly_params', $localize_vars );
115 }
116
117 /**
118 * Add custom body class
119 */
120 function custom_body_class( $classes ) {
121 $show_swatches_label = swatchly_get_option('pl_show_swatches_label');
122 if(!is_product() && $show_swatches_label){
123 $classes[] = 'pl_show_swatches_label_'. $show_swatches_label;
124 }
125
126 return $classes;
127 }
128
129 /**
130 * Ajax add to cart notice div
131 */
132 public function popup_notice_blank_div(){
133 ?>
134 <div id="swatchly_notice_popup" style="display:none;"></div>
135 <?php
136 }
137 }