PageRenderTime 57ms CodeModel.GetById 21ms RepoModel.GetById 1ms app.codeStats 0ms

/jigoshop_template_functions.php

https://github.com/ThemesWpFr/jigoshop
PHP | 1134 lines | 811 code | 210 blank | 113 comment | 173 complexity | ffd8d29dc23684965afe096a9f17c503 MD5 | raw file
Possible License(s): GPL-3.0
  1. <?php
  2. /**
  3. * Functions used in template files
  4. *
  5. * DISCLAIMER
  6. *
  7. * Do not edit or add directly to this file if you wish to upgrade Jigoshop to newer
  8. * versions in the future. If you wish to customise Jigoshop core for your needs,
  9. * please use our GitHub repository to publish essential changes for consideration.
  10. *
  11. * @package Jigoshop
  12. * @category Core
  13. * @author Jigowatt
  14. * @copyright Copyright Š 2011-2012 Jigowatt Ltd.
  15. * @license http://jigoshop.com/license/commercial-edition
  16. */
  17. /**
  18. * Front page archive/shop template
  19. */
  20. if (!function_exists('jigoshop_front_page_archive')) {
  21. function jigoshop_front_page_archive() {
  22. global $paged;
  23. // TODO: broken
  24. // is_page() fails for this - still testing -JAP-
  25. // is_shop() works, but only with a [recent_products] shortcode on the Shop page
  26. // however, if shortcode is used when not front page, double product listings appear
  27. //
  28. if ( is_front_page() && is_page( jigoshop_get_page_id('shop') )) :
  29. // if ( is_front_page() && is_shop() ) :
  30. if ( get_query_var('paged') ) {
  31. $paged = get_query_var('paged');
  32. } else if ( get_query_var('page') ) {
  33. $paged = get_query_var('page');
  34. } else {
  35. $paged = 1;
  36. }
  37. query_posts( array( 'page_id' => '', 'post_type' => 'product', 'paged' => $paged ) );
  38. define('SHOP_IS_ON_FRONT', true);
  39. endif;
  40. }
  41. }
  42. add_action('wp_head', 'jigoshop_front_page_archive', 0);
  43. /**
  44. * Content Wrappers
  45. **/
  46. if (!function_exists('jigoshop_output_content_wrapper')) {
  47. function jigoshop_output_content_wrapper() {
  48. if ( get_option('template') === 'twentytwelve' ) echo '<div id="primary" class="site-content"><div id="content" role="main">';
  49. elseif ( get_option('template') === 'twentyeleven' ) echo '<section id="primary"><div id="content" role="main">';
  50. else echo '<div id="container"><div id="content" role="main">'; /* twenty-ten */
  51. }
  52. }
  53. if (!function_exists('jigoshop_output_content_wrapper_end')) {
  54. function jigoshop_output_content_wrapper_end() {
  55. if ( get_option('template') === 'twentytwelve' ) echo '</div></div>';
  56. elseif ( get_option('template') === 'twentyeleven' ) echo '</div></section>';
  57. else echo '</div></div>'; /* twenty-ten */
  58. }
  59. }
  60. /**
  61. * Sale Flash
  62. **/
  63. if (!function_exists('jigoshop_show_product_sale_flash')) {
  64. function jigoshop_show_product_sale_flash( $post, $_product ) {
  65. if ($_product->is_on_sale()) echo '<span class="onsale">'.__('Sale!', 'jigoshop').'</span>';
  66. }
  67. }
  68. /**
  69. * Sidebar
  70. **/
  71. if (!function_exists('jigoshop_get_sidebar')) {
  72. function jigoshop_get_sidebar() {
  73. get_sidebar('shop');
  74. }
  75. }
  76. /**
  77. * Products Loop
  78. **/
  79. if (!function_exists('jigoshop_template_loop_add_to_cart')) {
  80. function jigoshop_template_loop_add_to_cart( $post, $_product ) {
  81. do_action('jigoshop_before_add_to_cart_button');
  82. // do not show "add to cart" button if product's price isn't announced
  83. if ( $_product->get_price() === '' AND ! ($_product->is_type(array('variable', 'grouped', 'external'))) ) return;
  84. if ( $_product->is_in_stock() OR $_product->is_type('external') ) :
  85. if ( $_product->is_type(array('variable', 'grouped')) ) :
  86. $output = '<a href="'.get_permalink($_product->id).'" class="button">'._x('Select', 'verb', 'jigoshop').'</a>';
  87. elseif ( $_product->is_type('external') ) :
  88. $output = '<a href="'.get_post_meta( $_product->id, 'external_url', true ).'" class="button">'.__('Buy product', 'jigoshop').'</a>';
  89. else :
  90. $output = '<a href="'.esc_url($_product->add_to_cart_url()).'" class="button" rel="nofollow">'.__('Add to cart', 'jigoshop').'</a>';
  91. endif;
  92. elseif ( ($_product->is_type(array('grouped')) ) ) :
  93. return;
  94. else :
  95. $output = '<span class="nostock">'.__('Out of Stock', 'jigoshop').'</span>';
  96. endif;
  97. echo apply_filters( 'jigoshop_loop_add_to_cart_output', $output, $post, $_product );
  98. do_action('jigoshop_after_add_to_cart_button');
  99. }
  100. }
  101. if (!function_exists('jigoshop_template_loop_product_thumbnail')) {
  102. function jigoshop_template_loop_product_thumbnail( $post, $_product ) {
  103. echo jigoshop_get_product_thumbnail();
  104. }
  105. }
  106. if (!function_exists('jigoshop_template_loop_price')) {
  107. function jigoshop_template_loop_price( $post, $_product ) {
  108. ?><span class="price"><?php echo $_product->get_price_html(); ?></span><?php
  109. }
  110. }
  111. /**
  112. * Before Single Products Summary Div
  113. **/
  114. if (!function_exists('jigoshop_show_product_images')) {
  115. function jigoshop_show_product_images() {
  116. global $_product, $post;
  117. echo '<div class="images">';
  118. do_action( 'jigoshop_before_single_product_summary_thumbnails', $post, $_product );
  119. $thumb_id = 0;
  120. if (has_post_thumbnail()) :
  121. $thumb_id = get_post_thumbnail_id();
  122. // since there are now user settings for sizes, shouldn't need filters -JAP-
  123. //$large_thumbnail_size = apply_filters('single_product_large_thumbnail_size', 'shop_large');
  124. $large_thumbnail_size = jigoshop_get_image_size( 'shop_large' );
  125. echo '<a href="'.wp_get_attachment_url($thumb_id).'" class="zoom" rel="thumbnails">';
  126. the_post_thumbnail($large_thumbnail_size);
  127. echo '</a>';
  128. else :
  129. echo jigoshop_get_image_placeholder( 'shop_large' );
  130. endif;
  131. do_action('jigoshop_product_thumbnails');
  132. echo '</div>';
  133. }
  134. }
  135. if (!function_exists('jigoshop_show_product_thumbnails')) {
  136. function jigoshop_show_product_thumbnails() {
  137. global $_product, $post;
  138. echo '<div class="thumbnails">';
  139. $thumb_id = get_post_thumbnail_id();
  140. $small_thumbnail_size = jigoshop_get_image_size( 'shop_thumbnail' );
  141. $args = array( 'post_type' => 'attachment', 'post_mime_type' => 'image', 'numberposts' => -1, 'post_status' => null, 'post_parent' => $post->ID, 'orderby' => 'menu_order', 'order' => 'asc' );
  142. $attachments = get_posts($args);
  143. if ($attachments) :
  144. $loop = 0;
  145. $columns = Jigoshop_Base::get_options()->get_option( 'jigoshop_product_thumbnail_columns', '3' );
  146. $columns = apply_filters( 'single_thumbnail_columns', $columns );
  147. foreach ( $attachments as $attachment ) :
  148. if ($thumb_id==$attachment->ID) continue;
  149. $loop++;
  150. $_post = get_post( $attachment->ID );
  151. $url = wp_get_attachment_url($_post->ID);
  152. $post_title = esc_attr($_post->post_title);
  153. $image = wp_get_attachment_image($attachment->ID, $small_thumbnail_size);
  154. if ( ! $image || $url == get_post_meta($post->ID, 'file_path', true) )
  155. continue;
  156. echo '<a href="'.esc_url($url).'" title="'.esc_attr($post_title).'" rel="thumbnails" class="zoom ';
  157. if ($loop==1 || ($loop-1)%$columns==0) echo 'first';
  158. if ($loop%$columns==0) echo 'last';
  159. echo '">'.$image.'</a>';
  160. endforeach;
  161. endif;
  162. wp_reset_query();
  163. echo '</div>';
  164. }
  165. }
  166. /**
  167. * After Single Products Summary Div
  168. **/
  169. if (!function_exists('jigoshop_output_product_data_tabs')) {
  170. function jigoshop_output_product_data_tabs() {
  171. if (isset($_COOKIE["current_tab"])) $current_tab = $_COOKIE["current_tab"]; else $current_tab = '#tab-description';
  172. ?>
  173. <div id="tabs">
  174. <ul class="tabs">
  175. <?php do_action('jigoshop_product_tabs', $current_tab); ?>
  176. </ul>
  177. <?php do_action('jigoshop_product_tab_panels'); ?>
  178. </div>
  179. <?php
  180. }
  181. }
  182. /**
  183. * Product summary box
  184. **/
  185. if (!function_exists('jigoshop_template_single_title')) {
  186. function jigoshop_template_single_title( $post, $_product ) {
  187. ?><h1 class="product_title page-title"><?php echo apply_filters( 'jigoshop_single_product_title', the_title( '', '', false ) ); ?></h1><?php
  188. }
  189. }
  190. if (!function_exists('jigoshop_template_single_price')) {
  191. function jigoshop_template_single_price( $post, $_product ) {
  192. ?><p class="price"><?php echo apply_filters( 'jigoshop_single_product_price', $_product->get_price_html() ); ?></p><?php
  193. }
  194. }
  195. if (!function_exists('jigoshop_template_single_excerpt')) {
  196. function jigoshop_template_single_excerpt( $post, $_product ) {
  197. if ($post->post_excerpt) echo apply_filters( 'jigoshop_single_product_excerpt', wpautop(wptexturize($post->post_excerpt)) );
  198. }
  199. }
  200. if (!function_exists('jigoshop_template_single_meta')) {
  201. function jigoshop_template_single_meta( $post, $_product ) {
  202. $jigoshop_options = Jigoshop_Base::get_options();
  203. echo '<div class="product_meta">';
  204. if ($jigoshop_options->get_option('jigoshop_enable_sku')=='yes' && !empty($_product->sku)) :
  205. echo '<div class="sku">'.__('SKU','jigoshop').': ' . $_product->sku . '</div>';
  206. endif;
  207. echo $_product->get_categories( ', ', ' <div class="posted_in">' . __( 'Posted in ', 'jigoshop' ) . '', '.</div>');
  208. echo $_product->get_tags( ', ', ' <div class="tagged_as">' . __( 'Tagged as ', 'jigoshop' ) . '', '.</div>');
  209. echo '</div>';
  210. }
  211. }
  212. if (!function_exists('jigoshop_template_single_sharing')) {
  213. function jigoshop_template_single_sharing( $post, $_product ) {
  214. $jigoshop_options = Jigoshop_Base::get_options();
  215. if ($jigoshop_options->get_option('jigoshop_sharethis')) :
  216. echo '<div class="social">
  217. <iframe src="https://www.facebook.com/plugins/like.php?href='.urlencode(get_permalink($post->ID)).'&amp;layout=button_count&amp;show_faces=false&amp;width=100&amp;action=like&amp;colorscheme=light&amp;height=21" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:100px; height:21px;" allowTransparency="true"></iframe>
  218. <span class="st_twitter"></span><span class="st_email"></span><span class="st_sharethis"></span><span class="st_plusone_button"></span>
  219. </div>';
  220. endif;
  221. }
  222. }
  223. /**
  224. * Product Add to cart buttons
  225. **/
  226. if (!function_exists('jigoshop_template_single_add_to_cart')) {
  227. function jigoshop_template_single_add_to_cart( $post, $_product ) {
  228. $availability = $_product->get_availability();
  229. ?>
  230. <p class="stock <?php echo $availability['class'] ?>"><?php echo $availability['availability']; ?></p>
  231. <?php
  232. if ( $_product->is_in_stock() ) {
  233. do_action( $_product->product_type . '_add_to_cart' );
  234. }
  235. }
  236. }
  237. if (!function_exists('jigoshop_simple_add_to_cart')) {
  238. function jigoshop_simple_add_to_cart() {
  239. global $_product; $availability = $_product->get_availability();
  240. // do not show "add to cart" button if product's price isn't announced
  241. if( $_product->get_price() === '') return;
  242. ?>
  243. <form action="<?php echo esc_url( $_product->add_to_cart_url() ); ?>" class="cart" method="post">
  244. <?php do_action('jigoshop_before_add_to_cart_form_button'); ?>
  245. <div class="quantity"><input name="quantity" value="1" size="4" title="Qty" class="input-text qty text" maxlength="12" /></div>
  246. <button type="submit" class="button-alt"><?php _e('Add to cart', 'jigoshop'); ?></button>
  247. <?php do_action('jigoshop_add_to_cart_form'); ?>
  248. </form>
  249. <?php
  250. }
  251. }
  252. if (!function_exists('jigoshop_virtual_add_to_cart')) {
  253. function jigoshop_virtual_add_to_cart() {
  254. jigoshop_simple_add_to_cart();
  255. }
  256. }
  257. if (!function_exists('jigoshop_downloadable_add_to_cart')) {
  258. function jigoshop_downloadable_add_to_cart() {
  259. global $_product; $availability = $_product->get_availability();
  260. // do not show "add to cart" button if product's price isn't announced
  261. if( $_product->get_price() === '') return;
  262. ?>
  263. <form action="<?php echo esc_url( $_product->add_to_cart_url() ); ?>" class="cart" method="post">
  264. <?php do_action('jigoshop_before_add_to_cart_form_button'); ?>
  265. <button type="submit" class="button-alt"><?php _e('Add to cart', 'jigoshop'); ?></button>
  266. <?php do_action('jigoshop_add_to_cart_form'); ?>
  267. </form>
  268. <?php
  269. }
  270. }
  271. if (!function_exists('jigoshop_grouped_add_to_cart')) {
  272. function jigoshop_grouped_add_to_cart() {
  273. global $_product;
  274. if(!$_product->get_children()) return;
  275. ?>
  276. <form action="<?php echo esc_url( $_product->add_to_cart_url() ); ?>" class="cart" method="post">
  277. <table>
  278. <tbody>
  279. <?php foreach ($_product->get_children() as $child_ID) : $child = $_product->get_child($child_ID); $cavailability = $child->get_availability(); ?>
  280. <tr>
  281. <td><div class="quantity"><input name="quantity[<?php echo $child->ID; ?>]" value="0" size="4" title="Qty" class="input-text qty text" maxlength="12" /></div></td>
  282. <td><label for="product-<?php echo $child->id; ?>"><?php
  283. if ($child->is_visible()) echo '<a href="'.get_permalink($child->ID).'">';
  284. echo $child->get_title();
  285. if ($child->is_visible()) echo '</a>';
  286. ?></label></td>
  287. <td class="price"><?php echo $child->get_price_html(); ?><small class="stock <?php echo $cavailability['class'] ?>"><?php echo $cavailability['availability']; ?></small></td>
  288. </tr>
  289. <?php endforeach; ?>
  290. </tbody>
  291. </table>
  292. <?php do_action('jigoshop_before_add_to_cart_form_button'); ?>
  293. <button type="submit" class="button-alt"><?php _e('Add to cart', 'jigoshop'); ?></button>
  294. <?php do_action('jigoshop_add_to_cart_form'); ?>
  295. </form>
  296. <?php
  297. }
  298. }
  299. if (!function_exists('jigoshop_variable_add_to_cart')) {
  300. function jigoshop_variable_add_to_cart() {
  301. global $post, $_product;
  302. $jigoshop_options = Jigoshop_Base::get_options();
  303. $attributes = $_product->get_available_attributes_variations();
  304. //get all variations available as an array for easy usage by javascript
  305. $variationsAvailable = array();
  306. $children = $_product->get_children();
  307. foreach($children as $child) {
  308. /* @var $variation jigoshop_product_variation */
  309. $variation = $_product->get_child( $child );
  310. if($variation instanceof jigoshop_product_variation) {
  311. $vattrs = $variation->get_variation_attributes();
  312. $availability = $variation->get_availability();
  313. //@todo needs to be moved to jigoshop_product_variation class
  314. if (has_post_thumbnail($variation->get_variation_id())) {
  315. $attachment_id = get_post_thumbnail_id( $variation->get_variation_id() );
  316. $large_thumbnail_size = apply_filters('single_product_large_thumbnail_size', 'shop_large');
  317. $image = wp_get_attachment_image_src( $attachment_id, $large_thumbnail_size);
  318. if ( ! empty( $image ) ) $image = $image[0];
  319. $image_link = wp_get_attachment_image_src( $attachment_id, 'full');
  320. if ( ! empty( $image_link ) ) $image_link = $image_link[0];
  321. } else {
  322. $image = '';
  323. $image_link = '';
  324. }
  325. $a_weight = $a_length = $a_width = $a_height = '';
  326. if ( $variation->get_weight() ) {
  327. $a_weight = '
  328. <tr class="weight">
  329. <th>Weight</th>
  330. <td>'.$variation->get_weight().$jigoshop_options->get_option('jigoshop_weight_unit').'</td>
  331. </tr>';
  332. }
  333. if ( $variation->get_length() ) {
  334. $a_length = '
  335. <tr class="length">
  336. <th>Length</th>
  337. <td>'.$variation->get_length().$jigoshop_options->get_option('jigoshop_dimension_unit').'</td>
  338. </tr>';
  339. }
  340. if ( $variation->get_width() ) {
  341. $a_width = '
  342. <tr class="width">
  343. <th>Width</th>
  344. <td>'.$variation->get_width().$jigoshop_options->get_option('jigoshop_dimension_unit').'</td>
  345. </tr>';
  346. }
  347. if ( $variation->get_height() ) {
  348. $a_height = '
  349. <tr class="height">
  350. <th>Height</th>
  351. <td>'.$variation->get_height().$jigoshop_options->get_option('jigoshop_dimension_unit').'</td>
  352. </tr>
  353. ';
  354. }
  355. $variationsAvailable[] = array(
  356. 'variation_id' => $variation->get_variation_id(),
  357. 'sku' => '<div class="sku">'.__('SKU','jigoshop').': ' . $variation->get_sku() . '</div>',
  358. 'attributes' => $vattrs,
  359. 'in_stock' => $variation->is_in_stock(),
  360. 'image_src' => $image,
  361. 'image_link' => $image_link,
  362. 'price_html' => '<span class="price">'.$variation->get_price_html().'</span>',
  363. 'availability_html'=> '<p class="stock ' . esc_attr( $availability['class'] ) . '">'. $availability['availability'].'</p>',
  364. 'a_weight' => $a_weight,
  365. 'a_length' => $a_length,
  366. 'a_width' => $a_width,
  367. 'a_height' => $a_height,
  368. );
  369. }
  370. }
  371. ?>
  372. <script type="text/javascript">
  373. var product_variations = <?php echo json_encode($variationsAvailable) ?>;
  374. </script>
  375. <form action="<?php echo esc_url( $_product->add_to_cart_url() ); ?>" class="variations_form cart" method="post">
  376. <fieldset class="variations">
  377. <?php foreach ( $attributes as $name => $options ): ?>
  378. <?php $sanitized_name = sanitize_title( $name ); ?>
  379. <div>
  380. <span class="select_label"><?php echo jigoshop_product::attribute_label('pa_'.$name); ?></span>
  381. <select id="<?php echo esc_attr( $sanitized_name ); ?>" name="tax_<?php echo $sanitized_name; ?>">
  382. <option value=""><?php echo __('Choose an option ', 'jigoshop') ?>&hellip;</option>
  383. <?php foreach ( $options as $value ) : ?>
  384. <?php if ( taxonomy_exists( 'pa_'.$sanitized_name )) : ?>
  385. <?php $term = get_term_by( 'slug', $value, 'pa_'.$sanitized_name ); ?>
  386. <option value="<?php echo esc_attr( $term->slug ); ?>"><?php echo $term->name; ?></option>
  387. <?php else : ?>
  388. <option value="<?php echo esc_attr( sanitize_title( $value ) ); ?>"><?php echo $value; ?></option>
  389. <?php endif;?>
  390. <?php endforeach; ?>
  391. </select>
  392. </div>
  393. <?php endforeach;?>
  394. </fieldset>
  395. <div class="single_variation"></div>
  396. <?php do_action('jigoshop_before_add_to_cart_form_button'); ?>
  397. <div class="variations_button" style="display:none;">
  398. <input type="hidden" name="variation_id" value="" />
  399. <input type="hidden" name="product_id" value="<?php echo esc_attr( $post->ID ); ?>" />
  400. <div class="quantity"><input name="quantity" value="1" size="4" title="Qty" class="input-text qty text" maxlength="12" /></div>
  401. <input type="submit" class="button-alt" value="<?php esc_html_e('Add to cart', 'jigoshop'); ?>" />
  402. </div>
  403. <?php do_action('jigoshop_add_to_cart_form'); ?>
  404. </form>
  405. <?php
  406. }
  407. }
  408. if (!function_exists('jigoshop_external_add_to_cart')) {
  409. function jigoshop_external_add_to_cart() {
  410. global $_product;
  411. $external_url = get_post_meta( $_product->ID, 'external_url', true );
  412. if ( ! $external_url ) return false;
  413. ?>
  414. <form action="" class="cart" method="">
  415. <?php do_action('jigoshop_before_add_to_cart_form_button'); ?>
  416. <p>
  417. <a href="<?php echo esc_url( $external_url ); ?>" rel="nofollow" class="button"><?php _e('Buy product', 'jigoshop'); ?></a>
  418. </p>
  419. <?php do_action('jigoshop_add_to_cart_form'); ?>
  420. </form>
  421. <?php
  422. }
  423. }
  424. /**
  425. * Product Add to Cart forms
  426. **/
  427. if (!function_exists('jigoshop_add_to_cart_form_nonce')) {
  428. function jigoshop_add_to_cart_form_nonce() {
  429. jigoshop::nonce_field('add_to_cart');
  430. }
  431. }
  432. /**
  433. * Pagination
  434. **/
  435. if (!function_exists('jigoshop_pagination')) {
  436. function jigoshop_pagination() {
  437. global $wp_query;
  438. if ( $wp_query->max_num_pages > 1 ) :
  439. ?>
  440. <div class="navigation">
  441. <div class="nav-next"><?php next_posts_link( __( 'Next <span class="meta-nav">&rarr;</span>', 'jigoshop' ) ); ?></div>
  442. <div class="nav-previous"><?php previous_posts_link( __( '<span class="meta-nav">&larr;</span> Previous', 'jigoshop' ) ); ?></div>
  443. </div>
  444. <?php
  445. endif;
  446. }
  447. }
  448. /**
  449. * Product page tabs
  450. **/
  451. if (!function_exists('jigoshop_product_description_tab')) {
  452. function jigoshop_product_description_tab( $current_tab ) {
  453. global $post;
  454. if( ! $post->post_content )
  455. return false;
  456. ?>
  457. <li <?php if ($current_tab=='#tab-description') echo 'class="active"'; ?>><a href="#tab-description"><?php _e('Description', 'jigoshop'); ?></a></li>
  458. <?php
  459. }
  460. }
  461. if (!function_exists('jigoshop_product_attributes_tab')) {
  462. function jigoshop_product_attributes_tab( $current_tab ) {
  463. global $_product;
  464. if( ( $_product->has_attributes() || $_product->has_dimensions() || $_product->has_weight() ) ):
  465. ?>
  466. <li <?php if ($current_tab=='#tab-attributes') echo 'class="active"'; ?>><a href="#tab-attributes"><?php _e('Additional Information', 'jigoshop'); ?></a></li><?php endif;
  467. }
  468. }
  469. if (!function_exists('jigoshop_product_reviews_tab')) {
  470. function jigoshop_product_reviews_tab( $current_tab ) {
  471. if ( comments_open() ) : ?><li <?php if ($current_tab=='#tab-reviews') echo 'class="active"'; ?>><a href="#tab-reviews"><?php _e('Reviews', 'jigoshop'); ?><?php echo comments_number(' (0)', ' (1)', ' (%)'); ?></a></li><?php endif;
  472. }
  473. }
  474. if (!function_exists('jigoshop_product_customize_tab')) {
  475. function jigoshop_product_customize_tab( $current_tab ) {
  476. global $_product;
  477. if ( get_post_meta( $_product->ID , 'customizable', true ) == 'yes' ) {
  478. ?>
  479. <li <?php if ($current_tab=='#tab-customize') echo 'class="active"'; ?>><a href="#tab-customize"><?php _e('Personalize', 'jigoshop'); ?></a></li>
  480. <?php
  481. }
  482. }
  483. }
  484. /**
  485. * Product page tab panels
  486. **/
  487. if (!function_exists('jigoshop_product_description_panel')) {
  488. function jigoshop_product_description_panel() {
  489. $content = get_the_content();
  490. $content = apply_filters( 'the_content', $content );
  491. $content = str_replace( ']]>', ']]&gt;', $content );
  492. $content = apply_filters( 'jigoshop_single_product_content', $content );
  493. if ( $content <> '' ) {
  494. echo '<div class="panel" id="tab-description">';
  495. echo '<h2>' . apply_filters('jigoshop_product_description_heading', __('Product Description', 'jigoshop')) . '</h2>';
  496. // the following 3 lines replicate the behavior of 'the_content()'
  497. // non echoed so Rich Snippets can be applied via a filter
  498. echo $content;
  499. echo '</div>';
  500. }
  501. }
  502. }
  503. if (!function_exists('jigoshop_product_attributes_panel')) {
  504. function jigoshop_product_attributes_panel() {
  505. global $_product;
  506. $content = apply_filters( 'jigoshop_single_product_attributes', $_product->list_attributes() );
  507. if ( $content <> '' ) {
  508. echo '<div class="panel" id="tab-attributes">';
  509. echo '<h2>' . apply_filters('jigoshop_product_attributes_heading', __('Additional Information', 'jigoshop')) . '</h2>';
  510. echo $content;
  511. echo '</div>';
  512. }
  513. }
  514. }
  515. if (!function_exists('jigoshop_product_reviews_panel')) {
  516. function jigoshop_product_reviews_panel() {
  517. echo '<div class="panel" id="tab-reviews">';
  518. comments_template();
  519. echo '</div>';
  520. }
  521. }
  522. if (!function_exists('jigoshop_product_customize_panel')) {
  523. function jigoshop_product_customize_panel() {
  524. global $_product;
  525. if ( isset( $_POST['Submit'] ) && $_POST['Submit'] == __('Save Personalization', 'jigoshop') ) {
  526. $custom_products = (array) jigoshop_session::instance()->customized_products;
  527. $custom_products[$_POST['customized_id']] = trim( wptexturize( $_POST['jigoshop_customized_product'] ));
  528. jigoshop_session::instance()->customized_products = $custom_products;
  529. }
  530. if ( get_post_meta( $_product->ID , 'customizable', true ) == 'yes' ) :
  531. $custom_products = (array) jigoshop_session::instance()->customized_products;
  532. $custom = isset( $custom_products[$_product->ID] ) ? $custom_products[$_product->ID] : '';
  533. $custom_length = get_post_meta( $_product->ID , 'customized_length', true );
  534. $length_str = $custom_length == '' ? '' : sprintf( __( 'You may enter a maximum of %s characters.', 'jigoshop' ), $custom_length );
  535. echo '<div class="panel" id="tab-customize">';
  536. echo '<p>' . apply_filters('jigoshop_product_customize_heading', __('Enter your personal information as you want it to appear on the product.<br />', 'jigoshop').$length_str) . '</p>';
  537. ?>
  538. <form action="" method="post">
  539. <input type="hidden" name="customized_id" value="<?php echo esc_attr( $_product->ID ); ?>" />
  540. <?php
  541. if ( $custom_length == '' ) :
  542. ?>
  543. <textarea
  544. id="jigoshop_customized_product"
  545. name="jigoshop_customized_product"
  546. cols="60"
  547. rows="4"><?php echo esc_textarea( $custom ); ?></textarea>
  548. <?php else : ?>
  549. <input
  550. type="text"
  551. id="jigoshop_customized_product"
  552. name="jigoshop_customized_product"
  553. size="<?php echo $custom_length; ?>"
  554. maxlength="<?php echo $custom_length; ?>"
  555. value="<?php echo esc_attr( $custom ); ?>" />
  556. <?php endif; ?>
  557. <p class="submit"><input name="Submit" type="submit" class="button-alt add_personalization" value="<?php _e( "Save Personalization", 'jigoshop' ); ?>" /></p>
  558. </form>
  559. <?php
  560. echo '</div>';
  561. endif;
  562. }
  563. }
  564. /**
  565. * Jigoshop Product Thumbnail
  566. **/
  567. if (!function_exists('jigoshop_get_product_thumbnail')) {
  568. function jigoshop_get_product_thumbnail( $size = 'shop_small' ) {
  569. global $post;
  570. if ( has_post_thumbnail() )
  571. return get_the_post_thumbnail($post->ID, $size);
  572. else
  573. return jigoshop_get_image_placeholder( $size );
  574. }
  575. }
  576. /**
  577. * Jigoshop Product Category Image
  578. **/
  579. if (!function_exists('jigoshop_product_cat_image')) {
  580. function jigoshop_product_cat_image($id) {
  581. if( empty($id) )
  582. return false;
  583. $thumbnail_id = get_metadata('jigoshop_term', $id, 'thumbnail_id', true);
  584. $category_image = $thumbnail_id ? wp_get_attachment_url( $thumbnail_id )
  585. : jigoshop::assets_url().'/assets/images/placeholder.png';
  586. return array('image' => $category_image, 'thumb_id' => $thumbnail_id);
  587. }
  588. }
  589. /**
  590. * Jigoshop Product Image Placeholder
  591. * @since 0.9.9
  592. **/
  593. if (!function_exists('jigoshop_get_image_placeholder')) {
  594. function jigoshop_get_image_placeholder( $size = 'shop_small' ) {
  595. $image_size = jigoshop_get_image_size( $size );
  596. return '<img src="'.jigoshop::assets_url().'/assets/images/placeholder.png" alt="Placeholder" width="'.$image_size[0].'" height="'.$image_size[1].'" />';
  597. }
  598. }
  599. /**
  600. * Jigoshop Related Products
  601. **/
  602. if (!function_exists('jigoshop_output_related_products')) {
  603. function jigoshop_output_related_products() {
  604. $jigoshop_options = Jigoshop_Base::get_options();
  605. if ($jigoshop_options->get_option ('jigoshop_enable_related_products') != 'no')
  606. // 2 Related Products in 2 columns
  607. jigoshop_related_products( 2, 2 );
  608. }
  609. }
  610. if (!function_exists('jigoshop_related_products')) {
  611. function jigoshop_related_products( $posts_per_page = 4, $post_columns = 4, $orderby = 'rand' ) {
  612. global $_product, $columns, $per_page;
  613. // Pass vars to loop
  614. $per_page = $posts_per_page;
  615. $columns = $post_columns;
  616. $related = $_product->get_related( $posts_per_page );
  617. if (sizeof($related)>0) :
  618. echo '<div class="related products"><h2>'.__('Related Products', 'jigoshop').'</h2>';
  619. $args = array(
  620. 'post_type' => 'product',
  621. 'ignore_sticky_posts' => 1,
  622. 'posts_per_page' => $per_page,
  623. 'orderby' => $orderby,
  624. 'post__in' => $related
  625. );
  626. $args = apply_filters('jigoshop_related_products_args', $args);
  627. query_posts($args);
  628. jigoshop_get_template_part( 'loop', 'shop' );
  629. echo '</div>';
  630. wp_reset_query();
  631. endif;
  632. $per_page = null; // reset for cross sells if enabled
  633. $columns = null;
  634. }
  635. }
  636. /**
  637. * Jigoshop Shipping Calculator
  638. **/
  639. if (!function_exists('jigoshop_shipping_calculator')) {
  640. function jigoshop_shipping_calculator() {
  641. if (jigoshop_shipping::show_shipping_calculator()) :
  642. ?>
  643. <form class="shipping_calculator" action="<?php echo esc_url( jigoshop_cart::get_cart_url() ); ?>" method="post">
  644. <h2><a href="#" class="shipping-calculator-button"><?php _e('Calculate Shipping', 'jigoshop'); ?> <span>&darr;</span></a></h2>
  645. <section class="shipping-calculator-form">
  646. <p class="form-row">
  647. <select name="calc_shipping_country" id="calc_shipping_country" class="country_to_state" rel="calc_shipping_state">
  648. <?php
  649. foreach(jigoshop_countries::get_allowed_countries() as $key=>$value) :
  650. echo '<option value="'.esc_attr($key).'"';
  651. if (jigoshop_customer::get_shipping_country()==$key) echo 'selected="selected"';
  652. echo '>'.$value.'</option>';
  653. endforeach;
  654. ?>
  655. </select>
  656. </p>
  657. <div class="col2-set">
  658. <p class="form-row col-1">
  659. <?php
  660. $current_cc = jigoshop_customer::get_shipping_country();
  661. $current_r = jigoshop_customer::get_shipping_state();
  662. $states = jigoshop_countries::$states;
  663. if (jigoshop_countries::country_has_states($current_cc)) :
  664. // Dropdown
  665. ?>
  666. <span>
  667. <select name="calc_shipping_state" id="calc_shipping_state"><option value=""><?php _e('Select a state&hellip;', 'jigoshop'); ?></option><?php
  668. foreach($states[$current_cc] as $key=>$value) :
  669. echo '<option value="'.esc_attr($key).'"';
  670. if ($current_r==$key) echo 'selected="selected"';
  671. echo '>'.$value.'</option>';
  672. endforeach;
  673. ?></select>
  674. </span>
  675. <?php
  676. else :
  677. // Input
  678. ?>
  679. <input type="text" class="input-text" value="<?php echo esc_attr( $current_r ); ?>" placeholder="<?php _e('state', 'jigoshop'); ?>" name="calc_shipping_state" id="calc_shipping_state" />
  680. <?php
  681. endif;
  682. ?>
  683. </p>
  684. <p class="form-row col-2">
  685. <input type="text" class="input-text" value="<?php echo esc_attr( jigoshop_customer::get_shipping_postcode() ); ?>" placeholder="<?php _e('Postcode/Zip', 'jigoshop'); ?>" title="<?php _e('Postcode', 'jigoshop'); ?>" name="calc_shipping_postcode" id="calc_shipping_postcode" />
  686. </p>
  687. <?php do_action('jigoshop_after_shipping_calculator_fields');?>
  688. </div>
  689. <p><button type="submit" name="calc_shipping" value="1" class="button"><?php _e('Update Totals', 'jigoshop'); ?></button></p>
  690. <p>
  691. <?php
  692. $available_methods = jigoshop_shipping::get_available_shipping_methods();
  693. foreach ( $available_methods as $method ) :
  694. for ($i = 0; $i < $method->get_rates_amount(); $i++) {
  695. ?>
  696. <div class="col2-set">
  697. <p class="form-row col-1">
  698. <?php
  699. echo '<input type="radio" name="shipping_rates" value="' . esc_attr( $method->id . ':' . $i ) . '"' . ' class="shipping_select"';
  700. if ( $method->get_cheapest_service() == $method->get_selected_service($i) && $method->is_chosen() ) echo ' checked>'; else echo '>';
  701. echo $method->get_selected_service($i);
  702. ?>
  703. <p class="form-row col-2"><?php
  704. if ($method->get_selected_price($i) > 0) :
  705. echo jigoshop_price($method->get_selected_price($i));
  706. echo __(' (ex. tax)', 'jigoshop');
  707. else :
  708. echo __('Free', 'jigoshop');
  709. endif;
  710. ?>
  711. </div>
  712. <?php
  713. }
  714. endforeach;
  715. ?>
  716. <input type="hidden" name="cart-url" value="<?php echo esc_attr( jigoshop_cart::get_cart_url() ); ?>">
  717. <?php jigoshop::nonce_field('cart') ?>
  718. </section>
  719. </form>
  720. <?php
  721. endif;
  722. }
  723. }
  724. /**
  725. * Jigoshop Login Form
  726. **/
  727. if (!function_exists('jigoshop_login_form')) {
  728. function jigoshop_login_form() {
  729. if (is_user_logged_in()) return;
  730. ?>
  731. <form method="post" class="login">
  732. <p class="form-row form-row-first">
  733. <label for="username"><?php _e('Username', 'jigoshop'); ?> <span class="required">*</span></label>
  734. <input type="text" class="input-text" name="username" id="username" />
  735. </p>
  736. <p class="form-row form-row-last">
  737. <label for="password"><?php _e('Password', 'jigoshop'); ?> <span class="required">*</span></label>
  738. <input class="input-text" type="password" name="password" id="password" />
  739. </p>
  740. <div class="clear"></div>
  741. <p class="form-row">
  742. <?php jigoshop::nonce_field('login', 'login') ?>
  743. <input type="submit" class="button" name="login" value="<?php esc_html_e('Login', 'jigoshop'); ?>" />
  744. <a class="lost_password" href="<?php echo esc_url( wp_lostpassword_url( get_permalink() ) ); ?>"><?php _e('Lost Password?', 'jigoshop'); ?></a>
  745. </p>
  746. </form>
  747. <?php
  748. }
  749. }
  750. /**
  751. * Jigoshop Login Form
  752. **/
  753. if (!function_exists('jigoshop_checkout_login_form')) {
  754. function jigoshop_checkout_login_form() {
  755. $jigoshop_options = Jigoshop_Base::get_options();
  756. if (is_user_logged_in() || $jigoshop_options->get_option('jigoshop_enable_guest_login') != 'yes') return;
  757. ?><p class="info"><?php _e('Already registered?', 'jigoshop'); ?> <a href="#" class="showlogin"><?php _e('Click here to login', 'jigoshop'); ?></a></p><?php
  758. jigoshop_login_form();
  759. }
  760. }
  761. /**
  762. * Jigoshop Verify Checkout States Message
  763. **/
  764. if (!function_exists('jigoshop_verify_checkout_states_for_countries_message')) {
  765. function jigoshop_verify_checkout_states_for_countries_message() {
  766. // the following will return true or false if a country requires states
  767. if ( ! jigoshop_customer::has_valid_shipping_state() ) {
  768. echo '<div class="clearfix">&nbsp;</div><div class="jigoshop_error">' . __('Please verify your Billing and Shipping state is correctly set for your country before placing your Order.','jigoshop') . '</div>';
  769. }
  770. }
  771. }
  772. /**
  773. * Jigoshop Breadcrumb
  774. **/
  775. if (!function_exists('jigoshop_breadcrumb')) {
  776. function jigoshop_breadcrumb( $delimiter = ' &rsaquo; ', $wrap_before = '<div id="breadcrumb">', $wrap_after = '</div>', $before = '', $after = '', $home = null ) {
  777. global $post, $wp_query, $author, $paged;
  778. $jigoshop_options = Jigoshop_Base::get_options();
  779. if( !$home ) $home = _x('Home', 'breadcrumb', 'jigoshop');
  780. $home_link = home_url();
  781. $prepend = '';
  782. if ( $jigoshop_options->get_option('jigoshop_prepend_shop_page_to_urls')=="yes" && jigoshop_get_page_id('shop') && get_option('page_on_front') !== jigoshop_get_page_id('shop') )
  783. $prepend = $before . '<a href="' . esc_url( jigoshop_cart::get_shop_url() ). '">' . get_the_title( jigoshop_get_page_id('shop') ) . '</a> ' . $after . $delimiter;
  784. if ( (!is_home() && !is_front_page() && !(is_post_type_archive() && get_option('page_on_front')==jigoshop_get_page_id('shop'))) || is_paged() ) :
  785. echo $wrap_before;
  786. echo $before . '<a class="home" href="' . $home_link . '">' . $home . '</a> ' . $after . $delimiter ;
  787. if ( is_category() ) :
  788. $cat_obj = $wp_query->get_queried_object();
  789. $this_category = $cat_obj->term_id;
  790. $this_category = get_category( $this_category );
  791. if ($thisCat->parent != 0) :
  792. $parent_category = get_category( $this_category->parent );
  793. echo get_category_parents($parent_category, TRUE, $delimiter );
  794. endif;
  795. echo $before . single_cat_title('', false) . $after;
  796. elseif ( is_tax('product_cat') ) :
  797. //echo $before . '<a href="' . get_post_type_archive_link('product') . '">' . ucwords($jigoshop_options->get_option('jigoshop_shop_slug')) . '</a>' . $after . $delimiter;
  798. $term = get_term_by( 'slug', get_query_var( 'term' ), get_query_var( 'taxonomy' ) );
  799. $parents = array();
  800. $parent = $term->parent;
  801. while ($parent):
  802. $parents[] = $parent;
  803. $new_parent = get_term_by( 'id', $parent, get_query_var( 'taxonomy' ));
  804. $parent = $new_parent->parent;
  805. endwhile;
  806. if(!empty($parents)):
  807. $parents = array_reverse($parents);
  808. foreach ($parents as $parent):
  809. $item = get_term_by( 'id', $parent, get_query_var( 'taxonomy' ));
  810. echo $before . '<a href="' . get_term_link( $item->slug, 'product_cat' ) . '">' . $item->name . '</a>' . $after . $delimiter;
  811. endforeach;
  812. endif;
  813. $queried_object = $wp_query->get_queried_object();
  814. echo $prepend . $before . $queried_object->name . $after;
  815. elseif ( is_tax('product_tag') ) :
  816. $queried_object = $wp_query->get_queried_object();
  817. echo $prepend . $before . __('Products tagged &ldquo;', 'jigoshop') . $queried_object->name . '&rdquo;' . $after;
  818. elseif ( is_day() ) :
  819. echo $before . '<a href="' . get_year_link(get_the_time('Y')) . '">' . get_the_time('Y') . '</a>' . $after . $delimiter;
  820. echo $before . '<a href="' . get_month_link(get_the_time('Y'),get_the_time('m')) . '">' . get_the_time('F') . '</a>' . $after . $delimiter;
  821. echo $before . get_the_time('d') . $after;
  822. elseif ( is_month() ) :
  823. echo $before . '<a href="' . get_year_link(get_the_time('Y')) . '">' . get_the_time('Y') . '</a>' . $after . $delimiter;
  824. echo $before . get_the_time('F') . $after;
  825. elseif ( is_year() ) :
  826. echo $before . get_the_time('Y') . $after;
  827. elseif ( is_post_type_archive('product') && get_option('page_on_front') !== jigoshop_get_page_id('shop') ) :
  828. $_name = jigoshop_get_page_id('shop') ? get_the_title( jigoshop_get_page_id('shop') ) : ucwords($jigoshop_options->get_option('jigoshop_shop_slug'));
  829. if (is_search()) :
  830. echo $before . '<a href="' . get_post_type_archive_link('product') . '">' . $_name . '</a>' . $delimiter . __('Search results for &ldquo;', 'jigoshop') . get_search_query() . '&rdquo;' . $after;
  831. else :
  832. echo $before . '<a href="' . get_post_type_archive_link('product') . '">' . $_name . '</a>' . $after;
  833. endif;
  834. elseif ( is_single() && !is_attachment() ) :
  835. if ( get_post_type() == 'product' ) :
  836. //echo $before . '<a href="' . get_post_type_archive_link('product') . '">' . ucwords($jigoshop_options->get_option('jigoshop_shop_slug')) . '</a>' . $after . $delimiter;
  837. echo $prepend;
  838. if ($terms = get_the_terms( $post->ID, 'product_cat' )) :
  839. $term = apply_filters( 'jigoshop_product_cat_breadcrumb_terms', current($terms), $terms);
  840. $parents = array();
  841. $parent = $term->parent;
  842. while ($parent):
  843. $parents[] = $parent;
  844. $new_parent = get_term_by( 'id', $parent, 'product_cat');
  845. $parent = $new_parent->parent;
  846. endwhile;
  847. if(!empty($parents)):
  848. $parents = array_reverse($parents);
  849. foreach ($parents as $parent):
  850. $item = get_term_by( 'id', $parent, 'product_cat');
  851. echo $before . '<a href="' . get_term_link( $item->slug, 'product_cat' ) . '">' . $item->name . '</a>' . $after . $delimiter;
  852. endforeach;
  853. endif;
  854. echo $before . '<a href="' . get_term_link( $term->slug, 'product_cat' ) . '">' . $term->name . '</a>' . $after . $delimiter;
  855. endif;
  856. echo $before . get_the_title() . $after;
  857. elseif ( get_post_type() != 'post' ) :
  858. $post_type = get_post_type_object(get_post_type());
  859. $slug = $post_type->rewrite;
  860. echo $before . '<a href="' . get_post_type_archive_link(get_post_type()) . '">' . $post_type->labels->singular_name . '</a>' . $after . $delimiter;
  861. echo $before . get_the_title() . $after;
  862. else :
  863. $cat = current(get_the_category());
  864. echo get_category_parents($cat, TRUE, $delimiter);
  865. echo $before . get_the_title() . $after;
  866. endif;
  867. elseif ( is_404() ) :
  868. echo $before . __('Error 404', 'jigoshop') . $after;
  869. elseif ( !is_single() && !is_page() && get_post_type() != 'post' ) :
  870. $post_type = get_post_type_object(get_post_type());
  871. if ($post_type) : echo $before . $post_type->labels->singular_name . $after; endif;
  872. elseif ( is_attachment() ) :
  873. $parent = get_post($post->post_parent);
  874. $cat = get_the_category($parent->ID); $cat = $cat[0];
  875. echo get_category_parents($cat, TRUE, '' . $delimiter);
  876. echo $before . '<a href="' . get_permalink($parent) . '">' . $parent->post_title . '</a>' . $after . $delimiter;
  877. echo $before . get_the_title() . $after;
  878. elseif ( is_page() && !$post->post_parent ) :
  879. echo $before . get_the_title() . $after;
  880. elseif ( is_page() && $post->post_parent ) :
  881. $parent_id = $post->post_parent;
  882. $breadcrumbs = array();
  883. while ($parent_id) {
  884. $page = get_page($parent_id);
  885. $breadcrumbs[] = '<a href="' . get_permalink($page->ID) . '">' . get_the_title($page->ID) . '</a>';
  886. $parent_id = $page->post_parent;
  887. }
  888. $breadcrumbs = array_reverse($breadcrumbs);
  889. foreach ($breadcrumbs as $crumb) :
  890. echo $crumb . '' . $delimiter;
  891. endforeach;
  892. echo $before . get_the_title() . $after;
  893. elseif ( is_search() ) :
  894. echo $before . __('Search results for &ldquo;', 'jigoshop') . get_search_query() . '&rdquo;' . $after;
  895. elseif ( is_tag() ) :
  896. echo $before . __('Posts tagged &ldquo;', 'jigoshop') . single_tag_title('', false) . '&rdquo;' . $after;
  897. elseif ( is_author() ) :
  898. $userdata = get_userdata($author);
  899. echo $before . __('Author: ', 'jigoshop') . $userdata->display_name . $after;
  900. endif;
  901. if ( get_query_var('paged') ) :
  902. echo ' (' . __('Page', 'jigoshop') . ' ' . get_query_var('paged') .')';
  903. endif;
  904. echo $wrap_after;
  905. endif;
  906. }
  907. }
  908. /**
  909. * Hook to remove the 'singular' class, for the twenty eleven theme, to properly display the sidebar
  910. *
  911. * @param array $classes
  912. */
  913. function jigoshop_body_classes ($classes) {
  914. if( ! is_content_wrapped() ) return $classes;
  915. $key = array_search('singular', $classes);
  916. if ( $key !== false ) unset($classes[$key]);
  917. return $classes;
  918. }
  919. /**
  920. * Order review table for checkout
  921. **/
  922. function jigoshop_order_review() {
  923. jigoshop_get_template('checkout/review_order.php', false);
  924. }