-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfunctions.php
464 lines (379 loc) · 14.2 KB
/
functions.php
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
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
<?php
// =============================================================================
// FUNCTIONS.PHP
// -----------------------------------------------------------------------------
// Overwrite or add your own custom functions to X in this file.
// =============================================================================
// =============================================================================
// TABLE OF CONTENTS
// -----------------------------------------------------------------------------
// 01. Enqueue Parent Stylesheet
// 02. Additional Functions
// =============================================================================
// Enqueue Parent Stylesheet
// =============================================================================
add_filter( 'x_enqueue_parent_stylesheet', '__return_true' );
// Additional Functions
// =============================================================================
add_filter( 'gform_enable_field_label_visibility_settings', '__return_true' );
// Do Not Remove Woocommerce Plugin Settings
// =============================================================================
function x_woocommerce_donot_remove_plugin_setting(){
if ( ! is_admin() ) {
return;
}
remove_filter( 'woocommerce_product_settings', 'x_woocommerce_remove_plugin_settings', 10 );
}
add_action('init', 'x_woocommerce_donot_remove_plugin_setting');
// Add classes to main categories
function wc_product_cat_class_mainCat( $class = '', $category = null ) {
// Count Categories
$args = array(
'taxonomy' => 'product_cat',
'parent' => 0,
'number' => 10,
'hide_empty' => 1
);
$categories = get_terms( $args );
$main_cat_number = count( $categories );
$cat_column_number = floor(100 / $main_cat_number);
// Separates classes with a single space, collates classes for post DIV
echo 'class="' . 'cat-menu-col-' . $cat_column_number . ' ' . esc_attr( join( ' ', wc_get_product_cat_class( $class, $category ) ) ) . '"';
}
// Add classes to sub categories
function wc_product_cat_class_subCat( $class = '', $category = null ) {
// Find the category + category parent, if applicable
$term = get_queried_object();
$parent_id = empty( $term->term_id ) ? 0 : $term->term_id;
$grand_parent_id = $term->parent;
// Count Categories
$args = array(
'taxonomy' => 'product_cat',
'parent' => $parent_id,
'number' => 10,
'hide_empty' => 1
);
$categories = get_terms( $args );
$main_cat_number = count( $categories );
// Check if is last child
if ( $main_cat_number == 0 ) {
$args = array(
'taxonomy' => 'product_cat',
'parent' => $grand_parent_id,
'number' => 10,
'hide_empty' => 1
);
$categories = get_terms( $args );
$main_cat_number = count( $categories );
$cat_column_number = floor(100 / $main_cat_number);
// Separates classes with a single space, collates classes for post DIV
echo 'class="' . 'cat-menu-col-' . $cat_column_number . ' ' . esc_attr( join( ' ', wc_get_product_cat_class( $class, $category ) ) ) . '"';
} else {
$cat_column_number = floor(100 / $main_cat_number);
// Separates classes with a single space, collates classes for post DIV
echo 'class="' . 'cat-menu-col-' . $cat_column_number . ' ' . esc_attr( join( ' ', wc_get_product_cat_class( $class, $category ) ) ) . '"';
}
}
// Edit woocommerce content
if ( ! function_exists( 'woocommerce_content_new' ) ) {
/**
* Output WooCommerce content.
*
* This function is only used in the optional 'woocommerce.php' template.
* which people can add to their themes to add basic woocommerce support.
* without hooks or modifying core templates.
*
*/
function woocommerce_content_new() {
if ( is_singular( 'product' ) ) {
while ( have_posts() ) : the_post();
wc_get_template_part( 'content', 'single-product' );
endwhile;
} else { ?>
<?php if (is_shop()) { ?>
<div class="x-section bg-image" style="margin: 0px;padding: 260px 0px 50px; background-image: url(/wp-content/uploads/2016/08/3108547829_e6d0f5e37b_b.jpg); background-color: transparent;">
<div class="x-container max width" style="margin: 0px auto;padding: 0px;">
<div class="x-column x-sm x-1-1" style="padding: 0px;">
<div class="x-text cs-ta-right">
<h1 class="page-title"><?php woocommerce_page_title(); ?></h1>
</div>
</div>
</div>
</div>
<?php
}
?>
<?php if ( have_posts() ) : ?>
<?php do_action('woocommerce_before_shop_loop'); ?>
<div class="nav-categories">
<?php woocommerce_product_subcategories_new(); ?>
</div>
<hr class="x-clear">
<div class="x-container max width">
<?php elseif ( ! woocommerce_product_subcategories_new( array( 'before' => woocommerce_product_loop_start( false ), 'after' => woocommerce_product_loop_end( false ) ) ) ) : ?>
<?php wc_get_template( 'loop/no-products-found.php' ); ?>
<?php endif; ?>
<?php do_action( 'woocommerce_archive_description' );?>
<?php woocommerce_product_loop_start(); ?>
<?php while ( have_posts() ) : the_post(); ?>
<?php wc_get_template_part( 'content', 'product' ); ?>
<?php endwhile; // end of the loop. ?>
</div>
<?php woocommerce_product_loop_end(); ?>
<?php do_action('woocommerce_after_shop_loop'); ?>
<?php
}
}
}
// Edit woocommerce_product_subcategories_new
if ( ! function_exists( 'woocommerce_product_subcategories_new' ) ) {
/**
* Display product sub categories as thumbnails.
*
* @subpackage Loop
* @param array $args
* @return null|boolean
*/
function woocommerce_product_subcategories_new( $args = array() ) {
global $wp_query;
$defaults = array(
'before' => '',
'after' => '',
'force_display' => false
);
$args = wp_parse_args( $args, $defaults );
extract( $args );
// Main query only
if ( ! is_main_query() && ! $force_display ) {
return;
}
// Don't show when filtering, searching or when on page > 1 and ensure we're on a product archive
if ( is_search() || is_filtered() || is_paged() || ( ! is_product_category() && ! is_shop() ) ) {
return;
}
// Check categories are enabled
if ( is_shop() && '' === get_option( 'woocommerce_shop_page_display' ) ) {
return;
}
// Find the category + category parent, if applicable
$term = get_queried_object();
$parent_id = empty( $term->term_id ) ? 0 : $term->term_id;
if ( is_product_category() ) {
$display_type = get_woocommerce_term_meta( $term->term_id, 'display_type', true );
switch ( $display_type ) {
case 'products' :
return;
break;
case '' :
if ( '' === get_option( 'woocommerce_category_archive_display' ) ) {
return;
}
break;
}
}
// NOTE: using child_of instead of parent - this is not ideal but due to a WP bug ( https://core.trac.wordpress.org/ticket/15626 ) pad_counts won't work
$product_categories = get_categories( apply_filters( 'woocommerce_product_subcategories_new_args', array(
'parent' => $parent_id,
'menu_order' => 'ASC',
'hide_empty' => 1,
'hierarchical' => 1,
'taxonomy' => 'product_cat',
'pad_counts' => 1
) ) );
if ( empty($product_categories) ) {
$category = get_queried_object();
$current = $category->term_id;
$parent = $term->parent;
$product_categories = get_categories( apply_filters( 'woocommerce_product_subcategories_new_args', array(
'parent' => $parent,
'menu_order' => 'ASC',
'hide_empty' => 1,
'hierarchical' => 1,
'taxonomy' => 'product_cat',
'pad_counts' => 1
) ) );
}
if ( ! apply_filters( 'woocommerce_product_subcategories_new_hide_empty', false ) ) {
$product_categories = wp_list_filter( $product_categories, array( 'count' => 0 ), 'NOT' );
}
if ( $product_categories ) {
echo $before;
if ($parent_id == 0) {
foreach ( $product_categories as $category ) {
wc_get_template( 'content-product_cat_main.php', array(
'category' => $category
) );
}
}else {
foreach ( $product_categories as $category ) {
wc_get_template( 'content-product_cat_sub.php', array(
'category' => $category
) );
}
}
// If we are hiding products disable the loop and pagination
if ( is_product_category() ) {
$display_type = get_woocommerce_term_meta( $term->term_id, 'display_type', true );
update_option( 'woocommerce_category_archive_display', 'both' );
switch ( $display_type ) {
case 'subcategories' :
$wp_query->post_count = 0;
$wp_query->max_num_pages = 0;
break;
case '' :
if ( 'subcategories' === get_option( 'woocommerce_category_archive_display' ) ) {
$wp_query->post_count = 0;
$wp_query->max_num_pages = 0;
}
break;
}
}
if ( is_shop() && 'subcategories' === get_option( 'woocommerce_shop_page_display' ) ) {
$wp_query->post_count = 0;
$wp_query->max_num_pages = 0;
}
echo $after;
return true;
}
}
}
// Add category image
add_action( 'woocommerce_before_shop_loop', 'woocommerce_category_image', 2 );
function woocommerce_category_image() {
if ( is_product_category() ){
global $wp_query;
$cat = $wp_query->get_queried_object();
$thumbnail_id = get_woocommerce_term_meta( $cat->term_id, 'thumbnail_id', true );
$image = wp_get_attachment_url( $thumbnail_id );
?>
<div class="x-section bg-image" style="margin: 0px;padding: 260px 0px 50px; background-image: url(<?php echo $image ?>); background-color: transparent;">
<div class="x-container max width" style="margin: 0px auto;padding: 0px;">
<div class="x-column x-sm x-1-1" style="padding: 0px;">
<div class="x-text cs-ta-right">
<h1 class="page-title"><?php woocommerce_page_title(); ?></h1>
</div>
</div>
</div>
</div>
<?php
}
}
// Remove orderby
remove_action( 'woocommerce_before_shop_loop', 'woocommerce_catalog_ordering', 30 );
function woocommerce_result_count() {
return;
}
if ( ! function_exists( 'woocommerce_template_loop_category_title_new' ) ) {
/**
* Show the subcategory title in the product loop.
*/
function woocommerce_template_loop_category_title_new( $category ) {
?>
<h3>
<?php
echo $category->name;
if ( $category->count > 0 )
echo apply_filters( 'woocommerce_subcategory_count_html', '', $category );
?>
</h3>
<?php
}
}
remove_action( 'woocommerce_shop_loop_subcategory_title', 'woocommerce_template_loop_category_title', 10 );
add_action( 'woocommerce_shop_loop_subcategory_title', 'woocommerce_template_loop_category_title_new', 10 );
// Configure products
function x_woocommerce_before_shop_loop_item_title_new() {
echo '<div class="entry-wrap"><header class="entry-header">';
}
remove_action( 'woocommerce_shop_loop_item_title', 'x_woocommerce_before_shop_loop_item_title', 99 );
add_action( 'woocommerce_shop_loop_item_title', 'x_woocommerce_before_shop_loop_item_title_new', 10 );
function x_woocommerce_after_shop_loop_item_title_new() {
echo '</header></div>';
}
remove_action( 'woocommerce_shop_loop_item_title', 'x_woocommerce_after_shop_loop_item_title', 99 );
add_action( 'woocommerce_shop_loop_item_title', 'x_woocommerce_after_shop_loop_item_title_new', 10 );
// Remove pagination
add_filter( 'loop_shop_per_page', create_function( '$cols', 'return 90;' ), 20 );
// Add product content
add_action( 'woocommerce_after_shop_loop_item_title', 'woocommerce_product_content', 9);
add_action('the_content','woo_content_div');
function woo_content_div( $content ){
return '<div class="product-content">'.$content.'</div>';
};
if (!function_exists('woocommerce_product_content')) {
function woocommerce_product_content() {
echo the_content();
}
};
function woocommerce_img_pdf() {
$productImg = get_the_post_thumbnail($post_id, 'full'); ?>
<div class="entry-featured">
<?php echo $productImg; ?>
<?php // check if the repeater field has rows of data
if( have_rows('pdf_file_container') ): ?>
<div class="product-file-container">
<p>Downloads disponíveis:</p>
<ul>
<?php while( have_rows('pdf_file_container') ): the_row();
$file = get_sub_field('pdf_file');?>
<li><a class="productPdf" target="_blank" href="<?php echo $file['url']; ?>">
<?php echo $file['title']; ?>
</a></li>
<?php endwhile; ?>
</ul>
</div>
<?php endif; ?>
</div>
<?php
}
add_action( 'woocommerce_before_shop_loop_item_title_new', 'woocommerce_img_pdf', 11 );
add_action( 'woocommerce_before_shop_loop_item_title_new', 'x_woocommerce_before_shop_loop_item_title', 10 );
// Disable comments
// Disable support for comments and trackbacks in post types
function df_disable_comments_post_types_support() {
$post_types = get_post_types();
foreach ($post_types as $post_type) {
if(post_type_supports($post_type, 'comments')) {
remove_post_type_support($post_type, 'comments');
remove_post_type_support($post_type, 'trackbacks');
}
}
}
add_action('admin_init', 'df_disable_comments_post_types_support');
// Close comments on the front-end
function df_disable_comments_status() {
return false;
}
add_filter('comments_open', 'df_disable_comments_status', 20, 2);
add_filter('pings_open', 'df_disable_comments_status', 20, 2);
// Hide existing comments
function df_disable_comments_hide_existing_comments($comments) {
$comments = array();
return $comments;
}
add_filter('comments_array', 'df_disable_comments_hide_existing_comments', 10, 2);
// Remove comments page in menu
function df_disable_comments_admin_menu() {
remove_menu_page('edit-comments.php');
}
add_action('admin_menu', 'df_disable_comments_admin_menu');
// Redirect any user trying to access comments page
function df_disable_comments_admin_menu_redirect() {
global $pagenow;
if ($pagenow === 'edit-comments.php') {
wp_redirect(admin_url()); exit;
}
}
add_action('admin_init', 'df_disable_comments_admin_menu_redirect');
// Remove comments metabox from dashboard
function df_disable_comments_dashboard() {
remove_meta_box('dashboard_recent_comments', 'dashboard', 'normal');
}
add_action('admin_init', 'df_disable_comments_dashboard');
// Remove comments links from admin bar
function df_disable_comments_admin_bar() {
if (is_admin_bar_showing()) {
remove_action('admin_bar_menu', 'wp_admin_bar_comments_menu', 60);
}
}
add_action('init', 'df_disable_comments_admin_bar');