1 <?php
   2 /**
   3  * WooCommerce Template
   4  *
   5  * Functions for the templating system.
   6  *
   7  * @author      WooThemes
   8  * @category    Core
   9  * @package     WooCommerce/Functions
  10  * @version     2.1.0
  11  */
  12 
  13 if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
  14 
  15 /**
  16  * Handle redirects before content is output - hooked into template_redirect so is_page works.
  17  *
  18  * @return void
  19  */
  20 function wc_template_redirect() {
  21     global $wp_query, $wp;
  22 
  23     // When default permalinks are enabled, redirect shop page to post type archive url
  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     // When on the checkout with an empty cart, redirect to cart page
  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     // Logout
  36     elseif ( isset( $wp->query_vars['customer-logout'] ) ) {
  37         wp_redirect( str_replace( '&amp;', '&', wp_logout_url( get_permalink( wc_get_page_id( 'myaccount' ) ) ) ) );
  38         exit;
  39     }
  40 
  41     // Redirect to the product page if we have a single product
  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     // Ensure payment gateways are loaded early
  52     elseif ( is_add_payment_method_page() ) {
  53 
  54         WC()->payment_gateways();
  55 
  56     }
  57 
  58     // Checkout pages handling
  59     elseif ( is_checkout() ) {
  60         // Buffer the checkout page
  61         ob_start();
  62 
  63         // Ensure gateways and shipping methods are loaded early
  64         WC()->payment_gateways();
  65         WC()->shipping();
  66     }
  67 }
  68 add_action( 'template_redirect', 'wc_template_redirect' );
  69 
  70 /**
  71  * When the_post is called, put product data into a global.
  72  *
  73  * @param mixed $post
  74  * @return WC_Product
  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      * Reset the loop's index and columns when we're done outputting a product loop.
  95      *
  96      * @access public
  97      * @subpackage  Loop
  98      * @return void
  99      */
 100     function woocommerce_reset_loop() {
 101         global $woocommerce_loop;
 102         // Reset loop/columns globals when starting a new loop
 103         $woocommerce_loop['loop'] = $woocommerce_loop['columns'] = '';
 104     }
 105 }
 106 add_filter( 'loop_end', 'woocommerce_reset_loop' );
 107 
 108 /**
 109  * Products RSS Feed.
 110  *
 111  * @access public
 112  * @return void
 113  */
 114 function wc_products_rss_feed() {
 115     // Product RSS
 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  * Output generator tag to aid debugging.
 143  *
 144  * @access public
 145  * @return void
 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  * Add body classes for WC pages
 161  *
 162  * @param  array $classes
 163  * @return array
 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  * Adds extra post classes for products
 197  *
 198  * @since 2.1.0
 199  * @param array $classes
 200  * @param string|array $class
 201  * @param int $post_id
 202  * @return array
 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         // add category slugs
 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         // add tag slugs
 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 /** Template pages ********************************************************/
 266 
 267 if ( ! function_exists( 'woocommerce_content' ) ) {
 268 
 269     /**
 270      * Output WooCommerce content.
 271      *
 272      * This function is only used in the optional 'woocommerce.php' template
 273      * which people can add to their themes to add basic woocommerce support
 274      * without hooks or modifying core templates.
 275      *
 276      * @access public
 277      * @return void
 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; // end of the loop. ?>
 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 /** Global ****************************************************************/
 328 
 329 if ( ! function_exists( 'woocommerce_output_content_wrapper' ) ) {
 330 
 331     /**
 332      * Output the start of the page wrapper.
 333      *
 334      * @access public
 335      * @return void
 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      * Output the end of the page wrapper.
 345      *
 346      * @access public
 347      * @return void
 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      * Get the shop sidebar template.
 358      *
 359      * @access public
 360      * @return void
 361      */
 362     function woocommerce_get_sidebar() {
 363         wc_get_template( 'global/sidebar.php' );
 364     }
 365 }
 366 
 367 if ( ! function_exists( 'woocommerce_demo_store' ) ) {
 368 
 369     /**
 370      * Adds a demo store banner to the site if enabled
 371      *
 372      * @access public
 373      * @return void
 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 &mdash; no orders shall be fulfilled.', 'woocommerce' );
 382 
 383         echo apply_filters( 'woocommerce_demo_store', '<p class="demo_store">' . $notice . '</p>'  );
 384     }
 385 }
 386 
 387 /** Loop ******************************************************************/
 388 
 389 if ( ! function_exists( 'woocommerce_page_title' ) ) {
 390 
 391     /**
 392      * woocommerce_page_title function.
 393      *
 394      * @param  boolean $echo
 395      * @return string
 396      */
 397     function woocommerce_page_title( $echo = true ) {
 398 
 399         if ( is_search() ) {
 400             $page_title = sprintf( __( 'Search Results: &ldquo;%s&rdquo;', 'woocommerce' ), get_search_query() );
 401 
 402             if ( get_query_var( 'paged' ) )
 403                 $page_title .= sprintf( __( '&nbsp;&ndash; 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      * Output the start of a product loop. By default this is a UL
 429      *
 430      * @access public
 431      * @param bool $echo
 432      * @return string
 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      * Output the end of a product loop. By default this is a UL
 447      *
 448      * @access public
 449      * @param bool $echo
 450      * @return string
 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      * Show an archive description on taxonomy archives
 467      *
 468      * @access public
 469      * @subpackage  Archives
 470      * @return void
 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      * Show a shop page description on product archives
 485      *
 486      * @access public
 487      * @subpackage  Archives
 488      * @return void
 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      * Get the add to cart template for the loop.
 507      *
 508      * @access public
 509      * @subpackage  Loop
 510      * @return void
 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      * Get the product thumbnail for the loop.
 520      *
 521      * @access public
 522      * @subpackage  Loop
 523      * @return void
 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      * Get the product price for the loop.
 533      *
 534      * @access public
 535      * @subpackage  Loop
 536      * @return void
 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      * Display the average rating in the loop
 546      *
 547      * @access public
 548      * @subpackage  Loop
 549      * @return void
 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      * Get the sale flash for the loop.
 559      *
 560      * @access public
 561      * @subpackage  Loop
 562      * @return void
 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      * Get a products Schema
 573      * @return string
 574      */
 575     function woocommerce_get_product_schema() {
 576         global $post, $product;
 577 
 578         $schema = "Product";
 579 
 580         // Downloadable product schema handling
 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      * Get the product thumbnail, or the placeholder if not set.
 603      *
 604      * @access public
 605      * @subpackage  Loop
 606      * @param string $size (default: 'shop_catalog')
 607      * @param int $placeholder_width (default: 0)
 608      * @param int $placeholder_height (default: 0)
 609      * @return string
 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      * Output the result count text (Showing x - x of x results).
 625      *
 626      * @access public
 627      * @subpackage  Loop
 628      * @return void
 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      * Output the product sorting options.
 639      *
 640      * @access public
 641      * @subpackage  Loop
 642      * @return void
 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      * Output the pagination.
 655      *
 656      * @access public
 657      * @subpackage  Loop
 658      * @return void
 659      */
 660     function woocommerce_pagination() {
 661         wc_get_template( 'loop/pagination.php' );
 662     }
 663 }
 664 
 665 /** Single Product ********************************************************/
 666 
 667 if ( ! function_exists( 'woocommerce_show_product_images' ) ) {
 668 
 669     /**
 670      * Output the product image before the single product summary.
 671      *
 672      * @access public
 673      * @subpackage  Product
 674      * @return void
 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      * Output the product thumbnails.
 684      *
 685      * @access public
 686      * @subpackage  Product
 687      * @return void
 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      * Output the product tabs.
 697      *
 698      * @access public
 699      * @subpackage  Product/Tabs
 700      * @return void
 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      * Output the product title.
 710      *
 711      * @access public
 712      * @subpackage  Product
 713      * @return void
 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      * Output the product rating.
 723      *
 724      * @access public
 725      * @subpackage  Product
 726      * @return void
 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      * Output the product price.
 736      *
 737      * @access public
 738      * @subpackage  Product
 739      * @return void
 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      * Output the product short description (excerpt).
 749      *
 750      * @access public
 751      * @subpackage  Product
 752      * @return void
 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      * Output the product meta.
 762      *
 763      * @access public
 764      * @subpackage  Product
 765      * @return void
 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      * Output the product sharing.
 775      *
 776      * @access public
 777      * @subpackage  Product
 778      * @return void
 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      * Output the product sale flash.
 788      *
 789      * @access public
 790      * @subpackage  Product
 791      * @return void
 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      * Trigger the single product add to cart action.
 802      *
 803      * @access public
 804      * @subpackage  Product
 805      * @return void
 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      * Output the simple product add to cart area.
 816      *
 817      * @access public
 818      * @subpackage  Product
 819      * @return void
 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      * Output the grouped product add to cart area.
 829      *
 830      * @access public
 831      * @subpackage  Product
 832      * @return void
 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      * Output the variable product add to cart area.
 848      *
 849      * @access public
 850      * @subpackage  Product
 851      * @return void
 852      */
 853     function woocommerce_variable_add_to_cart() {
 854         global $product;
 855 
 856         // Enqueue variation scripts
 857         wp_enqueue_script( 'wc-add-to-cart-variation' );
 858 
 859         // Load the template
 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      * Output the external product add to cart area.
 871      *
 872      * @access public
 873      * @subpackage  Product
 874      * @return void
 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      * Output the quantity input for add to cart forms.
 893      * 
 894      * @param  array $args Args for the input
 895      * @param  WC_Product|null $product 
 896      * @param  boolean $echo Whether to return or echo
 897      * @return void|string
 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      * Output the description tab content.
 929      *
 930      * @access public
 931      * @subpackage  Product/Tabs
 932      * @return void
 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      * Output the attributes tab content.
 942      *
 943      * @access public
 944      * @subpackage  Product/Tabs
 945      * @return void
 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      * Output the reviews tab content.
 955      *
 956      * @access public
 957      * @subpackage  Product/Tabs
 958      * @return void
 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      * Add default product tabs to product pages.
 969      *
 970      * @access public
 971      * @param array $tabs
 972      * @return array
 973      */
 974     function woocommerce_default_product_tabs( $tabs = array() ) {
 975         global $product, $post;
 976 
 977         // Description tab - shows product content
 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         // Additional information tab - shows attributes
 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         // Reviews tab - shows comments
 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      * Sort tabs by priority
1012      *
1013      * @access public
1014      * @param array $tabs
1015      * @return array
1016      */
1017     function woocommerce_sort_product_tabs( $tabs = array() ) {
1018         
1019         // Make sure the $tabs parameter is an array
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         // Re-order tabs by priority
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      * Output the Review comments template.
1044      *
1045      * @access public
1046      * @subpackage  Product
1047      * @return void
1048      */
1049     function woocommerce_comments( $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      * Output the related products.
1059      *
1060      * @access public
1061      * @subpackage  Product
1062      * @return void
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      * Output the related products.
1080      *
1081      * @access public
1082      * @param array Provided arguments
1083      * @param bool Columns argument for backwards compat
1084      * @param bool Order by argument for backwards compat
1085      * @return void
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      * Output product up sells.
1116      *
1117      * @access public
1118      * @param int $posts_per_page (default: -1)
1119      * @param int $columns (default: 2)
1120      * @param string $orderby (default: 'rand')
1121      * @return void
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 /** Cart ******************************************************************/
1133 
1134 if ( ! function_exists( 'woocommerce_shipping_calculator' ) ) {
1135 
1136     /**
1137      * Output the cart shipping calculator.
1138      *
1139      * @access public
1140      * @subpackage  Cart
1141      * @return void
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      * Output the cart totals.
1152      *
1153      * @access public
1154      * @subpackage  Cart
1155      * @return void
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      * Output the cart cross-sells.
1166      *
1167      * @param  integer $posts_per_page
1168      * @param  integer $columns
1169      * @param  string $orderby
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 /** Mini-Cart *************************************************************/
1181 
1182 if ( ! function_exists( 'woocommerce_mini_cart' ) ) {
1183 
1184     /**
1185      * Output the Mini-cart - used by cart widget
1186      *
1187      * @access public
1188      * @return void
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 /** Login *****************************************************************/
1203 
1204 if ( ! function_exists( 'woocommerce_login_form' ) ) {
1205 
1206     /**
1207      * Output the WooCommerce Login Form
1208      *
1209      * @access public
1210      * @subpackage  Forms
1211      * @return void
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      * Output the WooCommerce Checkout Login Form
1231      *
1232      * @access public
1233      * @subpackage  Checkout
1234      * @return void
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      * Output the WooCommerce Breadcrumb
1245      *
1246      * @access public
1247      * @return void
1248      */
1249     function woocommerce_breadcrumb( $args = array() ) {
1250 
1251         $defaults = apply_filters( 'woocommerce_breadcrumb_defaults', array(
1252             'delimiter'   => ' &#47; ',
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      * Output the Order review table for the checkout.
1270      *
1271      * @access public
1272      * @subpackage  Checkout
1273      * @return void
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      * Output the Coupon form for the checkout.
1284      *
1285      * @access public
1286      * @subpackage  Checkout
1287      * @return void
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      * Check if we will be showing products or not (and not subcats only)
1298      *
1299      * @access public
1300      * @subpackage  Loop
1301      * @return bool
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                     // Nothing - we want to continue to see if there are products/subcats
1319                 break;
1320                 case 'products' :
1321                 case 'both' :
1322                     return true;
1323                 break;
1324                 default :
1325                     // Default - no setting
1326                     if ( get_option( 'woocommerce_category_archive_display' ) != 'subcategories' )
1327                         return true;
1328                 break;
1329             }
1330         }
1331 
1332         // Begin subcategory logic
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                 // Check terms have products inside - parents first. If products are found inside, subcats will be shown instead of products so we can return false.
1348                 if ( sizeof( get_objects_in_term( $has_children, $taxonomy ) ) > 0 ) {
1349                     $products_will_display = false;
1350                 } else {
1351                     // If we get here, the parents were empty so we're forced to check children
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      * Display product sub categories as thumbnails.
1376      *
1377      * @access public
1378      * @subpackage  Loop
1379      * @param array $args
1380      * @return bool
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         // Main query only
1396         if ( ! is_main_query() && ! $force_display ) return;
1397 
1398         // Don't show when filtering, searching or when on page > 1 and ensure we're on a product archive
1399         if ( is_search() || is_filtered() || is_paged() || ( ! is_product_category() && ! is_shop() ) ) return;
1400 
1401         // Check categories are enabled
1402         if ( is_shop() && get_option( 'woocommerce_shop_page_display' ) == '' ) return;
1403 
1404         // Find the category + category parent, if applicable
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         // 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
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                     // We found a category
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         // If we are hiding products disable the loop and pagination
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      * Show subcategory thumbnails.
1494      *
1495      * @access public
1496      * @param mixed $category
1497      * @subpackage  Loop
1498      * @return void
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             // Prevent esc_url from breaking spaces in urls for image embeds
1514             // Ref: http://core.trac.wordpress.org/ticket/23605
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      * Displays order details in a table.
1526      *
1527      * @access public
1528      * @param mixed $order_id
1529      * @subpackage  Orders
1530      * @return void
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      * Display an 'order again' button on the view order page.
1546      *
1547      * @access public
1548      * @param object $order
1549      * @subpackage  Orders
1550      * @return void
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 /** Forms ****************************************************************/
1565 
1566 if ( ! function_exists( 'woocommerce_form_field' ) ) {
1567 
1568     /**
1569      * Outputs a checkout/address form field.
1570      *
1571      * @access public
1572      * @subpackage  Forms
1573      * @param mixed $key
1574      * @param mixed $args
1575      * @param string $value (default: null)
1576      * @return void
1577      * @todo This function needs to be broken up in smaller pieces 
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         // Custom attribute handling
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&hellip;', '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             /* Get Country */
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&hellip;', '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      * Output Product search forms.
1794      *
1795      * @access public
1796      * @subpackage  Forms
1797      * @param bool $echo (default: true)
1798      * @return string
1799      * @todo This function needs to be broken up in smaller pieces 
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 
WooCommerce API documentation generated by ApiGen 2.8.0