functions.php
3.71 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
<?php
/**
* General functions used to integrate this theme with WooCommerce.
*
* @package storefront
*/
/**
* Before Content
* Wraps all WooCommerce content in wrappers which match the theme markup
* @since 1.0.0
* @return void
*/
if ( ! function_exists( 'storefront_before_content' ) ) {
function storefront_before_content() {
?>
<div id="primary" class="content-area">
<main id="main" class="site-main" role="main">
<?php
}
}
/**
* After Content
* Closes the wrapping divs
* @since 1.0.0
* @return void
*/
if ( ! function_exists( 'storefront_after_content' ) ) {
function storefront_after_content() {
?>
</main><!-- #main -->
</div><!-- #primary -->
<?php do_action( 'storefront_sidebar' );
}
}
/**
* Default loop columns on product archives
* @return integer products per row
* @since 1.0.0
*/
function storefront_loop_columns() {
return apply_filters( 'storefront_loop_columns', 3 ); // 3 products per row
}
/**
* Add 'woocommerce-active' class to the body tag
* @param array $classes
* @return array $classes modified to include 'woocommerce-active' class
*/
function storefront_woocommerce_body_class( $classes ) {
if ( is_woocommerce_activated() ) {
$classes[] = 'woocommerce-active';
}
return $classes;
}
/**
* Cart Fragments
* Ensure cart contents update when products are added to the cart via AJAX
* @param array $fragments Fragments to refresh via AJAX
* @return array Fragments to refresh via AJAX
*/
if ( ! function_exists( 'storefront_cart_link_fragment' ) ) {
function storefront_cart_link_fragment( $fragments ) {
global $woocommerce;
ob_start();
storefront_cart_link();
$fragments['a.cart-contents'] = ob_get_clean();
return $fragments;
}
}
/**
* WooCommerce specific scripts & stylesheets
* @since 1.0.0
*/
function storefront_woocommerce_scripts() {
global $storefront_version;
wp_enqueue_style( 'storefront-woocommerce-style', get_template_directory_uri() . '/inc/woocommerce/css/woocommerce.css', $storefront_version );
wp_style_add_data( 'storefront-woocommerce-style', 'rtl', 'replace' );
wp_register_script( 'storefront-sticky-payment', get_template_directory_uri() . '/js/checkout.min.js', 'jquery', $storefront_version, true );
if ( is_checkout() ) {
wp_enqueue_script( 'storefront-sticky-payment' );
}
}
/**
* Star rating backwards compatibility script (WooCommerce <2.5).
* @since 1.6.0
*/
function storefront_star_rating_script() {
if ( wp_script_is( 'jquery', 'done' ) && is_product() ) {
?>
<script type="text/javascript">
jQuery( function( $ ) {
$( 'body' ).on( 'click', '#respond p.stars a', function() {
var $container = $( this ).closest( '.stars' );
$container.addClass( 'selected' );
});
});
</script>
<?php
}
}
/**
* Related Products Args
* @param array $args related products args
* @since 1.0.0
* @return array $args related products args
*/
function storefront_related_products_args( $args ) {
$args = apply_filters( 'storefront_related_products_args', array(
'posts_per_page' => 3,
'columns' => 3,
) );
return $args;
}
/**
* Product gallery thumnail columns
* @return integer number of columns
* @since 1.0.0
*/
function storefront_thumbnail_columns() {
return intval( apply_filters( 'storefront_product_thumbnail_columns', 4 ) );
}
/**
* Products per page
* @return integer number of products
* @since 1.0.0
*/
function storefront_products_per_page() {
return intval( apply_filters( 'storefront_products_per_page', 12 ) );
}
/**
* Query WooCommerce Extension Activation.
* @var $extension main extension class name
* @return boolean
*/
function is_woocommerce_extension_activated( $extension = 'WC_Bookings' ) {
return class_exists( $extension ) ? true : false;
}