PluginProbe
Ever Compare – Products Compare Plugin for WooCommerce / 1.0.2
Ever Compare – Products Compare Plugin for WooCommerce v1.0.2
1.3.7 1.1.7 1.1.8 1.1.9 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 1.3.0 1.3.1 1.3.2 1.3.3 1.3.4 1.3.5 1.3.6 trunk 1.0.0 1.0.1 1.0.2 All 31 releases
ever-compare / includes / classes / Frontend / Shortcode.php

Shortcode.php in Ever Compare – Products Compare Plugin for WooCommerce 1.0.2, at includes/classes/Frontend/Shortcode.php

105 lines 3.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 namespace EverCompare\Frontend;
3 /**
4 * Shortcode handler class
5 */
6 class Shortcode {
7
8 /**
9 * [$_instance]
10 * @var null
11 */
12 private static $_instance = null;
13
14 /**
15 * [instance] Initializes a singleton instance
16 * @return [Base]
17 */
18 public static function instance() {
19 if ( is_null( self::$_instance ) ) {
20 self::$_instance = new self();
21 }
22 return self::$_instance;
23 }
24
25 /**
26 * Initializes the class
27 */
28 function __construct() {
29 add_shortcode( 'evercompare_button', [ $this, 'button_shortcode' ] );
30 add_shortcode( 'evercompare_table', [ $this, 'table_shortcode' ] );
31 }
32
33 /**
34 * [button_shortcode] Compare Button Shortcode callable function
35 * @param [type] $atts
36 * @param string $content
37 * @return [HTML]
38 */
39 public function button_shortcode( $atts, $content = '' ){
40 wp_enqueue_style( 'evercompare-frontend' );
41 wp_enqueue_script( 'evercompare-frontend' );
42
43 global $product;
44
45 // Fetch option data
46 $button_text = ever_compare_get_option( 'button_text','ever_compare_table_settings_tabs', 'Compare' );
47 $button_added_text = ever_compare_get_option( 'added_button_text','ever_compare_table_settings_tabs', 'Added' );
48
49 $button_class = array(
50 'htcompare-btn',
51 'button',
52 );
53
54 // Shortcode atts
55 $default_atts = array(
56 'product_id' => $product->get_id(),
57 'button_url' => Manage_Compare::instance()->get_compare_page_url(),
58 'button_class' => implode(' ', $button_class ),
59 'button_text' => $button_text,
60 'button_added_text' => $button_added_text,
61 'template_name' => 'add',
62 );
63
64 $atts = shortcode_atts( $default_atts, $atts, $content );
65 return Manage_Compare::instance()->button_html( $atts );
66
67 }
68
69 /**
70 * [table_shortcode] Compare table shortcode callable function
71 * @param [type] $atts
72 * @param string $content
73 * @return [HTML]
74 */
75 public function table_shortcode( $atts, $content = '' ){
76 wp_enqueue_style( 'evercompare-frontend' );
77 wp_enqueue_script( 'evercompare-frontend' );
78
79 /* Fetch From option data */
80 $empty_compare_text = ever_compare_get_option('empty_table_text','ever_compare_table_settings_tabs');
81 $return_shop_button = ever_compare_get_option('shop_button_text','ever_compare_table_settings_tabs','Return to shop');
82
83 /* Product and Field */
84 $products = Manage_Compare::instance()->get_compared_products_data();
85 $fields = Manage_Compare::instance()->get_compare_fields();
86
87 $custom_heading = !empty( ever_compare_get_option( 'table_heading', 'ever_compare_table_settings_tabs' ) ) ? ever_compare_get_option( 'table_heading', 'ever_compare_table_settings_tabs' ) : array();
88
89 $default_atts = array(
90 'evercompare' => Manage_Compare::instance(),
91 'products' => $products,
92 'fields' => $fields,
93 'return_shop_button'=> $return_shop_button,
94 'heading_txt' => $custom_heading,
95 'empty_compare_text'=> $empty_compare_text,
96 );
97
98 $atts = shortcode_atts( $default_atts, $atts, $content );
99 return Manage_Compare::instance()->table_html( $atts );
100
101 }
102
103
104 }
105