-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinit.php
More file actions
267 lines (221 loc) · 9.98 KB
/
Copy pathinit.php
File metadata and controls
267 lines (221 loc) · 9.98 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
<?php
/**
* Plugin Name: Group Product Table Add-Ons for Woo Product Table
* Plugin URI:
* Description: Show grouped products as table using Woo Product Table plugin
* Author: autocircle
* Author URI:
* Text Domain: group-product-table-for-wpt
* Domain Path: /languages/
*
* Version: 1.0.0
* Requires at least: 4.0.0
* Tested up to: 5.4.2
* WC requires at least: 3.7
* WC tested up to: 4.2.2
*/
if ( !defined( 'ABSPATH' ) ) {
die();
}
if ( !defined( 'GPT_WPT_VERSION' ) ) {
define( 'GPT_WPT_VERSION', '1.0.0' );
}
if ( !defined( 'GPT_WPT_NAME' ) ) {
define( 'GPT_WPT_NAME', 'Group Product Table Add-Ons for Woo Product Table' );
}
include_once( ABSPATH . 'wp-admin/includes/plugin.php' );
GPT_WPT::getInstance();
class GPT_WPT {
/**
* Core singleton class
* @var self - pattern realization
*/
private static $_instance;
/**
* table id which we need
*/
private static $_table_id;
/**
* Table id which we need
*/
private static $_is_on;
/**
* Trying to commit and push something
* Minimum PHP Version
*
* @since 1.0.0
*
* @var string Minimum PHP version required to run the plugin.
*/
const MINIMUM_PHP_VERSION = '5.6';
/**
* Create instance
*/
public static function getInstance() {
if (!( self::$_instance instanceof self )) {
self::$_instance = new self();
}
return self::$_instance;
}
public function __construct() {
if ( !is_plugin_active( 'woocommerce/woocommerce.php' ) ) {
add_action( 'admin_notices', [$this, 'admin_notice_missing_main_plugin'] );
return;
}
if ( !is_plugin_active( 'woo-product-table/woo-product-table.php' )) {
add_action( 'admin_notices', [$this, 'admin_notice_missing_main_plugin'] );
return;
}
// Check for required PHP version
if ( version_compare( PHP_VERSION, self::MINIMUM_PHP_VERSION, '<' ) ) {
add_action( 'admin_notices', [ $this, 'admin_notice_minimum_php_version' ] );
return;
}
add_action(
'plugins_loaded',
function () {
load_plugin_textdomain( 'group-product-table-for-wpt', false, dirname( plugin_basename( __FILE__ ) ) . '/languages/' );
});
$this->gpt_wpt_start();
}
/**
* This function starts the main job
*/
public function gpt_wpt_start() {
// Get all the settings from table
$config_value = get_option( 'wpt_configure_options' );
self::$_table_id = isset( $config_value['group_product_table_id'] ) ? $config_value['group_product_table_id'] : false;
self::$_is_on = isset( $config_value['table_on_grouped_product'] ) ? $config_value['table_on_grouped_product'] : false;
// Change the grouped products template location
add_filter( 'woocommerce_locate_template', [$this, 'gpt_wpt_woocommerce_group_locate'], 10, 3 );
// Add admin settings
add_action( 'wpto_admin_configuration_form_top', [$this, 'gpt_wpt_add_admin_settings'], 10, 2 );
}
/**
* This function has used for relocate grouped products template
* with our product table plugin
*
* @param string $template
* @return string $template
*/
public function gpt_wpt_woocommerce_group_locate( $template ) {
$_product = wc_get_product( get_the_ID() );
if( is_singular( 'product' ) && $_product->is_type( 'grouped' ) ){
if(self::$_is_on){
remove_action( 'woocommerce_grouped_add_to_cart', 'woocommerce_grouped_add_to_cart', 30 );
add_action( 'woocommerce_grouped_add_to_cart', [$this, 'gpt_woocommerce_grouped_add_to_cart'], 30 );
}
}
return $template;
}
/**
* Output the grouped product add to cart area.
*/
public function gpt_woocommerce_grouped_add_to_cart() {
add_filter( 'wpto_table_query_args_in_row', [$this, 'gpt_wpt_arg_manipulate'], 10, 2 );
echo do_shortcode("[Product_Table id='". self::$_table_id ."']");
}
/**
* This function adds grouped child products ids to table's main query args
*
* @param array $args
* @param int $table_ID
* @return array $args
*/
public function gpt_wpt_arg_manipulate( $args, $table_ID ){
$product = wc_get_product(get_the_ID());
$children = $product->get_children();
if( $table_ID == self::$_table_id ){
$args['post__in'] = $children;
}
return $args;
}
/**
* Add setting for admin
*/
public function gpt_wpt_add_admin_settings( $settings, $current_config_value ){
?>
<div class="section ultraaddons-panel basic configuration_page">
<h3 class="with-background dark-background">Settings for Grouped Product</h3>
<table class="ultraaddons-table">
<tr class="each-style">
<th><label>Select Table for Grouped Product</label></th>
<td>
<?php
$product_tables = get_posts( array(
'post_type' => 'wpt_product_table',
'numberposts' => -1,
) );
if( !empty( $product_tables )){ ?>
<select name="data[group_product_table_id]" class="wpt_fullwidth ua_input wpt_table_on_archive">
<option value="">Select a Table</option>
<?php
foreach ($product_tables as $table){
$is_archive = isset( $current_config_value['archive_table_id'] ) && $current_config_value['archive_table_id'] == $table->ID ? __('--> currently using for archive', 'group-product-table-for-wpt') : '';
$selected = isset( $current_config_value['group_product_table_id'] ) && $current_config_value['group_product_table_id'] == $table->ID ? 'selected' : '';
echo '<option value="'. $table->ID .'" ' . $selected . '>' . $table->post_title . ' ' . $is_archive . '</option>';
}
?>
</select>
<?php
} else {
echo esc_html( 'Seems you have not created any table yet. Create a table first!', 'wpt_pro' );
} ?>
<br>
<label class="switch">
<input name="data[table_on_grouped_product]" type="checkbox" id="table_on_grouped_product" <?php echo isset( $current_config_value['table_on_grouped_product'] ) ? 'checked="checked"' : ''; ?>>
<div class="slider round">
<span class="on">On</span><span class="off">Off</span><!--END-->
</div>
</label>
<p><?php echo esc_html__( 'Enable Table on Grouped Product Page. First Select a table and check [On] to show.', 'group-product-table-for-wpt' ); ?></p>
<!-- <p class="wpt-tips">
<b><?php // echo esc_html__( 'Tips:', 'group-product-table-for-wpt' ); ?></b>
<span><?php // echo esc_html__( 'Advance Search box is not availeable on WooCommerce Archive page. Such: shop page, product category page.', 'group-product-table-for-wpt' ); ?></span>
</p>-->
</td>
</tr>
</table>
<div class="ultraaddons-button-wrapper">
<button name="configure_submit" class="button-primary primary button">Save All</button>
</div>
</div>
<?php
}
/**
* This function shows the missing plugins notifications
*/
public function admin_notice_missing_main_plugin() {
if (isset($_GET['activate']))
unset($_GET['activate']);
$link = $name = '';
if( !is_plugin_active('woocommerce/woocommerce.php') ){
$link = 'https://wordpress.org/plugins/woocommerce/';
$name = __('WooCommerce', 'group-product-table-for-wpt');
}
if( !is_plugin_active('woo-product-table/woo-product-table.php') ){
$link = 'https://wordpress.org/plugins/woo-product-table/';
$name = __('Woo Product Table', 'group-product-table-for-wpt');
}
$message = sprintf(
esc_html__('"%1$s" requires "%2$s" to be installed and activated.', 'group-product-table-for-wpt'),
'<strong>' . GPT_WPT_NAME . '</strong>',
'<strong><a href="' . esc_url( $link ) . '" target="_blank">' . esc_html( $name ) . '</a></strong>'
);
printf('<div class="notice notice-error is-dismissible"><p>%1$s</p></div>', $message);
}
/**
* This function will show the minimum php version message
*/
public function admin_notice_minimum_php_version() {
if ( isset( $_GET['activate'] ) ) unset( $_GET['activate'] );
$message = sprintf(
/* translators: 1: Plugin name 2: PHP 3: Required PHP version */
esc_html__( '"%1$s" requires "%2$s" version %3$s or greater.', 'fscart' ),
'<strong>' . GPT_WPT_NAME . '</strong>',
'<strong>' . esc_html__( 'PHP', 'fscart' ) . '</strong>',
self::MINIMUM_PHP_VERSION
);
printf( '<div class="notice notice-error is-dismissible"><p>%1$s</p></div>', $message );
}
}