1 <?php
2 3 4 5 6 7 8 9 10 11
12
13 if ( ! defined( 'ABSPATH' ) ) exit;
14
15
16 include( 'wc-cart-functions.php' );
17 include( 'wc-conditional-functions.php' );
18 include( 'wc-coupon-functions.php' );
19 include( 'wc-customer-functions.php' );
20 include( 'wc-deprecated-functions.php' );
21 include( 'wc-formatting-functions.php' );
22 include( 'wc-notice-functions.php' );
23 include( 'wc-order-functions.php' );
24 include( 'wc-page-functions.php' );
25 include( 'wc-product-functions.php' );
26 include( 'wc-term-functions.php' );
27 include( 'wc-attribute-functions.php' );
28
29 30 31
32 add_filter( 'woocommerce_coupon_code', 'sanitize_text_field' );
33 add_filter( 'woocommerce_coupon_code', 'strtolower' );
34 add_filter( 'woocommerce_stock_amount', 'intval' );
35
36 37 38
39 add_filter( 'woocommerce_short_description', 'wptexturize' );
40 add_filter( 'woocommerce_short_description', 'convert_smilies' );
41 add_filter( 'woocommerce_short_description', 'convert_chars' );
42 add_filter( 'woocommerce_short_description', 'wpautop' );
43 add_filter( 'woocommerce_short_description', 'shortcode_unautop' );
44 add_filter( 'woocommerce_short_description', 'prepend_attachment' );
45 add_filter( 'woocommerce_short_description', 'do_shortcode', 11 );
46
47 48 49 50 51 52 53 54
55 function wc_get_template_part( $slug, $name = '' ) {
56 $template = '';
57
58
59 if ( $name ) {
60 $template = locate_template( array( "{$slug}-{$name}.php", WC()->template_path() . "{$slug}-{$name}.php" ) );
61 }
62
63
64 if ( ! $template && $name && file_exists( WC()->plugin_path() . "/templates/{$slug}-{$name}.php" ) ) {
65 $template = WC()->plugin_path() . "/templates/{$slug}-{$name}.php";
66 }
67
68
69 if ( ! $template ) {
70 $template = locate_template( array( "{$slug}.php", WC()->template_path() . "{$slug}.php" ) );
71 }
72
73
74 $template = apply_filters( 'wc_get_template_part', $template, $slug, $name );
75
76 if ( $template ) {
77 load_template( $template, false );
78 }
79 }
80
81 82 83 84 85 86 87 88 89 90
91 function wc_get_template( $template_name, $args = array(), $template_path = '', $default_path = '' ) {
92 if ( $args && is_array( $args ) ) {
93 extract( $args );
94 }
95
96 $located = wc_locate_template( $template_name, $template_path, $default_path );
97
98 if ( ! file_exists( $located ) ) {
99 _doing_it_wrong( __FUNCTION__, sprintf( '<code>%s</code> does not exist.', $located ), '2.1' );
100 return;
101 }
102
103 do_action( 'woocommerce_before_template_part', $template_name, $template_path, $located, $args );
104
105 include( $located );
106
107 do_action( 'woocommerce_after_template_part', $template_name, $template_path, $located, $args );
108 }
109
110 111 112 113 114 115 116 117 118 119 120 121 122 123 124
125 function wc_locate_template( $template_name, $template_path = '', $default_path = '' ) {
126 if ( ! $template_path ) {
127 $template_path = WC()->template_path();
128 }
129
130 if ( ! $default_path ) {
131 $default_path = WC()->plugin_path() . '/templates/';
132 }
133
134
135 $template = locate_template(
136 array(
137 trailingslashit( $template_path ) . $template_name,
138 $template_name
139 )
140 );
141
142
143 if ( ! $template ) {
144 $template = $default_path . $template_name;
145 }
146
147
148 return apply_filters('woocommerce_locate_template', $template, $template_name, $template_path);
149 }
150
151 152 153 154
155 function get_woocommerce_currency() {
156 return apply_filters( 'woocommerce_currency', get_option('woocommerce_currency') );
157 }
158
159 160 161 162
163 function get_woocommerce_currencies() {
164 return array_unique(
165 apply_filters( 'woocommerce_currencies',
166 array(
167 'AED' => __( 'United Arab Emirates Dirham', 'woocommerce' ),
168 'AUD' => __( 'Australian Dollars', 'woocommerce' ),
169 'BDT' => __( 'Bangladeshi Taka', 'woocommerce' ),
170 'BRL' => __( 'Brazilian Real', 'woocommerce' ),
171 'BGN' => __( 'Bulgarian Lev', 'woocommerce' ),
172 'CAD' => __( 'Canadian Dollars', 'woocommerce' ),
173 'CLP' => __( 'Chilean Peso', 'woocommerce' ),
174 'CNY' => __( 'Chinese Yuan', 'woocommerce' ),
175 'COP' => __( 'Colombian Peso', 'woocommerce' ),
176 'CZK' => __( 'Czech Koruna', 'woocommerce' ),
177 'DKK' => __( 'Danish Krone', 'woocommerce' ),
178 'EUR' => __( 'Euros', 'woocommerce' ),
179 'HKD' => __( 'Hong Kong Dollar', 'woocommerce' ),
180 'HRK' => __( 'Croatia kuna', 'woocommerce' ),
181 'HUF' => __( 'Hungarian Forint', 'woocommerce' ),
182 'ISK' => __( 'Icelandic krona', 'woocommerce' ),
183 'IDR' => __( 'Indonesia Rupiah', 'woocommerce' ),
184 'INR' => __( 'Indian Rupee', 'woocommerce' ),
185 'ILS' => __( 'Israeli Shekel', 'woocommerce' ),
186 'JPY' => __( 'Japanese Yen', 'woocommerce' ),
187 'KRW' => __( 'South Korean Won', 'woocommerce' ),
188 'MYR' => __( 'Malaysian Ringgits', 'woocommerce' ),
189 'MXN' => __( 'Mexican Peso', 'woocommerce' ),
190 'NGN' => __( 'Nigerian Naira', 'woocommerce' ),
191 'NOK' => __( 'Norwegian Krone', 'woocommerce' ),
192 'NZD' => __( 'New Zealand Dollar', 'woocommerce' ),
193 'PHP' => __( 'Philippine Pesos', 'woocommerce' ),
194 'PLN' => __( 'Polish Zloty', 'woocommerce' ),
195 'GBP' => __( 'Pounds Sterling', 'woocommerce' ),
196 'RON' => __( 'Romanian Leu', 'woocommerce' ),
197 'RUB' => __( 'Russian Ruble', 'woocommerce' ),
198 'SGD' => __( 'Singapore Dollar', 'woocommerce' ),
199 'ZAR' => __( 'South African rand', 'woocommerce' ),
200 'SEK' => __( 'Swedish Krona', 'woocommerce' ),
201 'CHF' => __( 'Swiss Franc', 'woocommerce' ),
202 'TWD' => __( 'Taiwan New Dollars', 'woocommerce' ),
203 'THB' => __( 'Thai Baht', 'woocommerce' ),
204 'TRY' => __( 'Turkish Lira', 'woocommerce' ),
205 'USD' => __( 'US Dollars', 'woocommerce' ),
206 'VND' => __( 'Vietnamese Dong', 'woocommerce' ),
207 )
208 )
209 );
210 }
211
212 213 214 215 216
217 function get_woocommerce_currency_symbol( $currency = '' ) {
218 if ( ! $currency ) {
219 $currency = get_woocommerce_currency();
220 }
221
222 switch ( $currency ) {
223 case 'AED' :
224 $currency_symbol = 'د.إ';
225 break;
226 case 'BDT':
227 $currency_symbol = '৳ ';
228 break;
229 case 'BRL' :
230 $currency_symbol = 'R$';
231 break;
232 case 'BGN' :
233 $currency_symbol = 'лв.';
234 break;
235 case 'AUD' :
236 case 'CAD' :
237 case 'CLP' :
238 case 'MXN' :
239 case 'NZD' :
240 case 'HKD' :
241 case 'SGD' :
242 case 'USD' :
243 $currency_symbol = '$';
244 break;
245 case 'EUR' :
246 $currency_symbol = '€';
247 break;
248 case 'CNY' :
249 case 'RMB' :
250 case 'JPY' :
251 $currency_symbol = '¥';
252 break;
253 case 'RUB' :
254 $currency_symbol = 'руб.';
255 break;
256 case 'KRW' : $currency_symbol = '₩'; break;
257 case 'TRY' : $currency_symbol = 'TL'; break;
258 case 'NOK' : $currency_symbol = 'kr'; break;
259 case 'ZAR' : $currency_symbol = 'R'; break;
260 case 'CZK' : $currency_symbol = 'Kč'; break;
261 case 'MYR' : $currency_symbol = 'RM'; break;
262 case 'DKK' : $currency_symbol = 'kr.'; break;
263 case 'HUF' : $currency_symbol = 'Ft'; break;
264 case 'IDR' : $currency_symbol = 'Rp'; break;
265 case 'INR' : $currency_symbol = 'Rs.'; break;
266 case 'ISK' : $currency_symbol = 'Kr.'; break;
267 case 'ILS' : $currency_symbol = '₪'; break;
268 case 'PHP' : $currency_symbol = '₱'; break;
269 case 'PLN' : $currency_symbol = 'zł'; break;
270 case 'SEK' : $currency_symbol = 'kr'; break;
271 case 'CHF' : $currency_symbol = 'CHF'; break;
272 case 'TWD' : $currency_symbol = 'NT$'; break;
273 case 'THB' : $currency_symbol = '฿'; break;
274 case 'GBP' : $currency_symbol = '£'; break;
275 case 'RON' : $currency_symbol = 'lei'; break;
276 case 'VND' : $currency_symbol = '₫'; break;
277 case 'NGN' : $currency_symbol = '₦'; break;
278 case 'HRK' : $currency_symbol = 'Kn'; break;
279 default : $currency_symbol = ''; break;
280 }
281
282 return apply_filters( 'woocommerce_currency_symbol', $currency_symbol, $currency );
283 }
284
285 286 287 288 289 290 291 292 293
294 function wc_mail( $to, $subject, $message, $headers = "Content-Type: text/html\r\n", $attachments = "" ) {
295 global $woocommerce;
296
297 $mailer = WC()->mailer();
298
299 $mailer->send( $to, $subject, $message, $headers, $attachments );
300 }
301
302 303 304 305 306 307 308 309
310 function wc_get_image_size( $image_size ) {
311 if ( in_array( $image_size, array( 'shop_thumbnail', 'shop_catalog', 'shop_single' ) ) ) {
312 $size = get_option( $image_size . '_image_size', array() );
313 $size['width'] = isset( $size['width'] ) ? $size['width'] : '300';
314 $size['height'] = isset( $size['height'] ) ? $size['height'] : '300';
315 $size['crop'] = isset( $size['crop'] ) ? $size['crop'] : 1;
316 } else {
317 $size = array(
318 'width' => '300',
319 'height' => '300',
320 'crop' => 1
321 );
322 }
323
324 return apply_filters( 'woocommerce_get_image_size_' . $image_size, $size );
325 }
326
327 328 329 330 331
332 function wc_enqueue_js( $code ) {
333 global $wc_queued_js;
334
335 if ( empty( $wc_queued_js ) ) {
336 $wc_queued_js = '';
337 }
338
339 $wc_queued_js .= "\n" . $code . "\n";
340 }
341
342 343 344
345 function wc_print_js() {
346 global $wc_queued_js;
347
348 if ( ! empty( $wc_queued_js ) ) {
349
350 echo "<!-- WooCommerce JavaScript -->\n<script type=\"text/javascript\">\njQuery(function($) {";
351
352
353 $wc_queued_js = wp_check_invalid_utf8( $wc_queued_js );
354 $wc_queued_js = preg_replace( '/&#(x)?0*(?(1)27|39);?/i', "'", $wc_queued_js );
355 $wc_queued_js = str_replace( "\r", '', $wc_queued_js );
356
357 echo $wc_queued_js . "});\n</script>\n";
358
359 unset( $wc_queued_js );
360 }
361 }
362
363 364 365 366 367 368 369 370
371 function wc_setcookie( $name, $value, $expire = 0, $secure = false ) {
372 if ( ! headers_sent() ) {
373 setcookie( $name, $value, $expire, COOKIEPATH, COOKIE_DOMAIN, $secure );
374 } elseif ( defined( 'WP_DEBUG' ) && WP_DEBUG ) {
375 trigger_error( "Cookie cannot be set - headers already sent", E_USER_NOTICE );
376 }
377 }
378
379 380 381 382 383 384 385
386 function get_woocommerce_api_url( $path ) {
387
388 $url = get_home_url( null, 'wc-api/v' . WC_API::VERSION . '/', is_ssl() ? 'https' : 'http' );
389
390 if ( ! empty( $path ) && is_string( $path ) ) {
391 $url .= ltrim( $path, '/' );
392 }
393
394 return $url;
395 }
396