PluginProbe
Qi Blocks / 1.0.7
Qi Blocks v1.0.7
1.5.3 1.5.2 1.5.1 trunk 1.0 1.0.1 1.0.2 1.0.3 1.0.4 1.0.5 1.0.6 1.0.7 1.0.8 1.0.9 1.1 1.1.1 1.1.2 1.2 1.2.1 1.2.2 1.2.3 1.2.4 1.2.5 1.2.6 1.2.7 All 45 releases
qi-blocks / inc / woocommerce / helper.php

helper.php in Qi Blocks 1.0.7, at inc/woocommerce/helper.php

220 lines 6.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 // Exit if accessed directly.
4 defined( 'ABSPATH' ) || exit;
5
6 if ( ! function_exists( 'qi_blocks_woo_get_global_product' ) ) {
7 /**
8 * Function that return global WooCommerce object
9 *
10 * @return object
11 */
12 function qi_blocks_woo_get_global_product() {
13 global $product;
14
15 return $product;
16 }
17 }
18
19 if ( ! function_exists( 'qi_blocks_get_additional_product_query_args' ) ) {
20 /**
21 * Function that return additional query arguments
22 *
23 * @param array $atts - options value
24 *
25 * @return array
26 */
27 function qi_blocks_get_additional_product_query_args( $atts ) {
28 $args = qi_blocks_get_additional_query_args( $atts );
29
30 if ( ! empty( $atts['filterBy'] ) ) {
31 switch ( $atts['filterBy'] ) {
32 case 'on_sale':
33 $args['no_found_rows'] = 1;
34 $args['post__in'] = array_merge( array( 0 ), wc_get_product_ids_on_sale() );
35 break;
36 case 'featured':
37 $args['tax_query'] = WC()->query->get_tax_query();
38
39 $args['tax_query'][] = array(
40 'taxonomy' => 'product_visibility',
41 'terms' => 'featured',
42 'field' => 'name',
43 'operator' => 'IN',
44 'include_children' => false,
45 );
46 break;
47 case 'top_rated':
48 $args['meta_key'] = '_wc_average_rating';
49 $args['order'] = 'DESC';
50 $args['orderby'] = 'meta_value_num';
51 break;
52 case 'best_selling':
53 $args['meta_key'] = 'total_sales';
54 $args['order'] = 'DESC';
55 $args['orderby'] = 'meta_value_num';
56 break;
57 }
58 }
59
60 return $args;
61 }
62 }
63
64 if ( ! function_exists( 'qi_blocks_get_product_list_holder_classes' ) ) {
65 /**
66 * Function that return element holder classes
67 *
68 * @param array $atts - options value
69 *
70 * @return string
71 */
72 function qi_blocks_get_product_list_holder_classes( $atts ) {
73 $classes = qi_blocks_get_block_holder_classes( 'product-list', $atts, 'qi-blocks-woo-block' );
74
75 $classes[] = ! empty( $atts['columnClasses'] ) ? $atts['columnClasses'] : '';
76 $classes[] = ! empty( $atts['itemLayout'] ) ? 'qodef-item-layout--' . $atts['itemLayout'] : '';
77 $classes[] = ! empty( $atts['imageHover'] ) ? 'qodef-image--hover-' . $atts['imageHover'] : '';
78 $classes[] = ! empty( $atts['imageZoomOrigin'] ) ? 'qodef-image--hover-from-' . $atts['imageZoomOrigin'] : '';
79
80 return implode( ' ', $classes );
81 }
82 }
83
84 if ( ! function_exists( 'qi_blocks_woo_get_product_categories' ) ) {
85 /**
86 * Function that render product categories
87 *
88 * @param string $before
89 * @param string $after
90 *
91 * @return string
92 */
93 function qi_blocks_woo_get_product_categories( $before = '', $after = '' ) {
94 $product = qi_blocks_woo_get_global_product();
95
96 return ! empty( $product ) ? wc_get_product_category_list( $product->get_id(), '<span class="qodef-category-separator"></span>', $before, $after ) : '';
97 }
98 }
99
100 if ( ! function_exists( 'qi_blocks_get_out_of_stock_mark' ) ) {
101 /**
102 * Function for adding out of stock template for product
103 *
104 * @return string which contains html content
105 */
106 function qi_blocks_get_out_of_stock_mark() {
107 return '<span class="qodef-block-woo-product-mark qodef-out-of-stock">' . esc_html__( 'Sold', 'qi-blocks' ) . '</span>';
108 }
109 }
110
111 if ( ! function_exists( 'qi_blocks_woo_set_sale_flash' ) ) {
112 /**
113 * Function that override on sale template for product
114 *
115 * @return string which contains html content
116 */
117 function qi_blocks_woo_set_sale_flash() {
118 $product = qi_blocks_woo_get_global_product();
119
120 if ( ! empty( $product ) && $product->is_on_sale() && $product->is_in_stock() ) {
121 $sale_label = esc_html__( 'Sale', 'qi-blocks' );
122
123 return '<span class="qodef-block-woo-product-mark qodef-woo-onsale">' . $sale_label . '</span>';
124 }
125
126 return '';
127 }
128 }
129
130 if ( ! function_exists( 'qi_blocks_generate_add_to_cart_button_params' ) ) {
131 /**
132 * Function for generating add to cart button params
133 *
134 * @param array $atts - options value
135 *
136 * @return array
137 */
138 function qi_blocks_generate_add_to_cart_button_params( $atts ) {
139 $product = qi_blocks_woo_get_global_product();
140 $params = array();
141
142 if ( $product ) {
143 $args = array(
144 'quantity' => 1,
145 'class' => implode(
146 ' ',
147 array_filter(
148 array(
149 'button',
150 'product_type_' . $product->get_type(),
151 $product->is_purchasable() && $product->is_in_stock() ? 'add_to_cart_button' : '',
152 $product->supports( 'ajax_add_to_cart' ) && $product->is_purchasable() && $product->is_in_stock() ? 'ajax_add_to_cart' : '',
153 )
154 )
155 ),
156 'attributes' => array(
157 'data-product_id' => $product->get_id(),
158 'data-product_sku' => $product->get_sku(),
159 'aria-label' => $product->add_to_cart_description(),
160 'rel' => 'nofollow',
161 ),
162 );
163
164 if ( isset( $args['attributes']['aria-label'] ) ) {
165 $args['attributes']['aria-label'] = wp_strip_all_tags( $args['attributes']['aria-label'] );
166 }
167
168 if ( ! empty( $args['class'] ) ) {
169 $atts['custom_class'] = $args['class'];
170 }
171
172 if ( count( $args['attributes'] ) ) {
173 $params['custom_attrs'] = $args['attributes'];
174 $params['custom_attrs']['data-quantity'] = $args['quantity'];
175 }
176
177 $params['button_link'] = array(
178 'url' => $product->add_to_cart_url(),
179 );
180
181 $params['buttonText'] = $product->add_to_cart_text();
182
183 $params['button_classes'] = qi_blocks_button_get_holder_classes( $atts );
184 $params['icon_classes'] = qi_blocks_button_get_icon_classes( $atts );
185 $params['data_attrs'] = array_merge( array( 'target' => '_self' ), $params['custom_attrs'] );
186 }
187
188 return $params;
189 }
190 }
191
192 if ( ! function_exists( 'qi_blocks_woo_product_get_rating_html' ) ) {
193 /**
194 * Function that return ratings templates
195 *
196 * @param string $html - contains html content
197 * @param float $rating
198 *
199 * @return string
200 */
201 function qi_blocks_woo_product_get_rating_html( $html, $rating ) {
202
203 if ( ! empty( $rating ) ) {
204 $product_rating = apply_filters(
205 'qi_blocks_filter_woocommerce_product_rating',
206 '<svg class="qodef-m-star-item" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="16" height="15" x="0px" y="0px" viewBox="0 0 16.2 15.2" xml:space="preserve"><g><g><path d="M16.1,5.8l-5,3.5l1.9,5.7l-4.9-3.6l-4.9,3.6l1.9-5.7l-5-3.5h6.1l1.9-5.7L10,5.8H16.1z"/></g></g></svg>'
207 );
208
209 $html = '<div class="qodef-m-inner">';
210 $html .= '<div class="qodef-m-star qodef--initial">' . str_repeat( $product_rating, 5 ) . '</div>';
211 $html .= '<div class="qodef-m-star qodef--active" style="width:' . ( ( $rating / 5 ) * 100 ) . '%">';
212 $html .= str_repeat( $product_rating, 5 );
213 $html .= '</div>';
214 $html .= '</div>';
215 }
216
217 return $html;
218 }
219 }
220