1 <?php
2 3 4 5 6 7 8 9 10 11
12
13 if ( ! defined( 'ABSPATH' ) ) exit;
14
15 16 17 18 19
20 function wc_template_redirect() {
21 global $wp_query, $wp;
22
23
24 if ( ! empty( $_GET['page_id'] ) && get_option( 'permalink_structure' ) == "" && $_GET['page_id'] == wc_get_page_id( 'shop' ) ) {
25 wp_safe_redirect( get_post_type_archive_link('product') );
26 exit;
27 }
28
29
30 elseif ( is_page( wc_get_page_id( 'checkout' ) ) && sizeof( WC()->cart->get_cart() ) == 0 && empty( $wp->query_vars['order-pay'] ) && ! isset( $wp->query_vars['order-received'] ) ) {
31 wp_redirect( get_permalink( wc_get_page_id( 'cart' ) ) );
32 exit;
33 }
34
35
36 elseif ( isset( $wp->query_vars['customer-logout'] ) ) {
37 wp_redirect( str_replace( '&', '&', wp_logout_url( get_permalink( wc_get_page_id( 'myaccount' ) ) ) ) );
38 exit;
39 }
40
41
42 elseif ( is_search() && is_post_type_archive( 'product' ) && apply_filters( 'woocommerce_redirect_single_search_result', true ) && $wp_query->post_count == 1 ) {
43 $product = get_product( $wp_query->post );
44
45 if ( $product->is_visible() ) {
46 wp_safe_redirect( get_permalink( $product->id ), 302 );
47 exit;
48 }
49 }
50
51
52 elseif ( is_add_payment_method_page() ) {
53
54 WC()->payment_gateways();
55
56 }
57
58
59 elseif ( is_checkout() ) {
60
61 ob_start();
62
63
64 WC()->payment_gateways();
65 WC()->shipping();
66 }
67 }
68 add_action( 'template_redirect', 'wc_template_redirect' );
69
70 71 72 73 74 75
76 function wc_setup_product_data( $post ) {
77 unset( $GLOBALS['product'] );
78
79 if ( is_int( $post ) )
80 $post = get_post( $post );
81
82 if ( empty( $post->post_type ) || ! in_array( $post->post_type, array( 'product', 'product_variation' ) ) )
83 return;
84
85 $GLOBALS['product'] = get_product( $post );
86
87 return $GLOBALS['product'];
88 }
89 add_action( 'the_post', 'wc_setup_product_data' );
90
91 if ( ! function_exists( 'woocommerce_reset_loop' ) ) {
92
93 94 95 96 97 98 99
100 function woocommerce_reset_loop() {
101 global $woocommerce_loop;
102
103 $woocommerce_loop['loop'] = $woocommerce_loop['columns'] = '';
104 }
105 }
106 add_filter( 'loop_end', 'woocommerce_reset_loop' );
107
108 109 110 111 112 113
114 function () {
115
116 if ( is_post_type_archive( 'product' ) || is_singular( 'product' ) ) {
117
118 $feed = get_post_type_archive_feed_link( 'product' );
119
120 echo '<link rel="alternate" type="application/rss+xml" title="' . __( 'New products', 'woocommerce' ) . '" href="' . esc_attr( $feed ) . '" />';
121
122 } elseif ( is_tax( 'product_cat' ) ) {
123
124 $term = get_term_by('slug', esc_attr( get_query_var('product_cat') ), 'product_cat');
125
126 $feed = add_query_arg('product_cat', $term->slug, get_post_type_archive_feed_link( 'product' ));
127
128 echo '<link rel="alternate" type="application/rss+xml" title="' . sprintf(__( 'New products added to %s', 'woocommerce' ), urlencode($term->name)) . '" href="' . esc_attr( $feed ) . '" />';
129
130 } elseif ( is_tax( 'product_tag' ) ) {
131
132 $term = get_term_by('slug', esc_attr( get_query_var('product_tag') ), 'product_tag');
133
134 $feed = add_query_arg('product_tag', $term->slug, get_post_type_archive_feed_link( 'product' ));
135
136 echo '<link rel="alternate" type="application/rss+xml" title="' . sprintf(__( 'New products tagged %s', 'woocommerce' ), urlencode($term->name)) . '" href="' . esc_attr( $feed ) . '" />';
137
138 }
139 }
140
141 142 143 144 145 146
147 function wc_generator_tag( $gen, $type ) {
148 switch ( $type ) {
149 case 'html':
150 $gen .= "\n" . '<meta name="generator" content="WooCommerce ' . esc_attr( WC_VERSION ) . '">';
151 break;
152 case 'xhtml':
153 $gen .= "\n" . '<meta name="generator" content="WooCommerce ' . esc_attr( WC_VERSION ) . '" />';
154 break;
155 }
156 return $gen;
157 }
158
159 160 161 162 163 164
165 function wc_body_class( $classes ) {
166 $classes = (array) $classes;
167
168 if ( is_woocommerce() ) {
169 $classes[] = 'woocommerce';
170 $classes[] = 'woocommerce-page';
171 }
172
173 elseif ( is_checkout() ) {
174 $classes[] = 'woocommerce-checkout';
175 $classes[] = 'woocommerce-page';
176 }
177
178 elseif ( is_cart() ) {
179 $classes[] = 'woocommerce-cart';
180 $classes[] = 'woocommerce-page';
181 }
182
183 elseif ( is_account_page() ) {
184 $classes[] = 'woocommerce-account';
185 $classes[] = 'woocommerce-page';
186 }
187
188 if ( is_store_notice_showing() ) {
189 $classes[] = 'woocommerce-demo-store';
190 }
191
192 return array_unique( $classes );
193 }
194
195 196 197 198 199 200 201 202 203
204 function wc_product_post_class( $classes, $class = '', $post_id = '' ) {
205 if ( ! $post_id || get_post_type( $post_id ) !== 'product' )
206 return $classes;
207
208 $product = get_product( $post_id );
209
210 if ( $product ) {
211 if ( $product->is_on_sale() ) {
212 $classes[] = 'sale';
213 }
214 if ( $product->is_featured() ) {
215 $classes[] = 'featured';
216 }
217 if ( $product->is_downloadable() ) {
218 $classes[] = 'downloadable';
219 }
220 if ( $product->is_virtual() ) {
221 $classes[] = 'virtual';
222 }
223 if ( $product->is_sold_individually() ) {
224 $classes[] = 'sold-individually';
225 }
226 if ( $product->is_taxable() ) {
227 $classes[] = 'taxable';
228 }
229 if ( $product->is_shipping_taxable() ) {
230 $classes[] = 'shipping-taxable';
231 }
232 if ( $product->is_purchasable() ) {
233 $classes[] = 'purchasable';
234 }
235 if ( isset( $product->product_type ) ) {
236 $classes[] = "product-type-" . $product->product_type;
237 }
238
239
240 $categories = wp_get_post_terms( $product->id, "product_cat" );
241 if ( ! empty( $categories ) ) {
242 foreach ($categories as $key => $value) {
243 $classes[] = "product-cat-" . $value->slug;
244 }
245 }
246
247
248 $tags = wp_get_post_terms( $product->id, "product_tag" );
249 if ( ! empty( $tags ) ) {
250 foreach ($tags as $key => $value) {
251 $classes[] = "product-tag-" . $value->slug;
252 }
253 }
254
255 $classes[] = $product->stock_status;
256 }
257
258 if ( ( $key = array_search( 'hentry', $classes ) ) !== false ) {
259 unset( $classes[ $key ] );
260 }
261
262 return $classes;
263 }
264
265
266
267 if ( ! function_exists( 'woocommerce_content' ) ) {
268
269 270 271 272 273 274 275 276 277 278
279 function woocommerce_content() {
280
281 if ( is_singular( 'product' ) ) {
282
283 while ( have_posts() ) : the_post();
284
285 wc_get_template_part( 'content', 'single-product' );
286
287 endwhile;
288
289 } else { ?>
290
291 <?php if ( apply_filters( 'woocommerce_show_page_title', true ) ) : ?>
292
293 <h1 class="page-title"><?php woocommerce_page_title(); ?></h1>
294
295 <?php endif; ?>
296
297 <?php do_action( 'woocommerce_archive_description' ); ?>
298
299 <?php if ( have_posts() ) : ?>
300
301 <?php do_action('woocommerce_before_shop_loop'); ?>
302
303 <?php woocommerce_product_loop_start(); ?>
304
305 <?php woocommerce_product_subcategories(); ?>
306
307 <?php while ( have_posts() ) : the_post(); ?>
308
309 <?php wc_get_template_part( 'content', 'product' ); ?>
310
311 <?php endwhile;
312
313 <?php woocommerce_product_loop_end(); ?>
314
315 <?php do_action('woocommerce_after_shop_loop'); ?>
316
317 <?php elseif ( ! woocommerce_product_subcategories( array( 'before' => woocommerce_product_loop_start( false ), 'after' => woocommerce_product_loop_end( false ) ) ) ) : ?>
318
319 <?php wc_get_template( 'loop/no-products-found.php' ); ?>
320
321 <?php endif;
322
323 }
324 }
325 }
326
327
328
329 if ( ! function_exists( 'woocommerce_output_content_wrapper' ) ) {
330
331 332 333 334 335 336
337 function woocommerce_output_content_wrapper() {
338 wc_get_template( 'global/wrapper-start.php' );
339 }
340 }
341 if ( ! function_exists( 'woocommerce_output_content_wrapper_end' ) ) {
342
343 344 345 346 347 348
349 function woocommerce_output_content_wrapper_end() {
350 wc_get_template( 'global/wrapper-end.php' );
351 }
352 }
353
354 if ( ! function_exists( 'woocommerce_get_sidebar' ) ) {
355
356 357 358 359 360 361
362 function () {
363 wc_get_template( 'global/sidebar.php' );
364 }
365 }
366
367 if ( ! function_exists( 'woocommerce_demo_store' ) ) {
368
369 370 371 372 373 374
375 function woocommerce_demo_store() {
376 if ( !is_store_notice_showing() )
377 return;
378
379 $notice = get_option( 'woocommerce_demo_store_notice' );
380 if ( empty( $notice ) )
381 $notice = __( 'This is a demo store for testing purposes — no orders shall be fulfilled.', 'woocommerce' );
382
383 echo apply_filters( 'woocommerce_demo_store', '<p class="demo_store">' . $notice . '</p>' );
384 }
385 }
386
387
388
389 if ( ! function_exists( 'woocommerce_page_title' ) ) {
390
391 392 393 394 395 396
397 function woocommerce_page_title( $echo = true ) {
398
399 if ( is_search() ) {
400 $page_title = sprintf( __( 'Search Results: “%s”', 'woocommerce' ), get_search_query() );
401
402 if ( get_query_var( 'paged' ) )
403 $page_title .= sprintf( __( ' – Page %s', 'woocommerce' ), get_query_var( 'paged' ) );
404
405 } elseif ( is_tax() ) {
406
407 $page_title = single_term_title( "", false );
408
409 } else {
410
411 $shop_page_id = wc_get_page_id( 'shop' );
412 $page_title = get_the_title( $shop_page_id );
413
414 }
415
416 $page_title = apply_filters( 'woocommerce_page_title', $page_title );
417
418 if ( $echo )
419 echo $page_title;
420 else
421 return $page_title;
422 }
423 }
424
425 if ( ! function_exists( 'woocommerce_product_loop_start' ) ) {
426
427 428 429 430 431 432 433
434 function woocommerce_product_loop_start( $echo = true ) {
435 ob_start();
436 wc_get_template( 'loop/loop-start.php' );
437 if ( $echo )
438 echo ob_get_clean();
439 else
440 return ob_get_clean();
441 }
442 }
443 if ( ! function_exists( 'woocommerce_product_loop_end' ) ) {
444
445 446 447 448 449 450 451
452 function woocommerce_product_loop_end( $echo = true ) {
453 ob_start();
454
455 wc_get_template( 'loop/loop-end.php' );
456
457 if ( $echo )
458 echo ob_get_clean();
459 else
460 return ob_get_clean();
461 }
462 }
463 if ( ! function_exists( 'woocommerce_taxonomy_archive_description' ) ) {
464
465 466 467 468 469 470 471
472 function woocommerce_taxonomy_archive_description() {
473 if ( is_tax( array( 'product_cat', 'product_tag' ) ) && get_query_var( 'paged' ) == 0 ) {
474 $description = apply_filters( 'the_content', term_description() );
475 if ( $description ) {
476 echo '<div class="term-description">' . $description . '</div>';
477 }
478 }
479 }
480 }
481 if ( ! function_exists( 'woocommerce_product_archive_description' ) ) {
482
483 484 485 486 487 488 489
490 function woocommerce_product_archive_description() {
491 if ( is_post_type_archive( 'product' ) && get_query_var( 'paged' ) == 0 ) {
492 $shop_page = get_post( wc_get_page_id( 'shop' ) );
493 if ( $shop_page ) {
494 $description = apply_filters( 'the_content', $shop_page->post_content );
495 if ( $description ) {
496 echo '<div class="page-description">' . $description . '</div>';
497 }
498 }
499 }
500 }
501 }
502
503 if ( ! function_exists( 'woocommerce_template_loop_add_to_cart' ) ) {
504
505 506 507 508 509 510 511
512 function woocommerce_template_loop_add_to_cart() {
513 wc_get_template( 'loop/add-to-cart.php' );
514 }
515 }
516 if ( ! function_exists( 'woocommerce_template_loop_product_thumbnail' ) ) {
517
518 519 520 521 522 523 524
525 function woocommerce_template_loop_product_thumbnail() {
526 echo woocommerce_get_product_thumbnail();
527 }
528 }
529 if ( ! function_exists( 'woocommerce_template_loop_price' ) ) {
530
531 532 533 534 535 536 537
538 function woocommerce_template_loop_price() {
539 wc_get_template( 'loop/price.php' );
540 }
541 }
542 if ( ! function_exists( 'woocommerce_template_loop_rating' ) ) {
543
544 545 546 547 548 549 550
551 function woocommerce_template_loop_rating() {
552 wc_get_template( 'loop/rating.php' );
553 }
554 }
555 if ( ! function_exists( 'woocommerce_show_product_loop_sale_flash' ) ) {
556
557 558 559 560 561 562 563
564 function woocommerce_show_product_loop_sale_flash() {
565 wc_get_template( 'loop/sale-flash.php' );
566 }
567 }
568
569 if ( ! function_exists( 'woocommerce_get_product_schema' ) ) {
570
571 572 573 574
575 function woocommerce_get_product_schema() {
576 global $post, $product;
577
578 $schema = "Product";
579
580
581 if ( $product->is_downloadable() ) {
582 switch ( $product->download_type ) {
583 case 'application' :
584 $schema = "SoftwareApplication";
585 break;
586 case 'music' :
587 $schema = "MusicAlbum";
588 break;
589 default :
590 $schema = "Product";
591 break;
592 }
593 }
594
595 return 'http://schema.org/' . $schema;
596 }
597 }
598
599 if ( ! function_exists( 'woocommerce_get_product_thumbnail' ) ) {
600
601 602 603 604 605 606 607 608 609 610
611 function woocommerce_get_product_thumbnail( $size = 'shop_catalog', $placeholder_width = 0, $placeholder_height = 0 ) {
612 global $post;
613
614 if ( has_post_thumbnail() )
615 return get_the_post_thumbnail( $post->ID, $size );
616 elseif ( wc_placeholder_img_src() )
617 return wc_placeholder_img( $size );
618 }
619 }
620
621 if ( ! function_exists( 'woocommerce_result_count' ) ) {
622
623 624 625 626 627 628 629
630 function woocommerce_result_count() {
631 wc_get_template( 'loop/result-count.php' );
632 }
633 }
634
635 if ( ! function_exists( 'woocommerce_catalog_ordering' ) ) {
636
637 638 639 640 641 642 643
644 function woocommerce_catalog_ordering() {
645 $orderby = isset( $_GET['orderby'] ) ? wc_clean( $_GET['orderby'] ) : apply_filters( 'woocommerce_default_catalog_orderby', get_option( 'woocommerce_default_catalog_orderby' ) );
646
647 wc_get_template( 'loop/orderby.php', array( 'orderby' => $orderby ) );
648 }
649 }
650
651 if ( ! function_exists( 'woocommerce_pagination' ) ) {
652
653 654 655 656 657 658 659
660 function () {
661 wc_get_template( 'loop/pagination.php' );
662 }
663 }
664
665
666
667 if ( ! function_exists( 'woocommerce_show_product_images' ) ) {
668
669 670 671 672 673 674 675
676 function woocommerce_show_product_images() {
677 wc_get_template( 'single-product/product-image.php' );
678 }
679 }
680 if ( ! function_exists( 'woocommerce_show_product_thumbnails' ) ) {
681
682 683 684 685 686 687 688
689 function woocommerce_show_product_thumbnails() {
690 wc_get_template( 'single-product/product-thumbnails.php' );
691 }
692 }
693 if ( ! function_exists( 'woocommerce_output_product_data_tabs' ) ) {
694
695 696 697 698 699 700 701
702 function woocommerce_output_product_data_tabs() {
703 wc_get_template( 'single-product/tabs/tabs.php' );
704 }
705 }
706 if ( ! function_exists( 'woocommerce_template_single_title' ) ) {
707
708 709 710 711 712 713 714
715 function woocommerce_template_single_title() {
716 wc_get_template( 'single-product/title.php' );
717 }
718 }
719 if ( ! function_exists( 'woocommerce_template_single_rating' ) ) {
720
721 722 723 724 725 726 727
728 function woocommerce_template_single_rating() {
729 wc_get_template( 'single-product/rating.php' );
730 }
731 }
732 if ( ! function_exists( 'woocommerce_template_single_price' ) ) {
733
734 735 736 737 738 739 740
741 function woocommerce_template_single_price() {
742 wc_get_template( 'single-product/price.php' );
743 }
744 }
745 if ( ! function_exists( 'woocommerce_template_single_excerpt' ) ) {
746
747 748 749 750 751 752 753
754 function woocommerce_template_single_excerpt() {
755 wc_get_template( 'single-product/short-description.php' );
756 }
757 }
758 if ( ! function_exists( 'woocommerce_template_single_meta' ) ) {
759
760 761 762 763 764 765 766
767 function woocommerce_template_single_meta() {
768 wc_get_template( 'single-product/meta.php' );
769 }
770 }
771 if ( ! function_exists( 'woocommerce_template_single_sharing' ) ) {
772
773 774 775 776 777 778 779
780 function woocommerce_template_single_sharing() {
781 wc_get_template( 'single-product/share.php' );
782 }
783 }
784 if ( ! function_exists( 'woocommerce_show_product_sale_flash' ) ) {
785
786 787 788 789 790 791 792
793 function woocommerce_show_product_sale_flash() {
794 wc_get_template( 'single-product/sale-flash.php' );
795 }
796 }
797
798 if ( ! function_exists( 'woocommerce_template_single_add_to_cart' ) ) {
799
800 801 802 803 804 805 806
807 function woocommerce_template_single_add_to_cart() {
808 global $product;
809 do_action( 'woocommerce_' . $product->product_type . '_add_to_cart' );
810 }
811 }
812 if ( ! function_exists( 'woocommerce_simple_add_to_cart' ) ) {
813
814 815 816 817 818 819 820
821 function woocommerce_simple_add_to_cart() {
822 wc_get_template( 'single-product/add-to-cart/simple.php' );
823 }
824 }
825 if ( ! function_exists( 'woocommerce_grouped_add_to_cart' ) ) {
826
827 828 829 830 831 832 833
834 function woocommerce_grouped_add_to_cart() {
835 global $product;
836
837 wc_get_template( 'single-product/add-to-cart/grouped.php', array(
838 'grouped_product' => $product,
839 'grouped_products' => $product->get_children(),
840 'quantites_required' => false
841 ) );
842 }
843 }
844 if ( ! function_exists( 'woocommerce_variable_add_to_cart' ) ) {
845
846 847 848 849 850 851 852
853 function woocommerce_variable_add_to_cart() {
854 global $product;
855
856
857 wp_enqueue_script( 'wc-add-to-cart-variation' );
858
859
860 wc_get_template( 'single-product/add-to-cart/variable.php', array(
861 'available_variations' => $product->get_available_variations(),
862 'attributes' => $product->get_variation_attributes(),
863 'selected_attributes' => $product->get_variation_default_attributes()
864 ) );
865 }
866 }
867 if ( ! function_exists( 'woocommerce_external_add_to_cart' ) ) {
868
869 870 871 872 873 874 875
876 function woocommerce_external_add_to_cart() {
877 global $product;
878
879 if ( ! $product->get_product_url() )
880 return;
881
882 wc_get_template( 'single-product/add-to-cart/external.php', array(
883 'product_url' => $product->get_product_url(),
884 'button_text' => $product->single_add_to_cart_text()
885 ) );
886 }
887 }
888
889 if ( ! function_exists( 'woocommerce_quantity_input' ) ) {
890
891 892 893 894 895 896 897 898
899 function woocommerce_quantity_input( $args = array(), $product = null, $echo = true ) {
900 if ( is_null( $product ) )
901 $product = $GLOBALS['product'];
902
903 $defaults = array(
904 'input_name' => 'quantity',
905 'input_value' => '1',
906 'max_value' => apply_filters( 'woocommerce_quantity_input_max', '', $product ),
907 'min_value' => apply_filters( 'woocommerce_quantity_input_min', '', $product ),
908 'step' => apply_filters( 'woocommerce_quantity_input_step', '1', $product )
909 );
910
911 $args = apply_filters( 'woocommerce_quantity_input_args', wp_parse_args( $args, $defaults ), $product );
912
913 ob_start();
914
915 wc_get_template( 'global/quantity-input.php', $args );
916
917 if ( $echo ) {
918 echo ob_get_clean();
919 } else {
920 return ob_get_clean();
921 }
922 }
923 }
924
925 if ( ! function_exists( 'woocommerce_product_description_tab' ) ) {
926
927 928 929 930 931 932 933
934 function woocommerce_product_description_tab() {
935 wc_get_template( 'single-product/tabs/description.php' );
936 }
937 }
938 if ( ! function_exists( 'woocommerce_product_additional_information_tab' ) ) {
939
940 941 942 943 944 945 946
947 function woocommerce_product_additional_information_tab() {
948 wc_get_template( 'single-product/tabs/additional-information.php' );
949 }
950 }
951 if ( ! function_exists( 'woocommerce_product_reviews_tab' ) ) {
952
953 954 955 956 957 958 959
960 function woocommerce_product_reviews_tab() {
961 wc_get_template( 'single-product/tabs/reviews.php' );
962 }
963 }
964
965 if ( ! function_exists( 'woocommerce_default_product_tabs' ) ) {
966
967 968 969 970 971 972 973
974 function woocommerce_default_product_tabs( $tabs = array() ) {
975 global $product, $post;
976
977
978 if ( $post->post_content ) {
979 $tabs['description'] = array(
980 'title' => __( 'Description', 'woocommerce' ),
981 'priority' => 10,
982 'callback' => 'woocommerce_product_description_tab'
983 );
984 }
985
986
987 if ( $product && ( $product->has_attributes() || ( $product->enable_dimensions_display() && ( $product->has_dimensions() || $product->has_weight() ) ) ) ) {
988 $tabs['additional_information'] = array(
989 'title' => __( 'Additional Information', 'woocommerce' ),
990 'priority' => 20,
991 'callback' => 'woocommerce_product_additional_information_tab'
992 );
993 }
994
995
996 if ( comments_open() ) {
997 $tabs['reviews'] = array(
998 'title' => sprintf( __( 'Reviews (%d)', 'woocommerce' ), get_comments_number( $post->ID ) ),
999 'priority' => 30,
1000 'callback' => 'comments_template'
1001 );
1002 }
1003
1004 return $tabs;
1005 }
1006 }
1007
1008 if ( ! function_exists( 'woocommerce_sort_product_tabs' ) ) {
1009
1010 1011 1012 1013 1014 1015 1016
1017 function woocommerce_sort_product_tabs( $tabs = array() ) {
1018
1019
1020 if ( ! is_array( $tabs ) ) {
1021 trigger_error( "Function woocommerce_sort_product_tabs() expects an array as the first parameter. Defaulting to empty array." );
1022 $tabs = array( );
1023 }
1024
1025
1026 if ( ! function_exists( '_sort_priority_callback' ) ) {
1027 function _sort_priority_callback( $a, $b ) {
1028 if ( $a['priority'] == $b['priority'] )
1029 return 0;
1030 return ( $a['priority'] < $b['priority'] ) ? -1 : 1;
1031 }
1032 }
1033
1034 uasort( $tabs, '_sort_priority_callback' );
1035
1036 return $tabs;
1037 }
1038 }
1039
1040 if ( ! function_exists( 'woocommerce_comments' ) ) {
1041
1042 1043 1044 1045 1046 1047 1048
1049 function ( $comment, $args, $depth ) {
1050 $GLOBALS['comment'] = $comment;
1051 wc_get_template( 'single-product/review.php', array( 'comment' => $comment, 'args' => $args, 'depth' => $depth ) );
1052 }
1053 }
1054
1055 if ( ! function_exists( 'woocommerce_output_related_products' ) ) {
1056
1057 1058 1059 1060 1061 1062 1063
1064 function woocommerce_output_related_products() {
1065
1066 $args = array(
1067 'posts_per_page' => 2,
1068 'columns' => 2,
1069 'orderby' => 'rand'
1070 );
1071
1072 woocommerce_related_products( apply_filters( 'woocommerce_output_related_products_args', $args ) );
1073 }
1074 }
1075
1076 if ( ! function_exists( 'woocommerce_related_products' ) ) {
1077
1078 1079 1080 1081 1082 1083 1084 1085 1086
1087 function woocommerce_related_products( $args = array(), $columns = false, $orderby = false ) {
1088 if ( ! is_array( $args ) ) {
1089 _deprecated_argument( __FUNCTION__, '2.1', __( 'Use $args argument as an array instead. Deprecated argument will be removed in WC 2.2.', 'woocommerce' ) );
1090
1091 $argsvalue = $args;
1092
1093 $args = array(
1094 'posts_per_page' => $argsvalue,
1095 'columns' => $columns,
1096 'orderby' => $orderby,
1097 );
1098 }
1099
1100 $defaults = array(
1101 'posts_per_page' => 2,
1102 'columns' => 2,
1103 'orderby' => 'rand'
1104 );
1105
1106 $args = wp_parse_args( $args, $defaults );
1107
1108 wc_get_template( 'single-product/related.php', $args );
1109 }
1110 }
1111
1112 if ( ! function_exists( 'woocommerce_upsell_display' ) ) {
1113
1114 1115 1116 1117 1118 1119 1120 1121 1122
1123 function woocommerce_upsell_display( $posts_per_page = '-1', $columns = 2, $orderby = 'rand' ) {
1124 wc_get_template( 'single-product/up-sells.php', array(
1125 'posts_per_page' => $posts_per_page,
1126 'orderby' => apply_filters( 'woocommerce_upsells_orderby', $orderby ),
1127 'columns' => $columns
1128 ) );
1129 }
1130 }
1131
1132
1133
1134 if ( ! function_exists( 'woocommerce_shipping_calculator' ) ) {
1135
1136 1137 1138 1139 1140 1141 1142
1143 function woocommerce_shipping_calculator() {
1144 wc_get_template( 'cart/shipping-calculator.php' );
1145 }
1146 }
1147
1148 if ( ! function_exists( 'woocommerce_cart_totals' ) ) {
1149
1150 1151 1152 1153 1154 1155 1156
1157 function woocommerce_cart_totals() {
1158 wc_get_template( 'cart/cart-totals.php' );
1159 }
1160 }
1161
1162 if ( ! function_exists( 'woocommerce_cross_sell_display' ) ) {
1163
1164 1165 1166 1167 1168 1169 1170
1171 function woocommerce_cross_sell_display( $posts_per_page = 2, $columns = 2, $orderby = 'rand' ) {
1172 wc_get_template( 'cart/cross-sells.php', array(
1173 'posts_per_page' => $posts_per_page,
1174 'orderby' => $orderby,
1175 'columns' => $columns
1176 ) );
1177 }
1178 }
1179
1180
1181
1182 if ( ! function_exists( 'woocommerce_mini_cart' ) ) {
1183
1184 1185 1186 1187 1188 1189
1190 function woocommerce_mini_cart( $args = array() ) {
1191
1192 $defaults = array(
1193 'list_class' => ''
1194 );
1195
1196 $args = wp_parse_args( $args, $defaults );
1197
1198 wc_get_template( 'cart/mini-cart.php', $args );
1199 }
1200 }
1201
1202
1203
1204 if ( ! function_exists( 'woocommerce_login_form' ) ) {
1205
1206 1207 1208 1209 1210 1211 1212
1213 function woocommerce_login_form( $args = array() ) {
1214
1215 $defaults = array(
1216 'message' => '',
1217 'redirect' => '',
1218 'hidden' => false
1219 );
1220
1221 $args = wp_parse_args( $args, $defaults );
1222
1223 wc_get_template( 'global/form-login.php', $args );
1224 }
1225 }
1226
1227 if ( ! function_exists( 'woocommerce_checkout_login_form' ) ) {
1228
1229 1230 1231 1232 1233 1234 1235
1236 function woocommerce_checkout_login_form() {
1237 wc_get_template( 'checkout/form-login.php', array( 'checkout' => WC()->checkout() ) );
1238 }
1239 }
1240
1241 if ( ! function_exists( 'woocommerce_breadcrumb' ) ) {
1242
1243 1244 1245 1246 1247 1248
1249 function woocommerce_breadcrumb( $args = array() ) {
1250
1251 $defaults = apply_filters( 'woocommerce_breadcrumb_defaults', array(
1252 'delimiter' => ' / ',
1253 'wrap_before' => '<nav class="woocommerce-breadcrumb" ' . ( is_single() ? 'itemprop="breadcrumb"' : '' ) . '>',
1254 'wrap_after' => '</nav>',
1255 'before' => '',
1256 'after' => '',
1257 'home' => _x( 'Home', 'breadcrumb', 'woocommerce' ),
1258 ) );
1259
1260 $args = wp_parse_args( $args, $defaults );
1261
1262 wc_get_template( 'global/breadcrumb.php', $args );
1263 }
1264 }
1265
1266 if ( ! function_exists( 'woocommerce_order_review' ) ) {
1267
1268 1269 1270 1271 1272 1273 1274
1275 function woocommerce_order_review() {
1276 wc_get_template( 'checkout/review-order.php', array( 'checkout' => WC()->checkout() ) );
1277 }
1278 }
1279
1280 if ( ! function_exists( 'woocommerce_checkout_coupon_form' ) ) {
1281
1282 1283 1284 1285 1286 1287 1288
1289 function woocommerce_checkout_coupon_form() {
1290 wc_get_template( 'checkout/form-coupon.php', array( 'checkout' => WC()->checkout() ) );
1291 }
1292 }
1293
1294 if ( ! function_exists( 'woocommerce_products_will_display' ) ) {
1295
1296 1297 1298 1299 1300 1301 1302
1303 function woocommerce_products_will_display() {
1304 if ( is_shop() )
1305 return get_option( 'woocommerce_shop_page_display' ) != 'subcategories';
1306
1307 if ( ! is_product_taxonomy() )
1308 return false;
1309
1310 if ( is_search() || is_filtered() || is_paged() )
1311 return true;
1312
1313 $term = get_queried_object();
1314
1315 if ( is_product_category() ) {
1316 switch ( get_woocommerce_term_meta( $term->term_id, 'display_type', true ) ) {
1317 case 'subcategories' :
1318
1319 break;
1320 case 'products' :
1321 case 'both' :
1322 return true;
1323 break;
1324 default :
1325
1326 if ( get_option( 'woocommerce_category_archive_display' ) != 'subcategories' )
1327 return true;
1328 break;
1329 }
1330 }
1331
1332
1333 global $wpdb;
1334
1335 $parent_id = empty( $term->term_id ) ? 0 : $term->term_id;
1336 $taxonomy = empty( $term->taxonomy ) ? '' : $term->taxonomy;
1337 $products_will_display = true;
1338
1339 if ( ! $parent_id && ! $taxonomy ) {
1340 return true;
1341 }
1342
1343 if ( false === ( $products_will_display = get_transient( 'wc_products_will_display_' . $parent_id ) ) ) {
1344 $has_children = $wpdb->get_col( $wpdb->prepare( "SELECT term_id FROM {$wpdb->term_taxonomy} WHERE parent = %d AND taxonomy = %s", $parent_id, $taxonomy ) );
1345
1346 if ( $has_children ) {
1347
1348 if ( sizeof( get_objects_in_term( $has_children, $taxonomy ) ) > 0 ) {
1349 $products_will_display = false;
1350 } else {
1351
1352 foreach ( $has_children as $term ) {
1353 $children = get_term_children( $term, $taxonomy );
1354
1355 if ( sizeof( get_objects_in_term( $children, $taxonomy ) ) > 0 ) {
1356 $products_will_display = false;
1357 break;
1358 }
1359 }
1360 }
1361 } else {
1362 $products_will_display = true;
1363 }
1364 }
1365
1366 set_transient( 'wc_products_will_display_' . $parent_id, $products_will_display, YEAR_IN_SECONDS );
1367
1368 return $products_will_display;
1369 }
1370 }
1371
1372 if ( ! function_exists( 'woocommerce_product_subcategories' ) ) {
1373
1374 1375 1376 1377 1378 1379 1380 1381
1382 function woocommerce_product_subcategories( $args = array() ) {
1383 global $wp_query;
1384
1385 $defaults = array(
1386 'before' => '',
1387 'after' => '',
1388 'force_display' => false
1389 );
1390
1391 $args = wp_parse_args( $args, $defaults );
1392
1393 extract( $args );
1394
1395
1396 if ( ! is_main_query() && ! $force_display ) return;
1397
1398
1399 if ( is_search() || is_filtered() || is_paged() || ( ! is_product_category() && ! is_shop() ) ) return;
1400
1401
1402 if ( is_shop() && get_option( 'woocommerce_shop_page_display' ) == '' ) return;
1403
1404
1405 $term = get_queried_object();
1406 $parent_id = empty( $term->term_id ) ? 0 : $term->term_id;
1407
1408 if ( is_product_category() ) {
1409 $display_type = get_woocommerce_term_meta( $term->term_id, 'display_type', true );
1410
1411 switch ( $display_type ) {
1412 case 'products' :
1413 return;
1414 break;
1415 case '' :
1416 if ( get_option( 'woocommerce_category_archive_display' ) == '' )
1417 return;
1418 break;
1419 }
1420 }
1421
1422
1423 $args = apply_filters( 'woocommerce_product_subcategories_args', array(
1424 'child_of' => $parent_id,
1425 'menu_order' => 'ASC',
1426 'hide_empty' => 1,
1427 'hierarchical' => 1,
1428 'taxonomy' => 'product_cat',
1429 'pad_counts' => 1
1430 ) );
1431
1432 $product_categories = get_categories( $args );
1433 $product_category_found = false;
1434
1435 if ( $product_categories ) {
1436
1437 foreach ( $product_categories as $category ) {
1438
1439 if ( $category->parent != $parent_id ) {
1440 continue;
1441 }
1442 if ( $args['hide_empty'] && $category->count == 0 ) {
1443 continue;
1444 }
1445
1446 if ( ! $product_category_found ) {
1447
1448 $product_category_found = true;
1449 echo $before;
1450 }
1451
1452 wc_get_template( 'content-product_cat.php', array(
1453 'category' => $category
1454 ) );
1455
1456 }
1457
1458 }
1459
1460
1461 if ( $product_category_found ) {
1462 if ( is_product_category() ) {
1463 $display_type = get_woocommerce_term_meta( $term->term_id, 'display_type', true );
1464
1465 switch ( $display_type ) {
1466 case 'subcategories' :
1467 $wp_query->post_count = 0;
1468 $wp_query->max_num_pages = 0;
1469 break;
1470 case '' :
1471 if ( get_option( 'woocommerce_category_archive_display' ) == 'subcategories' ) {
1472 $wp_query->post_count = 0;
1473 $wp_query->max_num_pages = 0;
1474 }
1475 break;
1476 }
1477 }
1478 if ( is_shop() && get_option( 'woocommerce_shop_page_display' ) == 'subcategories' ) {
1479 $wp_query->post_count = 0;
1480 $wp_query->max_num_pages = 0;
1481 }
1482
1483 echo $after;
1484 return true;
1485 }
1486
1487 }
1488 }
1489
1490 if ( ! function_exists( 'woocommerce_subcategory_thumbnail' ) ) {
1491
1492 1493 1494 1495 1496 1497 1498 1499
1500 function woocommerce_subcategory_thumbnail( $category ) {
1501 $small_thumbnail_size = apply_filters( 'single_product_small_thumbnail_size', 'shop_catalog' );
1502 $dimensions = wc_get_image_size( $small_thumbnail_size );
1503 $thumbnail_id = get_woocommerce_term_meta( $category->term_id, 'thumbnail_id', true );
1504
1505 if ( $thumbnail_id ) {
1506 $image = wp_get_attachment_image_src( $thumbnail_id, $small_thumbnail_size );
1507 $image = $image[0];
1508 } else {
1509 $image = wc_placeholder_img_src();
1510 }
1511
1512 if ( $image ) {
1513
1514
1515 $image = str_replace( ' ', '%20', $image );
1516
1517 echo '<img src="' . esc_url( $image ) . '" alt="' . esc_attr( $category->name ) . '" width="' . esc_attr( $dimensions['width'] ) . '" height="' . esc_attr( $dimensions['height'] ) . '" />';
1518 }
1519 }
1520 }
1521
1522 if ( ! function_exists( 'woocommerce_order_details_table' ) ) {
1523
1524 1525 1526 1527 1528 1529 1530 1531
1532 function woocommerce_order_details_table( $order_id ) {
1533 if ( ! $order_id ) return;
1534
1535 wc_get_template( 'order/order-details.php', array(
1536 'order_id' => $order_id
1537 ) );
1538 }
1539 }
1540
1541
1542 if ( ! function_exists( 'woocommerce_order_again_button' ) ) {
1543
1544 1545 1546 1547 1548 1549 1550 1551
1552 function woocommerce_order_again_button( $order ) {
1553 if ( ! $order || $order->status != 'completed' )
1554 return;
1555
1556 ?>
1557 <p class="order-again">
1558 <a href="<?php echo wp_nonce_url( add_query_arg( 'order_again', $order->id ) , 'woocommerce-order_again' ); ?>" class="button"><?php _e( 'Order Again', 'woocommerce' ); ?></a>
1559 </p>
1560 <?php
1561 }
1562 }
1563
1564
1565
1566 if ( ! function_exists( 'woocommerce_form_field' ) ) {
1567
1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578
1579 function woocommerce_form_field( $key, $args, $value = null ) {
1580 $defaults = array(
1581 'type' => 'text',
1582 'label' => '',
1583 'placeholder' => '',
1584 'maxlength' => false,
1585 'required' => false,
1586 'class' => array(),
1587 'label_class' => array(),
1588 'input_class' => array(),
1589 'return' => false,
1590 'options' => array(),
1591 'custom_attributes' => array(),
1592 'validate' => array(),
1593 'default' => '',
1594 );
1595
1596 $args = wp_parse_args( $args, $defaults );
1597
1598 if ( ( ! empty( $args['clear'] ) ) ) $after = '<div class="clear"></div>'; else $after = '';
1599
1600 if ( $args['required'] ) {
1601 $args['class'][] = 'validate-required';
1602 $required = ' <abbr class="required" title="' . esc_attr__( 'required', 'woocommerce' ) . '">*</abbr>';
1603 } else {
1604 $required = '';
1605 }
1606
1607 $args['maxlength'] = ( $args['maxlength'] ) ? 'maxlength="' . absint( $args['maxlength'] ) . '"' : '';
1608
1609 if ( is_string( $args['label_class'] ) )
1610 $args['label_class'] = array( $args['label_class'] );
1611
1612 if ( is_null( $value ) )
1613 $value = $args['default'];
1614
1615
1616 $custom_attributes = array();
1617
1618 if ( ! empty( $args['custom_attributes'] ) && is_array( $args['custom_attributes'] ) )
1619 foreach ( $args['custom_attributes'] as $attribute => $attribute_value )
1620 $custom_attributes[] = esc_attr( $attribute ) . '="' . esc_attr( $attribute_value ) . '"';
1621
1622 if ( ! empty( $args['validate'] ) )
1623 foreach( $args['validate'] as $validate )
1624 $args['class'][] = 'validate-' . $validate;
1625
1626 switch ( $args['type'] ) {
1627 case "country" :
1628
1629 $countries = $key == 'shipping_country' ? WC()->countries->get_shipping_countries() : WC()->countries->get_allowed_countries();
1630
1631 if ( sizeof( $countries ) == 1 ) {
1632
1633 $field = '<p class="form-row ' . esc_attr( implode( ' ', $args['class'] ) ) .'" id="' . esc_attr( $key ) . '_field">';
1634
1635 if ( $args['label'] )
1636 $field .= '<label class="' . implode( ' ', $args['label_class'] ) .'">' . $args['label'] . '</label>';
1637
1638 $field .= '<strong>' . current( array_values( $countries ) ) . '</strong>';
1639
1640 $field .= '<input type="hidden" name="' . esc_attr( $key ) . '" id="' . esc_attr( $key ) . '" value="' . current( array_keys($countries ) ) . '" ' . implode( ' ', $custom_attributes ) . ' class="country_to_state" />';
1641
1642 $field .= '</p>' . $after;
1643
1644 } else {
1645
1646 $field = '<p class="form-row ' . esc_attr( implode( ' ', $args['class'] ) ) .'" id="' . esc_attr( $key ) . '_field">'
1647 . '<label for="' . esc_attr( $key ) . '" class="' . implode( ' ', $args['label_class'] ) .'">' . $args['label'] . $required . '</label>'
1648 . '<select name="' . esc_attr( $key ) . '" id="' . esc_attr( $key ) . '" class="country_to_state country_select" ' . implode( ' ', $custom_attributes ) . '>'
1649 . '<option value="">'.__( 'Select a country…', 'woocommerce' ) .'</option>';
1650
1651 foreach ( $countries as $ckey => $cvalue )
1652 $field .= '<option value="' . esc_attr( $ckey ) . '" '.selected( $value, $ckey, false ) .'>'.__( $cvalue, 'woocommerce' ) .'</option>';
1653
1654 $field .= '</select>';
1655
1656 $field .= '<noscript><input type="submit" name="woocommerce_checkout_update_totals" value="' . __( 'Update country', 'woocommerce' ) . '" /></noscript>';
1657
1658 $field .= '</p>' . $after;
1659
1660 }
1661
1662 break;
1663 case "state" :
1664
1665
1666 $country_key = $key == 'billing_state'? 'billing_country' : 'shipping_country';
1667
1668 if ( isset( $_POST[ $country_key ] ) ) {
1669 $current_cc = wc_clean( $_POST[ $country_key ] );
1670 } elseif ( is_user_logged_in() ) {
1671 $current_cc = get_user_meta( get_current_user_id() , $country_key, true );
1672 if ( ! $current_cc) {
1673 $current_cc = apply_filters('default_checkout_country', (WC()->customer->get_country()) ? WC()->customer->get_country() : WC()->countries->get_base_country());
1674 }
1675 } elseif ( $country_key == 'billing_country' ) {
1676 $current_cc = apply_filters('default_checkout_country', (WC()->customer->get_country()) ? WC()->customer->get_country() : WC()->countries->get_base_country());
1677 } else {
1678 $current_cc = apply_filters('default_checkout_country', (WC()->customer->get_shipping_country()) ? WC()->customer->get_shipping_country() : WC()->countries->get_base_country());
1679 }
1680
1681 $states = WC()->countries->get_states( $current_cc );
1682
1683 if ( is_array( $states ) && empty( $states ) ) {
1684
1685 $field = '<p class="form-row ' . esc_attr( implode( ' ', $args['class'] ) ) .'" id="' . esc_attr( $key ) . '_field" style="display: none">';
1686
1687 if ( $args['label'] )
1688 $field .= '<label for="' . esc_attr( $key ) . '" class="' . implode( ' ', $args['label_class'] ) .'">' . $args['label'] . $required . '</label>';
1689 $field .= '<input type="hidden" class="hidden" name="' . esc_attr( $key ) . '" id="' . esc_attr( $key ) . '" value="" ' . implode( ' ', $custom_attributes ) . ' placeholder="' . esc_attr( $args['placeholder'] ) . '" />';
1690 $field .= '</p>' . $after;
1691
1692 } elseif ( is_array( $states ) ) {
1693
1694 $field = '<p class="form-row ' . esc_attr( implode( ' ', $args['class'] ) ) .'" id="' . esc_attr( $key ) . '_field">';
1695
1696 if ( $args['label'] )
1697 $field .= '<label for="' . esc_attr( $key ) . '" class="' . implode( ' ', $args['label_class'] ) .'">' . $args['label']. $required . '</label>';
1698 $field .= '<select name="' . esc_attr( $key ) . '" id="' . esc_attr( $key ) . '" class="state_select" ' . implode( ' ', $custom_attributes ) . ' placeholder="' . esc_attr( $args['placeholder'] ) . '">
1699 <option value="">'.__( 'Select a state…', 'woocommerce' ) .'</option>';
1700
1701 foreach ( $states as $ckey => $cvalue )
1702 $field .= '<option value="' . esc_attr( $ckey ) . '" '.selected( $value, $ckey, false ) .'>'.__( $cvalue, 'woocommerce' ) .'</option>';
1703
1704 $field .= '</select>';
1705 $field .= '</p>' . $after;
1706
1707 } else {
1708
1709 $field = '<p class="form-row ' . esc_attr( implode( ' ', $args['class'] ) ) .'" id="' . esc_attr( $key ) . '_field">';
1710
1711 if ( $args['label'] )
1712 $field .= '<label for="' . esc_attr( $key ) . '" class="' . implode( ' ', $args['label_class'] ) .'">' . $args['label']. $required . '</label>';
1713 $field .= '<input type="text" class="input-text ' . implode( ' ', $args['input_class'] ) .'" value="' . esc_attr( $value ) . '" placeholder="' . esc_attr( $args['placeholder'] ) . '" name="' . esc_attr( $key ) . '" id="' . esc_attr( $key ) . '" ' . implode( ' ', $custom_attributes ) . ' />';
1714 $field .= '</p>' . $after;
1715
1716 }
1717
1718 break;
1719 case "textarea" :
1720
1721 $field = '<p class="form-row ' . esc_attr( implode( ' ', $args['class'] ) ) .'" id="' . esc_attr( $key ) . '_field">';
1722
1723 if ( $args['label'] )
1724 $field .= '<label for="' . esc_attr( $key ) . '" class="' . implode( ' ', $args['label_class'] ) .'">' . $args['label']. $required . '</label>';
1725
1726 $field .= '<textarea name="' . esc_attr( $key ) . '" class="input-text ' . implode( ' ', $args['input_class'] ) .'" id="' . esc_attr( $key ) . '" placeholder="' . esc_attr( $args['placeholder'] ) . '"' . ( empty( $args['custom_attributes']['rows'] ) ? ' rows="2"' : '' ) . ( empty( $args['custom_attributes']['cols'] ) ? ' cols="5"' : '' ) . implode( ' ', $custom_attributes ) . '>'. esc_textarea( $value ) .'</textarea>
1727 </p>' . $after;
1728
1729 break;
1730 case "checkbox" :
1731
1732 $field = '<p class="form-row ' . esc_attr( implode( ' ', $args['class'] ) ) .'" id="' . esc_attr( $key ) . '_field">
1733 <input type="' . esc_attr( $args['type'] ) . '" class="input-checkbox" name="' . esc_attr( $key ) . '" id="' . esc_attr( $key ) . '" value="1" '.checked( $value, 1, false ) .' />
1734 <label for="' . esc_attr( $key ) . '" class="checkbox ' . implode( ' ', $args['label_class'] ) .'" ' . implode( ' ', $custom_attributes ) . '>' . $args['label'] . $required . '</label>
1735 </p>' . $after;
1736
1737 break;
1738 case "password" :
1739
1740 $field = '<p class="form-row ' . esc_attr( implode( ' ', $args['class'] ) ) .'" id="' . esc_attr( $key ) . '_field">';
1741
1742 if ( $args['label'] )
1743 $field .= '<label for="' . esc_attr( $key ) . '" class="' . implode( ' ', $args['label_class'] ) .'">' . $args['label']. $required . '</label>';
1744
1745 $field .= '<input type="password" class="input-text ' . implode( ' ', $args['input_class'] ) .'" name="' . esc_attr( $key ) . '" id="' . esc_attr( $key ) . '" placeholder="' . esc_attr( $args['placeholder'] ) . '" value="' . esc_attr( $value ) . '" ' . implode( ' ', $custom_attributes ) . ' />
1746 </p>' . $after;
1747
1748 break;
1749 case "text" :
1750
1751 $field = '<p class="form-row ' . esc_attr( implode( ' ', $args['class'] ) ) .'" id="' . esc_attr( $key ) . '_field">';
1752
1753 if ( $args['label'] )
1754 $field .= '<label for="' . esc_attr( $key ) . '" class="' . implode( ' ', $args['label_class'] ) .'">' . $args['label'] . $required . '</label>';
1755
1756 $field .= '<input type="text" class="input-text ' . implode( ' ', $args['input_class'] ) .'" name="' . esc_attr( $key ) . '" id="' . esc_attr( $key ) . '" placeholder="' . esc_attr( $args['placeholder'] ) . '" '.$args['maxlength'].' value="' . esc_attr( $value ) . '" ' . implode( ' ', $custom_attributes ) . ' />
1757 </p>' . $after;
1758
1759 break;
1760 case "select" :
1761
1762 $options = '';
1763
1764 if ( ! empty( $args['options'] ) )
1765 foreach ( $args['options'] as $option_key => $option_text )
1766 $options .= '<option value="' . esc_attr( $option_key ) . '" '. selected( $value, $option_key, false ) . '>' . esc_attr( $option_text ) .'</option>';
1767
1768 $field = '<p class="form-row ' . esc_attr( implode( ' ', $args['class'] ) ) .'" id="' . esc_attr( $key ) . '_field">';
1769
1770 if ( $args['label'] )
1771 $field .= '<label for="' . esc_attr( $key ) . '" class="' . implode( ' ', $args['label_class'] ) .'">' . $args['label']. $required . '</label>';
1772
1773 $field .= '<select name="' . esc_attr( $key ) . '" id="' . esc_attr( $key ) . '" class="select" ' . implode( ' ', $custom_attributes ) . '>
1774 ' . $options . '
1775 </select>
1776 </p>' . $after;
1777
1778 break;
1779 default :
1780
1781 $field = apply_filters( 'woocommerce_form_field_' . $args['type'], '', $key, $args, $value );
1782
1783 break;
1784 }
1785
1786 if ( $args['return'] ) return $field; else echo $field;
1787 }
1788 }
1789
1790 if ( ! function_exists( 'get_product_search_form' ) ) {
1791
1792 1793 1794 1795 1796 1797 1798 1799 1800
1801 function get_product_search_form( $echo = true ) {
1802 do_action( 'get_product_search_form' );
1803
1804 $search_form_template = locate_template( 'product-searchform.php' );
1805 if ( '' != $search_form_template ) {
1806 require $search_form_template;
1807 return;
1808 }
1809
1810 $form = '<form role="search" method="get" id="searchform" action="' . esc_url( home_url( '/' ) ) . '">
1811 <div>
1812 <label class="screen-reader-text" for="s">' . __( 'Search for:', 'woocommerce' ) . '</label>
1813 <input type="text" value="' . get_search_query() . '" name="s" id="s" placeholder="' . __( 'Search for products', 'woocommerce' ) . '" />
1814 <input type="submit" id="searchsubmit" value="'. esc_attr__( 'Search', 'woocommerce' ) .'" />
1815 <input type="hidden" name="post_type" value="product" />
1816 </div>
1817 </form>';
1818
1819 if ( $echo )
1820 echo apply_filters( 'get_product_search_form', $form );
1821 else
1822 return apply_filters( 'get_product_search_form', $form );
1823 }
1824 }
1825