PageRenderTime 55ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 0ms

/woocommerce-template.php

https://github.com/alexcsandru/woocommerce
PHP | 1500 lines | 742 code | 277 blank | 481 comment | 178 complexity | 22aba0ed7c3f996d7232f62fd3366c62 MD5 | raw file
Possible License(s): GPL-3.0
  1. <?php
  2. /**
  3. * WooCommerce Template Functions
  4. *
  5. * Functions used in the template files to output content - in most cases hooked in via the template actions. All functions are pluggable.
  6. *
  7. * @author WooThemes
  8. * @category Core
  9. * @package WooCommerce/Templates
  10. * @version 1.6.4
  11. */
  12. if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
  13. /** Template pages ********************************************************/
  14. if ( ! function_exists( 'woocommerce_content' ) ) {
  15. /**
  16. * Output WooCommerce content.
  17. *
  18. * This function is only used in the optional 'woocommerce.php' template
  19. * which people can add to their themes to add basic woocommerce support
  20. * without hooks or modifying core templates.
  21. *
  22. * @access public
  23. * @return void
  24. */
  25. function woocommerce_content() {
  26. if ( is_singular( 'product' ) ) {
  27. while ( have_posts() ) : the_post();
  28. woocommerce_get_template_part( 'content', 'single-product' );
  29. endwhile;
  30. } else {
  31. ?><h1 class="page-title"><?php woocommerce_page_title(); ?></h1>
  32. <?php do_action( 'woocommerce_archive_description' ); ?>
  33. <?php if ( have_posts() ) : ?>
  34. <?php do_action('woocommerce_before_shop_loop'); ?>
  35. <?php woocommerce_product_loop_start(); ?>
  36. <?php woocommerce_product_subcategories(); ?>
  37. <?php while ( have_posts() ) : the_post(); ?>
  38. <?php woocommerce_get_template_part( 'content', 'product' ); ?>
  39. <?php endwhile; // end of the loop. ?>
  40. <?php woocommerce_product_loop_end(); ?>
  41. <?php do_action('woocommerce_after_shop_loop'); ?>
  42. <?php elseif ( ! woocommerce_product_subcategories( array( 'before' => woocommerce_product_loop_start( false ), 'after' => woocommerce_product_loop_end( false ) ) ) ) : ?>
  43. <?php woocommerce_get_template( 'loop/no-products-found.php' ); ?>
  44. <?php endif;
  45. }
  46. }
  47. }
  48. if ( ! function_exists( 'woocommerce_single_product_content' ) ) {
  49. /**
  50. * woocommerce_single_product_content function.
  51. *
  52. * @access public
  53. * @return void
  54. * @deprecated 1.6
  55. */
  56. function woocommerce_single_product_content() {
  57. _deprecated_function( __FUNCTION__, '1.6' );
  58. woocommerce_content();
  59. }
  60. }
  61. if ( ! function_exists( 'woocommerce_archive_product_content' ) ) {
  62. /**
  63. * woocommerce_archive_product_content function.
  64. *
  65. * @access public
  66. * @return void
  67. * @deprecated 1.6
  68. */
  69. function woocommerce_archive_product_content() {
  70. _deprecated_function( __FUNCTION__, '1.6' );
  71. woocommerce_content();
  72. }
  73. }
  74. if ( ! function_exists( 'woocommerce_product_taxonomy_content' ) ) {
  75. /**
  76. * woocommerce_product_taxonomy_content function.
  77. *
  78. * @access public
  79. * @return void
  80. * @deprecated 1.6
  81. */
  82. function woocommerce_product_taxonomy_content() {
  83. _deprecated_function( __FUNCTION__, '1.6' );
  84. woocommerce_content();
  85. }
  86. }
  87. /** Global ****************************************************************/
  88. if ( ! function_exists( 'woocommerce_output_content_wrapper' ) ) {
  89. /**
  90. * Output the start of the page wrapper.
  91. *
  92. * @access public
  93. * @return void
  94. */
  95. function woocommerce_output_content_wrapper() {
  96. woocommerce_get_template( 'shop/wrapper-start.php' );
  97. }
  98. }
  99. if ( ! function_exists( 'woocommerce_output_content_wrapper_end' ) ) {
  100. /**
  101. * Output the end of the page wrapper.
  102. *
  103. * @access public
  104. * @return void
  105. */
  106. function woocommerce_output_content_wrapper_end() {
  107. woocommerce_get_template( 'shop/wrapper-end.php' );
  108. }
  109. }
  110. if ( ! function_exists( 'woocommerce_show_messages' ) ) {
  111. /**
  112. * Show messages on the frontend.
  113. *
  114. * @access public
  115. * @return void
  116. */
  117. function woocommerce_show_messages() {
  118. global $woocommerce;
  119. if ( $woocommerce->error_count() > 0 )
  120. woocommerce_get_template( 'shop/errors.php', array(
  121. 'errors' => $woocommerce->get_errors()
  122. ) );
  123. if ( $woocommerce->message_count() > 0 )
  124. woocommerce_get_template( 'shop/messages.php', array(
  125. 'messages' => $woocommerce->get_messages()
  126. ) );
  127. $woocommerce->clear_messages();
  128. }
  129. }
  130. if ( ! function_exists( 'woocommerce_get_sidebar' ) ) {
  131. /**
  132. * Get the shop sidebar template.
  133. *
  134. * @access public
  135. * @return void
  136. */
  137. function woocommerce_get_sidebar() {
  138. woocommerce_get_template( 'shop/sidebar.php' );
  139. }
  140. }
  141. if ( ! function_exists( 'woocommerce_demo_store' ) ) {
  142. /**
  143. * Adds a demo store banner to the site if enabled
  144. *
  145. * @access public
  146. * @return void
  147. */
  148. function woocommerce_demo_store() {
  149. if ( get_option( 'woocommerce_demo_store' ) == 'no' )
  150. return;
  151. $notice = get_option( 'woocommerce_demo_store_notice' );
  152. if ( empty( $notice ) )
  153. $notice = __( 'This is a demo store for testing purposes &mdash; no orders shall be fulfilled.', 'woocommerce' );
  154. echo apply_filters( 'woocommerce_demo_store', '<p class="demo_store">' . $notice . '</p>' );
  155. }
  156. }
  157. /** Loop ******************************************************************/
  158. if ( ! function_exists( 'woocommerce_page_title' ) ) {
  159. /**
  160. * woocommerce_page_title function.
  161. *
  162. * @access public
  163. * @return void
  164. */
  165. function woocommerce_page_title() {
  166. if ( is_search() ) {
  167. $page_title = sprintf( __( 'Search Results: &ldquo;%s&rdquo;', 'woocommerce' ), get_search_query() );
  168. if ( get_query_var( 'paged' ) )
  169. $page_title .= sprintf( __( '&nbsp;&ndash; Page %s', 'woocommerce' ), get_query_var( 'paged' ) );
  170. } elseif ( is_tax() ) {
  171. $page_title = single_term_title( "", false );
  172. } else {
  173. $shop_page_id = woocommerce_get_page_id( 'shop' );
  174. $page_title = apply_filters( 'the_title', ( $shop_page_title = get_option( 'woocommerce_shop_page_title' ) ) ? $shop_page_title : get_the_title( $shop_page_id ), $shop_page_id );
  175. }
  176. echo apply_filters( 'woocommerce_page_title', $page_title );
  177. }
  178. }
  179. if ( ! function_exists( 'woocommerce_product_loop_start' ) ) {
  180. /**
  181. * Output the start of a product loop. By default this is a UL
  182. *
  183. * @access public
  184. * @return void
  185. */
  186. function woocommerce_product_loop_start( $echo = true ) {
  187. ob_start();
  188. woocommerce_get_template( 'loop/loop-start.php' );
  189. if ( $echo )
  190. echo ob_get_clean();
  191. else
  192. return ob_get_clean();
  193. }
  194. }
  195. if ( ! function_exists( 'woocommerce_product_loop_end' ) ) {
  196. /**
  197. * Output the end of a product loop. By default this is a UL
  198. *
  199. * @access public
  200. * @return void
  201. */
  202. function woocommerce_product_loop_end( $echo = true ) {
  203. ob_start();
  204. woocommerce_get_template( 'loop/loop-end.php' );
  205. if ( $echo )
  206. echo ob_get_clean();
  207. else
  208. return ob_get_clean();
  209. }
  210. }
  211. if ( ! function_exists( 'woocommerce_taxonomy_archive_description' ) ) {
  212. /**
  213. * Show an archive description on taxonomy archives
  214. *
  215. * @access public
  216. * @subpackage Archives
  217. * @return void
  218. */
  219. function woocommerce_taxonomy_archive_description() {
  220. if ( is_tax( array( 'product_cat', 'product_tag' ) ) && get_query_var( 'paged' ) == 0 ) {
  221. $description = term_description();
  222. if ( $description ) {
  223. echo '<div class="term-description">' . wpautop( wptexturize( $description ) ) . '</div>';
  224. }
  225. }
  226. }
  227. }
  228. if ( ! function_exists( 'woocommerce_product_archive_description' ) ) {
  229. /**
  230. * Show a shop page description on product archives
  231. *
  232. * @access public
  233. * @subpackage Archives
  234. * @return void
  235. */
  236. function woocommerce_product_archive_description() {
  237. if ( is_post_type_archive( 'product' ) && get_query_var( 'paged' ) == 0 ) {
  238. $shop_page = get_post( woocommerce_get_page_id( 'shop' ) );
  239. $description = apply_filters( 'the_content', $shop_page->post_content );
  240. if ( $description ) {
  241. echo '<div class="page-description">' . $description . '</div>';
  242. }
  243. }
  244. }
  245. }
  246. if ( ! function_exists( 'woocommerce_template_loop_add_to_cart' ) ) {
  247. /**
  248. * Get the add to cart template for the loop.
  249. *
  250. * @access public
  251. * @subpackage Loop
  252. * @return void
  253. */
  254. function woocommerce_template_loop_add_to_cart() {
  255. woocommerce_get_template( 'loop/add-to-cart.php' );
  256. }
  257. }
  258. if ( ! function_exists( 'woocommerce_template_loop_product_thumbnail' ) ) {
  259. /**
  260. * Get the product thumbnail for the loop.
  261. *
  262. * @access public
  263. * @subpackage Loop
  264. * @return void
  265. */
  266. function woocommerce_template_loop_product_thumbnail() {
  267. echo woocommerce_get_product_thumbnail();
  268. }
  269. }
  270. if ( ! function_exists( 'woocommerce_template_loop_price' ) ) {
  271. /**
  272. * Get the product price for the loop.
  273. *
  274. * @access public
  275. * @subpackage Loop
  276. * @return void
  277. */
  278. function woocommerce_template_loop_price() {
  279. woocommerce_get_template( 'loop/price.php' );
  280. }
  281. }
  282. if ( ! function_exists( 'woocommerce_template_loop_rating' ) ) {
  283. /**
  284. * Display the average rating in the loop
  285. *
  286. * @access public
  287. * @subpackage Loop
  288. * @return void
  289. */
  290. function woocommerce_template_loop_rating() {
  291. woocommerce_get_template( 'loop/rating.php' );
  292. }
  293. }
  294. if ( ! function_exists( 'woocommerce_show_product_loop_sale_flash' ) ) {
  295. /**
  296. * Get the sale flash for the loop.
  297. *
  298. * @access public
  299. * @subpackage Loop
  300. * @return void
  301. */
  302. function woocommerce_show_product_loop_sale_flash() {
  303. woocommerce_get_template( 'loop/sale-flash.php' );
  304. }
  305. }
  306. if ( ! function_exists( 'woocommerce_reset_loop' ) ) {
  307. /**
  308. * Reset the loop's index and columns when we're done outputting a product loop.
  309. *
  310. * @access public
  311. * @subpackage Loop
  312. * @return void
  313. */
  314. function woocommerce_reset_loop() {
  315. global $woocommerce_loop;
  316. // Reset loop/columns globals when starting a new loop
  317. $woocommerce_loop['loop'] = $woocommerce_loop['column'] = '';
  318. }
  319. }
  320. add_filter( 'loop_end', 'woocommerce_reset_loop' );
  321. if ( ! function_exists( 'woocommerce_get_product_thumbnail' ) ) {
  322. /**
  323. * Get the product thumbnail, or the placeholder if not set.
  324. *
  325. * @access public
  326. * @subpackage Loop
  327. * @param string $size (default: 'shop_catalog')
  328. * @param int $placeholder_width (default: 0)
  329. * @param int $placeholder_height (default: 0)
  330. * @return string
  331. */
  332. function woocommerce_get_product_thumbnail( $size = 'shop_catalog', $placeholder_width = 0, $placeholder_height = 0 ) {
  333. global $post;
  334. if ( has_post_thumbnail() )
  335. return get_the_post_thumbnail( $post->ID, $size );
  336. elseif ( woocommerce_placeholder_img_src() )
  337. return woocommerce_placeholder_img( $size );
  338. }
  339. }
  340. if ( ! function_exists( 'woocommerce_result_count' ) ) {
  341. /**
  342. * Output the result count text (Showing x - x of x results).
  343. *
  344. * @access public
  345. * @subpackage Loop
  346. * @return void
  347. */
  348. function woocommerce_result_count() {
  349. woocommerce_get_template( 'loop/result-count.php' );
  350. }
  351. }
  352. if ( ! function_exists( 'woocommerce_catalog_ordering' ) ) {
  353. /**
  354. * Output the product sorting options.
  355. *
  356. * @access public
  357. * @subpackage Loop
  358. * @return void
  359. */
  360. function woocommerce_catalog_ordering() {
  361. global $woocommerce;
  362. $orderby = isset( $_GET['orderby'] ) ? woocommerce_clean( $_GET['orderby'] ) : apply_filters( 'woocommerce_default_catalog_orderby', get_option( 'woocommerce_default_catalog_orderby' ) );
  363. woocommerce_get_template( 'loop/orderby.php', array( 'orderby' => $orderby ) );
  364. }
  365. }
  366. if ( ! function_exists( 'woocommerce_pagination' ) ) {
  367. /**
  368. * Output the pagination.
  369. *
  370. * @access public
  371. * @subpackage Loop
  372. * @return void
  373. */
  374. function woocommerce_pagination() {
  375. woocommerce_get_template( 'loop/pagination.php' );
  376. }
  377. }
  378. /** Single Product ********************************************************/
  379. if ( ! function_exists( 'woocommerce_show_product_images' ) ) {
  380. /**
  381. * Output the product image before the single product summary.
  382. *
  383. * @access public
  384. * @subpackage Product
  385. * @return void
  386. */
  387. function woocommerce_show_product_images() {
  388. woocommerce_get_template( 'single-product/product-image.php' );
  389. }
  390. }
  391. if ( ! function_exists( 'woocommerce_show_product_thumbnails' ) ) {
  392. /**
  393. * Output the product thumbnails.
  394. *
  395. * @access public
  396. * @subpackage Product
  397. * @return void
  398. */
  399. function woocommerce_show_product_thumbnails() {
  400. woocommerce_get_template( 'single-product/product-thumbnails.php' );
  401. }
  402. }
  403. if ( ! function_exists( 'woocommerce_output_product_data_tabs' ) ) {
  404. /**
  405. * Output the product tabs.
  406. *
  407. * @access public
  408. * @subpackage Product/Tabs
  409. * @return void
  410. */
  411. function woocommerce_output_product_data_tabs() {
  412. woocommerce_get_template( 'single-product/tabs/tabs.php' );
  413. }
  414. }
  415. if ( ! function_exists( 'woocommerce_template_single_title' ) ) {
  416. /**
  417. * Output the product title.
  418. *
  419. * @access public
  420. * @subpackage Product
  421. * @return void
  422. */
  423. function woocommerce_template_single_title() {
  424. woocommerce_get_template( 'single-product/title.php' );
  425. }
  426. }
  427. if ( ! function_exists( 'woocommerce_template_single_price' ) ) {
  428. /**
  429. * Output the product price.
  430. *
  431. * @access public
  432. * @subpackage Product
  433. * @return void
  434. */
  435. function woocommerce_template_single_price() {
  436. woocommerce_get_template( 'single-product/price.php' );
  437. }
  438. }
  439. if ( ! function_exists( 'woocommerce_template_single_excerpt' ) ) {
  440. /**
  441. * Output the product short description (excerpt).
  442. *
  443. * @access public
  444. * @subpackage Product
  445. * @return void
  446. */
  447. function woocommerce_template_single_excerpt() {
  448. woocommerce_get_template( 'single-product/short-description.php' );
  449. }
  450. }
  451. if ( ! function_exists( 'woocommerce_template_single_meta' ) ) {
  452. /**
  453. * Output the product meta.
  454. *
  455. * @access public
  456. * @subpackage Product
  457. * @return void
  458. */
  459. function woocommerce_template_single_meta() {
  460. woocommerce_get_template( 'single-product/meta.php' );
  461. }
  462. }
  463. if ( ! function_exists( 'woocommerce_template_single_sharing' ) ) {
  464. /**
  465. * Output the product sharing.
  466. *
  467. * @access public
  468. * @subpackage Product
  469. * @return void
  470. */
  471. function woocommerce_template_single_sharing() {
  472. woocommerce_get_template( 'single-product/share.php' );
  473. }
  474. }
  475. if ( ! function_exists( 'woocommerce_show_product_sale_flash' ) ) {
  476. /**
  477. * Output the product sale flash.
  478. *
  479. * @access public
  480. * @subpackage Product
  481. * @return void
  482. */
  483. function woocommerce_show_product_sale_flash() {
  484. woocommerce_get_template( 'single-product/sale-flash.php' );
  485. }
  486. }
  487. if ( ! function_exists( 'woocommerce_template_single_add_to_cart' ) ) {
  488. /**
  489. * Trigger the single product add to cart action.
  490. *
  491. * @access public
  492. * @subpackage Product
  493. * @return void
  494. */
  495. function woocommerce_template_single_add_to_cart() {
  496. global $product;
  497. do_action( 'woocommerce_' . $product->product_type . '_add_to_cart' );
  498. }
  499. }
  500. if ( ! function_exists( 'woocommerce_simple_add_to_cart' ) ) {
  501. /**
  502. * Output the simple product add to cart area.
  503. *
  504. * @access public
  505. * @subpackage Product
  506. * @return void
  507. */
  508. function woocommerce_simple_add_to_cart() {
  509. woocommerce_get_template( 'single-product/add-to-cart/simple.php' );
  510. }
  511. }
  512. if ( ! function_exists( 'woocommerce_grouped_add_to_cart' ) ) {
  513. /**
  514. * Output the grouped product add to cart area.
  515. *
  516. * @access public
  517. * @subpackage Product
  518. * @return void
  519. */
  520. function woocommerce_grouped_add_to_cart() {
  521. woocommerce_get_template( 'single-product/add-to-cart/grouped.php' );
  522. }
  523. }
  524. if ( ! function_exists( 'woocommerce_variable_add_to_cart' ) ) {
  525. /**
  526. * Output the variable product add to cart area.
  527. *
  528. * @access public
  529. * @subpackage Product
  530. * @return void
  531. */
  532. function woocommerce_variable_add_to_cart() {
  533. global $product;
  534. // Enqueue variation scripts
  535. wp_enqueue_script( 'wc-add-to-cart-variation' );
  536. // Load the template
  537. woocommerce_get_template( 'single-product/add-to-cart/variable.php', array(
  538. 'available_variations' => $product->get_available_variations(),
  539. 'attributes' => $product->get_variation_attributes(),
  540. 'selected_attributes' => $product->get_variation_default_attributes()
  541. ) );
  542. }
  543. }
  544. if ( ! function_exists( 'woocommerce_external_add_to_cart' ) ) {
  545. /**
  546. * Output the external product add to cart area.
  547. *
  548. * @access public
  549. * @subpackage Product
  550. * @return void
  551. */
  552. function woocommerce_external_add_to_cart() {
  553. global $product;
  554. if ( ! $product->get_product_url() )
  555. return;
  556. woocommerce_get_template( 'single-product/add-to-cart/external.php', array(
  557. 'product_url' => $product->get_product_url(),
  558. 'button_text' => $product->get_button_text()
  559. ) );
  560. }
  561. }
  562. if ( ! function_exists( 'woocommerce_quantity_input' ) ) {
  563. /**
  564. * Output the quantity input for add to cart forms.
  565. *
  566. * @access public
  567. * @subpackage Product
  568. * @return void
  569. */
  570. function woocommerce_quantity_input( $args = array() ) {
  571. global $product;
  572. $defaults = array(
  573. 'input_name' => 'quantity',
  574. 'input_value' => '1',
  575. 'max_value' => apply_filters( 'woocommerce_quantity_input_max', '', $product ),
  576. 'min_value' => apply_filters( 'woocommerce_quantity_input_min', '', $product ),
  577. 'step' => apply_filters( 'woocommerce_quantity_input_step', '1', $product )
  578. );
  579. $args = apply_filters( 'woocommerce_quantity_input_args', wp_parse_args( $args, $defaults ), $product );
  580. woocommerce_get_template( 'single-product/add-to-cart/quantity.php', $args );
  581. }
  582. }
  583. if ( ! function_exists( 'woocommerce_product_description_tab' ) ) {
  584. /**
  585. * Output the description tab content.
  586. *
  587. * @access public
  588. * @subpackage Product/Tabs
  589. * @return void
  590. */
  591. function woocommerce_product_description_tab() {
  592. woocommerce_get_template( 'single-product/tabs/description.php' );
  593. }
  594. }
  595. if ( ! function_exists( 'woocommerce_product_additional_information_tab' ) ) {
  596. /**
  597. * Output the attributes tab content.
  598. *
  599. * @access public
  600. * @subpackage Product/Tabs
  601. * @return void
  602. */
  603. function woocommerce_product_additional_information_tab() {
  604. woocommerce_get_template( 'single-product/tabs/additional-information.php' );
  605. }
  606. }
  607. if ( ! function_exists( 'woocommerce_product_reviews_tab' ) ) {
  608. /**
  609. * Output the reviews tab content.
  610. *
  611. * @access public
  612. * @subpackage Product/Tabs
  613. * @return void
  614. */
  615. function woocommerce_product_reviews_tab() {
  616. woocommerce_get_template( 'single-product/tabs/reviews.php' );
  617. }
  618. }
  619. if ( ! function_exists( 'woocommerce_default_product_tabs' ) ) {
  620. /**
  621. * Add default product tabs to product pages.
  622. *
  623. * @access public
  624. * @param mixed $tabs
  625. * @return void
  626. */
  627. function woocommerce_default_product_tabs( $tabs = array() ) {
  628. global $product, $post;
  629. // Description tab - shows product content
  630. if ( $post->post_content )
  631. $tabs['description'] = array(
  632. 'title' => __( 'Description', 'woocommerce' ),
  633. 'priority' => 10,
  634. 'callback' => 'woocommerce_product_description_tab'
  635. );
  636. // Additonal information tab - shows attributes
  637. if ( $product->has_attributes() || ( get_option( 'woocommerce_enable_dimension_product_attributes' ) == 'yes' && ( $product->has_dimensions() || $product->has_weight() ) ) )
  638. $tabs['additional_information'] = array(
  639. 'title' => __( 'Additional Information', 'woocommerce' ),
  640. 'priority' => 20,
  641. 'callback' => 'woocommerce_product_additional_information_tab'
  642. );
  643. // Reviews tab - shows comments
  644. if ( comments_open() )
  645. $tabs['reviews'] = array(
  646. 'title' => sprintf( __( 'Reviews (%d)', 'woocommerce' ), get_comments_number( $post->ID ) ),
  647. 'priority' => 30,
  648. 'callback' => 'comments_template'
  649. );
  650. return $tabs;
  651. }
  652. }
  653. if ( ! function_exists( 'woocommerce_sort_product_tabs' ) ) {
  654. /**
  655. * Sort tabs by priority
  656. *
  657. * @access public
  658. * @return void
  659. */
  660. function woocommerce_sort_product_tabs( $tabs = array() ) {
  661. // Re-order tabs by priority
  662. if ( ! function_exists( '_sort_priority_callback' ) ) {
  663. function _sort_priority_callback( $a, $b ) {
  664. if ( $a['priority'] == $b['priority'] )
  665. return 0;
  666. return ( $a['priority'] < $b['priority'] ) ? -1 : 1;
  667. }
  668. }
  669. uasort( $tabs, '_sort_priority_callback' );
  670. return $tabs;
  671. }
  672. }
  673. if ( ! function_exists( 'woocommerce_comments' ) ) {
  674. /**
  675. * Output the Review comments template.
  676. *
  677. * @access public
  678. * @subpackage Product
  679. * @return void
  680. */
  681. function woocommerce_comments( $comment, $args, $depth ) {
  682. $GLOBALS['comment'] = $comment;
  683. woocommerce_get_template( 'single-product/review.php' );
  684. }
  685. }
  686. if ( ! function_exists( 'woocommerce_output_related_products' ) ) {
  687. /**
  688. * Output the related products.
  689. *
  690. * @access public
  691. * @subpackage Product
  692. * @return void
  693. */
  694. function woocommerce_output_related_products() {
  695. woocommerce_related_products( 2, 2 );
  696. }
  697. }
  698. if ( ! function_exists( 'woocommerce_related_products' ) ) {
  699. /**
  700. * Output the related products.
  701. *
  702. * @access public
  703. * @param int $posts_per_page (default: 2)
  704. * @param int $columns (default: 2)
  705. * @param string $orderby (default: 'rand')
  706. * @return void
  707. */
  708. function woocommerce_related_products( $posts_per_page = 2, $columns = 2, $orderby = 'rand' ) {
  709. woocommerce_get_template( 'single-product/related.php', array(
  710. 'posts_per_page' => $posts_per_page,
  711. 'orderby' => $orderby,
  712. 'columns' => $columns
  713. ) );
  714. }
  715. }
  716. if ( ! function_exists( 'woocommerce_upsell_display' ) ) {
  717. /**
  718. * Output product up sells.
  719. *
  720. * @access public
  721. * @param int $posts_per_page (default: -1)
  722. * @param int $columns (default: 2)
  723. * @param string $orderby (default: 'rand')
  724. * @return void
  725. */
  726. function woocommerce_upsell_display( $posts_per_page = '-1', $columns = 2, $orderby = 'rand' ) {
  727. woocommerce_get_template( 'single-product/up-sells.php', array(
  728. 'posts_per_page' => $posts_per_page,
  729. 'orderby' => $orderby,
  730. 'columns' => $columns
  731. ) );
  732. }
  733. }
  734. /** Cart ******************************************************************/
  735. if ( ! function_exists( 'woocommerce_shipping_calculator' ) ) {
  736. /**
  737. * Output the cart shipping calculator.
  738. *
  739. * @access public
  740. * @subpackage Cart
  741. * @return void
  742. */
  743. function woocommerce_shipping_calculator() {
  744. woocommerce_get_template( 'cart/shipping-calculator.php' );
  745. }
  746. }
  747. if ( ! function_exists( 'woocommerce_cart_totals' ) ) {
  748. /**
  749. * Output the cart totals.
  750. *
  751. * @access public
  752. * @subpackage Cart
  753. * @return void
  754. */
  755. function woocommerce_cart_totals() {
  756. woocommerce_get_template( 'cart/totals.php' );
  757. }
  758. }
  759. if ( ! function_exists( 'woocommerce_cross_sell_display' ) ) {
  760. /**
  761. * Output the cart cross-sells.
  762. *
  763. * @access public
  764. * @subpackage Cart
  765. * @return void
  766. */
  767. function woocommerce_cross_sell_display() {
  768. woocommerce_get_template( 'cart/cross-sells.php' );
  769. }
  770. }
  771. /** Mini-Cart *************************************************************/
  772. if ( ! function_exists( 'woocommerce_mini_cart' ) ) {
  773. /**
  774. * Output the Mini-cart - used by cart widget
  775. *
  776. * @access public
  777. * @return void
  778. */
  779. function woocommerce_mini_cart( $args = array() ) {
  780. $defaults = array(
  781. 'list_class' => ''
  782. );
  783. $args = wp_parse_args( $args, $defaults );
  784. woocommerce_get_template( 'cart/mini-cart.php', $args );
  785. }
  786. }
  787. /** Login *****************************************************************/
  788. if ( ! function_exists( 'woocommerce_login_form' ) ) {
  789. /**
  790. * Output the WooCommerce Login Form
  791. *
  792. * @access public
  793. * @subpackage Forms
  794. * @return void
  795. */
  796. function woocommerce_login_form( $args = array() ) {
  797. $defaults = array(
  798. 'message' => '',
  799. 'redirect' => ''
  800. );
  801. $args = wp_parse_args( $args, $defaults );
  802. woocommerce_get_template( 'shop/form-login.php', $args );
  803. }
  804. }
  805. if ( ! function_exists( 'woocommerce_checkout_login_form' ) ) {
  806. /**
  807. * Output the WooCommerce Checkout Login Form
  808. *
  809. * @access public
  810. * @subpackage Checkout
  811. * @return void
  812. */
  813. function woocommerce_checkout_login_form() {
  814. global $woocommerce;
  815. woocommerce_get_template( 'checkout/form-login.php', array( 'checkout' => $woocommerce->checkout() ) );
  816. }
  817. }
  818. if ( ! function_exists( 'woocommerce_breadcrumb' ) ) {
  819. /**
  820. * Output the WooCommerce Breadcrumb
  821. *
  822. * @access public
  823. * @return void
  824. */
  825. function woocommerce_breadcrumb( $args = array() ) {
  826. $defaults = apply_filters( 'woocommerce_breadcrumb_defaults', array(
  827. 'delimiter' => ' &#47; ',
  828. 'wrap_before' => '<nav class="woocommerce-breadcrumb" itemprop="breadcrumb">',
  829. 'wrap_after' => '</nav>',
  830. 'before' => '',
  831. 'after' => '',
  832. 'home' => _x( 'Home', 'breadcrumb', 'woocommerce' ),
  833. ) );
  834. $args = wp_parse_args( $args, $defaults );
  835. woocommerce_get_template( 'shop/breadcrumb.php', $args );
  836. }
  837. }
  838. if ( ! function_exists( 'woocommerce_order_review' ) ) {
  839. /**
  840. * Output the Order review table for the checkout.
  841. *
  842. * @access public
  843. * @subpackage Checkout
  844. * @return void
  845. */
  846. function woocommerce_order_review() {
  847. global $woocommerce;
  848. woocommerce_get_template( 'checkout/review-order.php', array( 'checkout' => $woocommerce->checkout() ) );
  849. }
  850. }
  851. if ( ! function_exists( 'woocommerce_checkout_coupon_form' ) ) {
  852. /**
  853. * Output the Coupon form for the checkout.
  854. *
  855. * @access public
  856. * @subpackage Checkout
  857. * @return void
  858. */
  859. function woocommerce_checkout_coupon_form() {
  860. global $woocommerce;
  861. woocommerce_get_template( 'checkout/form-coupon.php', array( 'checkout' => $woocommerce->checkout() ) );
  862. }
  863. }
  864. if ( ! function_exists( 'woocommerce_products_will_display' ) ) {
  865. /**
  866. * Check if we will be showing products or not (and not subcats only)
  867. *
  868. * @access public
  869. * @subpackage Loop
  870. * @return void
  871. */
  872. function woocommerce_products_will_display() {
  873. global $woocommerce, $wpdb;
  874. if ( ! is_product_category() && ! is_shop() )
  875. return false;
  876. if ( is_search() || is_filtered() || is_paged() )
  877. return true;
  878. if ( is_shop() && get_option( 'woocommerce_shop_page_display' ) != 'subcategories' )
  879. return true;
  880. $term = get_queried_object();
  881. if ( is_product_category() ) {
  882. switch ( get_woocommerce_term_meta( $term->term_id, 'display_type', true ) ) {
  883. case 'products' :
  884. case 'both' :
  885. return true;
  886. break;
  887. case '' :
  888. if ( get_option( 'woocommerce_category_archive_display' ) != 'subcategories' )
  889. return true;
  890. break;
  891. }
  892. }
  893. $parent_id = empty( $term->term_id ) ? 0 : $term->term_id;
  894. $has_children = $wpdb->get_col( $wpdb->prepare( "SELECT term_id FROM {$wpdb->term_taxonomy} WHERE parent = %d", $parent_id ) );
  895. if ( $has_children ) {
  896. // Check terms have products inside
  897. $children = array();
  898. foreach ( $has_children as $term ) {
  899. $children = array_merge( $children, get_term_children( $term, 'product_cat' ) );
  900. $children[] = $term;
  901. }
  902. $objects = get_objects_in_term( $children, 'product_cat' );
  903. if ( sizeof( $objects ) > 0 ) {
  904. return false;
  905. } else {
  906. return true;
  907. }
  908. } else {
  909. return true;
  910. }
  911. }
  912. }
  913. if ( ! function_exists( 'woocommerce_product_subcategories' ) ) {
  914. /**
  915. * Display product sub categories as thumbnails.
  916. *
  917. * @access public
  918. * @subpackage Loop
  919. * @return void
  920. */
  921. function woocommerce_product_subcategories( $args = array() ) {
  922. global $woocommerce, $wp_query;
  923. $defaults = array(
  924. 'before' => '',
  925. 'after' => '',
  926. 'force_display' => false
  927. );
  928. $args = wp_parse_args( $args, $defaults );
  929. extract( $args );
  930. // Main query only
  931. if ( ! is_main_query() && ! $force_display ) return;
  932. // Don't show when filtering, searching or when on page > 1 and ensure we're on a product archive
  933. if ( is_search() || is_filtered() || is_paged() || ( ! is_product_category() && ! is_shop() ) ) return;
  934. // Check categories are enabled
  935. if ( is_shop() && get_option( 'woocommerce_shop_page_display' ) == '' ) return;
  936. // Find the category + category parent, if applicable
  937. $term = get_queried_object();
  938. $parent_id = empty( $term->term_id ) ? 0 : $term->term_id;
  939. if ( is_product_category() ) {
  940. $display_type = get_woocommerce_term_meta( $term->term_id, 'display_type', true );
  941. switch ( $display_type ) {
  942. case 'products' :
  943. return;
  944. break;
  945. case '' :
  946. if ( get_option( 'woocommerce_category_archive_display' ) == '' )
  947. return;
  948. break;
  949. }
  950. }
  951. // NOTE: using child_of instead of parent - this is not ideal but due to a WP bug ( http://core.trac.wordpress.org/ticket/15626 ) pad_counts won't work
  952. $args = array(
  953. 'child_of' => $parent_id,
  954. 'menu_order' => 'ASC',
  955. 'hide_empty' => 1,
  956. 'hierarchical' => 1,
  957. 'taxonomy' => 'product_cat',
  958. 'pad_counts' => 1
  959. );
  960. $product_categories = get_categories( apply_filters( 'woocommerce_product_subcategories_args', $args ) );
  961. $product_category_found = false;
  962. if ( $product_categories ) {
  963. foreach ( $product_categories as $category ) {
  964. if ( $category->parent != $parent_id )
  965. continue;
  966. if ( ! $product_category_found ) {
  967. // We found a category
  968. $product_category_found = true;
  969. echo $before;
  970. }
  971. woocommerce_get_template( 'content-product_cat.php', array(
  972. 'category' => $category
  973. ) );
  974. }
  975. }
  976. // If we are hiding products disable the loop and pagination
  977. if ( $product_category_found ) {
  978. if ( is_product_category() ) {
  979. $display_type = get_woocommerce_term_meta( $term->term_id, 'display_type', true );
  980. switch ( $display_type ) {
  981. case 'subcategories' :
  982. $wp_query->post_count = 0;
  983. $wp_query->max_num_pages = 0;
  984. break;
  985. case '' :
  986. if ( get_option( 'woocommerce_category_archive_display' ) == 'subcategories' ) {
  987. $wp_query->post_count = 0;
  988. $wp_query->max_num_pages = 0;
  989. }
  990. break;
  991. }
  992. }
  993. if ( is_shop() && get_option( 'woocommerce_shop_page_display' ) == 'subcategories' ) {
  994. $wp_query->post_count = 0;
  995. $wp_query->max_num_pages = 0;
  996. }
  997. echo $after;
  998. return true;
  999. }
  1000. }
  1001. }
  1002. if ( ! function_exists( 'woocommerce_subcategory_thumbnail' ) ) {
  1003. /**
  1004. * Show subcategory thumbnails.
  1005. *
  1006. * @access public
  1007. * @param mixed $category
  1008. * @subpackage Loop
  1009. * @return void
  1010. */
  1011. function woocommerce_subcategory_thumbnail( $category ) {
  1012. global $woocommerce;
  1013. $small_thumbnail_size = apply_filters( 'single_product_small_thumbnail_size', 'shop_catalog' );
  1014. $dimensions = $woocommerce->get_image_size( $small_thumbnail_size );
  1015. $thumbnail_id = get_woocommerce_term_meta( $category->term_id, 'thumbnail_id', true );
  1016. if ( $thumbnail_id ) {
  1017. $image = wp_get_attachment_image_src( $thumbnail_id, $small_thumbnail_size );
  1018. $image = $image[0];
  1019. } else {
  1020. $image = woocommerce_placeholder_img_src();
  1021. }
  1022. if ( $image )
  1023. echo '<img src="' . $image . '" alt="' . $category->name . '" width="' . $dimensions['width'] . '" height="' . $dimensions['height'] . '" />';
  1024. }
  1025. }
  1026. if ( ! function_exists( 'woocommerce_order_details_table' ) ) {
  1027. /**
  1028. * Displays order details in a table.
  1029. *
  1030. * @access public
  1031. * @param mixed $order_id
  1032. * @subpackage Orders
  1033. * @return void
  1034. */
  1035. function woocommerce_order_details_table( $order_id ) {
  1036. if ( ! $order_id ) return;
  1037. woocommerce_get_template( 'order/order-details.php', array(
  1038. 'order_id' => $order_id
  1039. ) );
  1040. }
  1041. }
  1042. /** Forms ****************************************************************/
  1043. if ( ! function_exists( 'woocommerce_form_field' ) ) {
  1044. /**
  1045. * Outputs a checkout/address form field.
  1046. *
  1047. * @access public
  1048. * @subpackage Forms
  1049. * @param mixed $key
  1050. * @param mixed $args
  1051. * @param string $value (default: '')
  1052. * @return void
  1053. */
  1054. function woocommerce_form_field( $key, $args, $value = '' ) {
  1055. global $woocommerce;
  1056. $defaults = array(
  1057. 'type' => 'text',
  1058. 'label' => '',
  1059. 'placeholder' => '',
  1060. 'maxlength' => false,
  1061. 'required' => false,
  1062. 'class' => array(),
  1063. 'label_class' => array(),
  1064. 'return' => false,
  1065. 'options' => array(),
  1066. 'custom_attributes' => array(),
  1067. 'validate' => array()
  1068. );
  1069. $args = wp_parse_args( $args, $defaults );
  1070. if ( ( ! empty( $args['clear'] ) ) ) $after = '<div class="clear"></div>'; else $after = '';
  1071. if ( $args['required'] ) {
  1072. $args['class'][] = 'validate-required';
  1073. $required = ' <abbr class="required" title="' . esc_attr__( 'required', 'woocommerce' ) . '">*</abbr>';
  1074. } else {
  1075. $required = '';
  1076. }
  1077. $args['maxlength'] = ( $args['maxlength'] ) ? 'maxlength="' . absint( $args['maxlength'] ) . '"' : '';
  1078. // Custom attribute handling
  1079. $custom_attributes = array();
  1080. if ( ! empty( $args['custom_attributes'] ) && is_array( $args['custom_attributes'] ) )
  1081. foreach ( $args['custom_attributes'] as $attribute => $value )
  1082. $custom_attributes[] = esc_attr( $attribute ) . '="' . esc_attr( $value ) . '"';
  1083. if ( ! empty( $args['validate'] ) )
  1084. foreach( $args['validate'] as $validate )
  1085. $args['class'][] = 'validate-' . $validate;
  1086. switch ( $args['type'] ) {
  1087. case "country" :
  1088. if ( sizeof( $woocommerce->countries->get_allowed_countries() ) == 1 ) {
  1089. $field = '<p class="form-row ' . esc_attr( implode( ' ', $args['class'] ) ) .'" id="' . esc_attr( $key ) . '_field">';
  1090. if ( $args['label'] )
  1091. $field .= '<label class="' . implode( ' ', $args['label_class'] ) .'">' . $args['label'] . '</label>';
  1092. $field .= '<strong>' . current( array_values( $woocommerce->countries->get_allowed_countries() ) ) . '</strong>';
  1093. $field .= '<input type="hidden" name="' . esc_attr( $key ) . '" id="' . esc_attr( $key ) . '" value="' . current( array_keys( $woocommerce->countries->get_allowed_countries() ) ) . '" ' . implode( ' ', $custom_attributes ) . ' />';
  1094. $field .= '</p>' . $after;
  1095. } else {
  1096. $field = '<p class="form-row ' . esc_attr( implode( ' ', $args['class'] ) ) .'" id="' . esc_attr( $key ) . '_field">
  1097. <label for="' . esc_attr( $key ) . '" class="' . implode( ' ', $args['label_class'] ) .'">' . $args['label']. $required . '</label>
  1098. <select name="' . esc_attr( $key ) . '" id="' . esc_attr( $key ) . '" class="country_to_state country_select" ' . implode( ' ', $custom_attributes ) . '>
  1099. <option value="">'.__( 'Select a country&hellip;', 'woocommerce' ) .'</option>';
  1100. foreach ( $woocommerce->countries->get_allowed_countries() as $ckey => $cvalue )
  1101. $field .= '<option value="' . $ckey . '" '.selected( $value, $ckey, false ) .'>'.__( $cvalue, 'woocommerce' ) .'</option>';
  1102. $field .= '</select>';
  1103. $field .= '<noscript><input type="submit" name="woocommerce_checkout_update_totals" value="' . __( 'Update country', 'woocommerce' ) . '" /></noscript>';
  1104. $field .= '</p>' . $after;
  1105. }
  1106. break;
  1107. case "state" :
  1108. /* Get Country */
  1109. $country_key = $key == 'billing_state'? 'billing_country' : 'shipping_country';
  1110. if ( isset( $_POST[ $country_key ] ) ) {
  1111. $current_cc = woocommerce_clean( $_POST[ $country_key ] );
  1112. } elseif ( is_user_logged_in() ) {
  1113. $current_cc = get_user_meta( get_current_user_id() , $country_key, true );
  1114. if ( ! $current_cc) {
  1115. $current_cc = apply_filters('default_checkout_country', ($woocommerce->customer->get_country()) ? $woocommerce->customer->get_country() : $woocommerce->countries->get_base_country());
  1116. }
  1117. } elseif ( $country_key == 'billing_country' ) {
  1118. $current_cc = apply_filters('default_checkout_country', ($woocommerce->customer->get_country()) ? $woocommerce->customer->get_country() : $woocommerce->countries->get_base_country());
  1119. } else {
  1120. $current_cc = apply_filters('default_checkout_country', ($woocommerce->customer->get_shipping_country()) ? $woocommerce->customer->get_shipping_country() : $woocommerce->countries->get_base_country());
  1121. }
  1122. $states = $woocommerce->countries->get_states( $current_cc );
  1123. if ( is_array( $states ) && empty( $states ) ) {
  1124. $field = '<p class="form-row ' . esc_attr( implode( ' ', $args['class'] ) ) .'" id="' . esc_attr( $key ) . '_field" style="display: none">';
  1125. if ( $args['label'] )
  1126. $field .= '<label for="' . esc_attr( $key ) . '" class="' . implode( ' ', $args['label_class'] ) .'">' . $args['label'] . $required . '</label>';
  1127. $field .= '<input type="hidden" class="hidden" name="' . esc_attr( $key ) . '" id="' . esc_attr( $key ) . '" value="" ' . implode( ' ', $custom_attributes ) . ' placeholder="' . $args['placeholder'] . '" />';
  1128. $field .= '</p>' . $after;
  1129. } elseif ( is_array( $states ) ) {
  1130. $field = '<p class="form-row ' . esc_attr( implode( ' ', $args['class'] ) ) .'" id="' . esc_attr( $key ) . '_field">';
  1131. if ( $args['label'] )
  1132. $field .= '<label for="' . esc_attr( $key ) . '" class="' . implode( ' ', $args['label_class'] ) .'">' . $args['label']. $required . '</label>';
  1133. $field .= '<select name="' . esc_attr( $key ) . '" id="' . esc_attr( $key ) . '" class="state_select" ' . implode( ' ', $custom_attributes ) . ' placeholder="' . $args['placeholder'] . '">
  1134. <option value="">'.__( 'Select a state&hellip;', 'woocommerce' ) .'</option>';
  1135. foreach ( $states as $ckey => $cvalue )
  1136. $field .= '<option value="' . $ckey . '" '.selected( $value, $ckey, false ) .'>'.__( $cvalue, 'woocommerce' ) .'</option>';
  1137. $field .= '</select>';
  1138. $field .= '</p>' . $after;
  1139. } else {
  1140. $field = '<p class="form-row ' . esc_attr( implode( ' ', $args['class'] ) ) .'" id="' . esc_attr( $key ) . '_field">';
  1141. if ( $args['label'] )
  1142. $field .= '<label for="' . esc_attr( $key ) . '" class="' . implode( ' ', $args['label_class'] ) .'">' . $args['label']. $required . '</label>';
  1143. $field .= '<input type="text" class="input-text" value="' . $value . '" placeholder="' . $args['placeholder'] . '" name="' . esc_attr( $key ) . '" id="' . esc_attr( $key ) . '" ' . implode( ' ', $custom_attributes ) . ' />';
  1144. $field .= '</p>' . $after;
  1145. }
  1146. break;
  1147. case "textarea" :
  1148. $field = '<p class="form-row ' . esc_attr( implode( ' ', $args['class'] ) ) .'" id="' . esc_attr( $key ) . '_field">';
  1149. if ( $args['label'] )
  1150. $field .= '<label for="' . esc_attr( $key ) . '" class="' . implode( ' ', $args['label_class'] ) .'">' . $args['label']. $required . '</label>';
  1151. $field .= '<textarea name="' . esc_attr( $key ) . '" class="input-text" id="' . esc_attr( $key ) . '" placeholder="' . $args['placeholder'] . '" cols="5" rows="2" ' . implode( ' ', $custom_attributes ) . '>'. esc_textarea( $value ) .'</textarea>
  1152. </p>' . $after;
  1153. break;
  1154. case "checkbox" :
  1155. $field = '<p class="form-row ' . esc_attr( implode( ' ', $args['class'] ) ) .'" id="' . esc_attr( $key ) . '_field">
  1156. <input type="' . $args['type'] . '" class="input-checkbox" name="' . esc_attr( $key ) . '" id="' . esc_attr( $key ) . '" value="1" '.checked( $value, 1, false ) .' />
  1157. <label for="' . esc_attr( $key ) . '" class="checkbox ' . implode( ' ', $args['label_class'] ) .'" ' . implode( ' ', $custom_attributes ) . '>' . $args['label'] . $required . '</label>
  1158. </p>' . $after;
  1159. break;
  1160. case "password" :
  1161. $field = '<p class="form-row ' . esc_attr( implode( ' ', $args['class'] ) ) .'" id="' . esc_attr( $key ) . '_field">';
  1162. if ( $args['label'] )
  1163. $field .= '<label for="' . esc_attr( $key ) . '" class="' . implode( ' ', $args['label_class'] ) .'">' . $args['label']. $required . '</label>';
  1164. $field .= '<input type="password" class="input-text" name="' . esc_attr( $key ) . '" id="' . esc_attr( $key ) . '" placeholder="' . $args['placeholder'] . '" value="' . esc_attr( $value ) . '" ' . implode( ' ', $custom_attributes ) . ' />
  1165. </p>' . $after;
  1166. break;
  1167. case "text" :
  1168. $field = '<p class="form-row ' . esc_attr( implode( ' ', $args['class'] ) ) .'" id="' . esc_attr( $key ) . '_field">';
  1169. if ( $args['label'] )
  1170. $field .= '<label for="' . esc_attr( $key ) . '" class="' . implode( ' ', $args['label_class'] ) .'">' . $args['label'] . $required . '</label>';
  1171. $field .= '<input type="text" class="input-text" name="' . esc_attr( $key ) . '" id="' . esc_attr( $key ) . '" placeholder="' . $args['placeholder'] . '" '.$args['maxlength'].' value="' . esc_attr( $value ) . '" ' . implode( ' ', $custom_attributes ) . ' />
  1172. </p>' . $after;
  1173. break;
  1174. case "select" :
  1175. $options = '';
  1176. if ( ! empty( $args['options'] ) )
  1177. foreach ( $args['options'] as $option_key => $option_text )
  1178. $options .= '<option value="' . esc_attr( $option_key ) . '" '. selected( $value, $option_key, false ) . '>' . esc_attr( $option_text ) .'</option>';
  1179. $field = '<p class="form-row ' . esc_attr( implode( ' ', $args['class'] ) ) .'" id="' . esc_attr( $key ) . '_field">';
  1180. if ( $args['label'] )
  1181. $field .= '<label for="' . esc_attr( $key ) . '" class="' . implode( ' ', $args['label_class'] ) .'">' . $args['label']. $required . '</label>';
  1182. $field .= '<select name="' . esc_attr( $key ) . '" id="' . esc_attr( $key ) . '" class="select" ' . implode( ' ', $custom_attributes ) . '>
  1183. ' . $options . '
  1184. </select>
  1185. </p>' . $after;
  1186. break;
  1187. default :
  1188. $field = apply_filters( 'woocommerce_form_field_' . $args['type'], '', $key, $args, $value );
  1189. break;
  1190. }
  1191. if ( $args['return'] ) return $field; else echo $field;
  1192. }
  1193. }
  1194. if ( ! function_exists( 'get_product_search_form' ) ) {
  1195. /**
  1196. * Output Product search forms.
  1197. *
  1198. * @access public
  1199. * @subpackage Forms
  1200. * @param bool $echo (default: true)
  1201. * @return void
  1202. */
  1203. function get_product_search_form( $echo = true ) {
  1204. do_action( 'get_product_search_form' );
  1205. $search_form_template = locate_template( 'product-searchform.php' );
  1206. if ( '' != $search_form_template ) {
  1207. require $search_form_template;
  1208. return;
  1209. }
  1210. $form = '<form role="search" method="get" id="searchform" action="' . esc_url( home_url( '/' ) ) . '">
  1211. <div>
  1212. <label class="screen-reader-text" for="s">' . __( 'Search for:', 'woocommerce' ) . '</label>
  1213. <input type="text" value="' . get_search_query() . '" name="s" id="s" placeholder="' . __( 'Search for products', 'woocommerce' ) . '" />
  1214. <input type="submit" id="searchsubmit" value="'. esc_attr__( 'Search', 'woocommerce' ) .'" />
  1215. <input type="hidden" name="post_type" value="product" />
  1216. </div>
  1217. </form>';
  1218. if ( $echo )
  1219. echo apply_filters( 'get_product_search_form', $form );
  1220. else
  1221. return apply_filters( 'get_product_search_form', $form );
  1222. }
  1223. }