PageRenderTime 48ms CodeModel.GetById 12ms RepoModel.GetById 0ms app.codeStats 1ms

/skeleton/jigoshop_functions.php

https://github.com/gellybeans/skeleton_wp
PHP | 811 lines | 557 code | 170 blank | 84 comment | 105 complexity | 37ce6e6a4fac1a1311eaf6e2fe66eca8 MD5 | raw file
Possible License(s): AGPL-1.0
  1. <?php
  2. /**
  3. * ACTIONS USED IN TEMPLATE FILES
  4. *
  5. **/
  6. // add_image_size( $name, $width, $height, $crop );
  7. add_image_size( 'shop_tiny', jigoshop::get_var('shop_tiny_w'), jigoshop::get_var('shop_tiny_h'), 'true' );
  8. add_image_size( 'shop_thumbnail', jigoshop::get_var('shop_thumbnail_w'), jigoshop::get_var('shop_thumbnail_h'), 'true' );
  9. add_image_size( 'shop_small', jigoshop::get_var('shop_small_w'), jigoshop::get_var('shop_small_h'), 'true' );
  10. add_image_size( 'shop_large', '280', '150', 'true' );
  11. /* Content Wrappers */
  12. remove_action( 'jigoshop_before_main_content', 'jigoshop_output_content_wrapper', 10);
  13. remove_action( 'jigoshop_after_main_content', 'jigoshop_output_content_wrapper_end', 10);
  14. /* Shop Messages */
  15. add_action( 'jigoshop_before_single_product', 'jigoshop::show_messages', 10);
  16. add_action( 'jigoshop_before_shop_loop', 'jigoshop::show_messages', 10);
  17. /* Sale flashes */
  18. add_action( 'jigoshop_before_shop_loop_item_title', 'jigoshop_show_product_sale_flash', 10, 2);
  19. add_action( 'jigoshop_before_single_product_summary', 'jigoshop_show_product_sale_flash', 10, 2);
  20. /* Breadcrumbs */
  21. add_action( 'jigoshop_before_main_content', 'jigoshop_breadcrumb', 20, 0);
  22. /* Products Loop */
  23. add_action( 'jigoshop_after_shop_loop_item', 'jigoshop_template_loop_add_to_cart', 10, 2);
  24. add_action( 'jigoshop_before_shop_loop_item_title', 'jigoshop_template_loop_product_thumbnail', 10, 2);
  25. add_action( 'jigoshop_after_shop_loop_item_title', 'jigoshop_template_loop_price', 10, 2);
  26. /* Before Single Products */
  27. add_action( 'jigoshop_before_single_product', 'jigoshop_check_product_visibility', 10, 2);
  28. /* Before Single Products Summary Div */
  29. add_action( 'jigoshop_before_single_product_summary', 'jigoshop_show_product_images', 20);
  30. add_action( 'jigoshop_product_thumbnails', 'jigoshop_show_product_thumbnails', 20 );
  31. /* After Single Products Summary Div */
  32. add_action( 'jigoshop_after_single_product_summary', 'jigoshop_output_product_data_tabs', 10);
  33. add_action( 'jigoshop_after_single_product_summary', 'jigoshop_output_related_products', 20);
  34. /* Product Summary Box */
  35. add_action( 'jigoshop_template_single_summary', 'jigoshop_template_single_price', 10, 2);
  36. add_action( 'jigoshop_template_single_summary', 'jigoshop_template_single_excerpt', 20, 2);
  37. add_action( 'jigoshop_template_single_summary', 'jigoshop_template_single_meta', 40, 2);
  38. add_action( 'jigoshop_template_single_summary', 'jigoshop_template_single_sharing', 50, 2);
  39. /* Product Add to cart */
  40. add_action( 'jigoshop_template_single_summary', 'jigoshop_template_single_add_to_cart', 30, 2 );
  41. add_action( 'simple_add_to_cart', 'jigoshop_simple_add_to_cart' );
  42. add_action( 'virtual_add_to_cart', 'jigoshop_simple_add_to_cart' );
  43. add_action( 'downloadable_add_to_cart', 'jigoshop_downloadable_add_to_cart' );
  44. add_action( 'grouped_add_to_cart', 'jigoshop_grouped_add_to_cart' );
  45. /* Product Add to Cart forms */
  46. add_action( 'jigoshop_add_to_cart_form', 'jigoshop_add_to_cart_form_nonce', 10);
  47. /* Pagination in loop-shop */
  48. add_action( 'jigoshop_pagination', 'jigoshop_pagination', 10 );
  49. /* Product page tabs */
  50. add_action( 'jigoshop_product_tabs', 'jigoshop_product_description_tab', 10 );
  51. add_action( 'jigoshop_product_tabs', 'jigoshop_product_attributes_tab', 20 );
  52. add_action( 'jigoshop_product_tabs', 'jigoshop_product_reviews_tab', 30 );
  53. add_action( 'jigoshop_product_tab_panels', 'jigoshop_product_description_panel', 10 );
  54. add_action( 'jigoshop_product_tab_panels', 'jigoshop_product_attributes_panel', 20 );
  55. add_action( 'jigoshop_product_tab_panels', 'jigoshop_product_reviews_panel', 30 );
  56. /* Checkout */
  57. add_action( 'before_checkout_form', 'jigoshop_checkout_login_form', 10 );
  58. /**
  59. * FUNCTIONS USED IN TEMPLATE FILES
  60. **/
  61. /**
  62. * Sale Flash
  63. **/
  64. if (!function_exists('jigoshop_show_product_sale_flash')) {
  65. function jigoshop_show_product_sale_flash( $post, $_product ) {
  66. if ($_product->is_on_sale()) echo '<span class="onsale">'.__('Sale!', 'jigoshop').'</span>';
  67. }
  68. }
  69. /**
  70. * Sidebar
  71. **/
  72. if (!function_exists('jigoshop_get_sidebar')) {
  73. function jigoshop_get_sidebar() {
  74. get_sidebar('shop');
  75. }
  76. }
  77. /**
  78. * Products Loop
  79. **/
  80. if (!function_exists('jigoshop_template_loop_add_to_cart')) {
  81. function jigoshop_template_loop_add_to_cart( $post, $_product ) {
  82. $output = '<div class="button small left">';
  83. // do not show "add to cart" button if product's price isn't announced
  84. if ( $_product->get_price() === '' AND ! ($_product->is_type(array('variable', 'grouped', 'external'))) ) return;
  85. if ( $_product->is_in_stock() OR $_product->is_type('external') ) :
  86. if ( $_product->is_type(array('variable', 'grouped')) ) :
  87. $output .= '<a href="'.get_permalink($_product->id).'" class="button">'.__('&nbsp;&nbsp; Select &nbsp;&nbsp;', 'jigoshop').'</a>';
  88. elseif ( $_product->is_type('external') ) :
  89. $output .= '<a href="'.get_post_meta( $_product->id, 'external_url', true ).'" class="button">'.__('Buy product', 'jigoshop').'</a>';
  90. else :
  91. $output .= '<a href="'.esc_url($_product->add_to_cart_url()).'" class="button">'.__('Add to cart', 'jigoshop').'</a>';
  92. endif;
  93. elseif ( ($_product->is_type(array('grouped')) ) ) :
  94. return;
  95. else :
  96. $output .= '<span class="nostock">'.__('Out of Stock', 'jigoshop').'</span>';
  97. endif;
  98. $output .= '</div>';
  99. echo $output;
  100. }
  101. }
  102. if (!function_exists('jigoshop_template_loop_product_thumbnail')) {
  103. function jigoshop_template_loop_product_thumbnail( $post, $_product ) {
  104. echo jigoshop_get_product_thumbnail();
  105. }
  106. }
  107. if (!function_exists('jigoshop_template_loop_price')) {
  108. function jigoshop_template_loop_price( $post, $_product ) {
  109. ?><span class="price"><?php echo $_product->get_price_html(); ?></span><?php
  110. }
  111. }
  112. /**
  113. * Check product visibility in loop
  114. **/
  115. if (!function_exists('jigoshop_check_product_visibility')) {
  116. function jigoshop_check_product_visibility( $post, $_product ) {
  117. if (!$_product->is_visible() && $post->post_parent > 0) : wp_safe_redirect(get_permalink($post->post_parent)); exit; endif;
  118. if (!$_product->is_visible()) : wp_safe_redirect(home_url()); exit; endif;
  119. }
  120. }
  121. /**
  122. * Before Single Products Summary Div
  123. **/
  124. if (!function_exists('jigoshop_show_product_images')) {
  125. function jigoshop_show_product_images() {
  126. global $_product, $post;
  127. echo '<div class="images two_thirds">';
  128. $thumb_id = 0;
  129. if (has_post_thumbnail()) :
  130. $thumb_id = get_post_thumbnail_id();
  131. $large_thumbnail_size = apply_filters('single_product_large_thumbnail_size', 'shop_large');
  132. echo '<a href="'.wp_get_attachment_url($thumb_id).'" class="scale-with-grid zoom" rel="thumbnails">';
  133. the_post_thumbnail($large_thumbnail_size);
  134. echo '</a>';
  135. else :
  136. echo '<img src="'.jigoshop::plugin_url().'/assets/images/placeholder.png" alt="Placeholder" />';
  137. endif;
  138. do_action('jigoshop_product_thumbnails');
  139. echo '</div>';
  140. }
  141. }
  142. if (!function_exists('jigoshop_show_product_thumbnails')) {
  143. function jigoshop_show_product_thumbnails() {
  144. global $_product, $post;
  145. echo '<div class="thumbnails">';
  146. $thumb_id = get_post_thumbnail_id();
  147. $small_thumbnail_size = apply_filters('single_product_small_thumbnail_size', 'shop_thumbnail');
  148. $args = array( 'post_type' => 'attachment', 'numberposts' => -1, 'post_status' => null, 'post_parent' => $post->ID );
  149. $attachments = get_posts($args);
  150. if ($attachments) :
  151. $loop = 0;
  152. $columns = 3;
  153. foreach ( $attachments as $attachment ) :
  154. if ($thumb_id==$attachment->ID) continue;
  155. $loop++;
  156. $_post = & get_post( $attachment->ID );
  157. $url = wp_get_attachment_url($_post->ID);
  158. $post_title = esc_attr($_post->post_title);
  159. $image = wp_get_attachment_image($attachment->ID, $small_thumbnail_size);
  160. echo '<a href="'.$url.'" title="'.$post_title.'" rel="thumbnails" class="scale-with-grid zoom ';
  161. if ($loop==1 || ($loop-1)%$columns==0) echo 'first';
  162. if ($loop%$columns==0) echo 'last';
  163. echo '">'.$image.'</a>';
  164. endforeach;
  165. endif;
  166. wp_reset_query();
  167. echo '</div>';
  168. }
  169. }
  170. /**
  171. * After Single Products Summary Div
  172. **/
  173. if (!function_exists('jigoshop_output_product_data_tabs')) {
  174. function jigoshop_output_product_data_tabs() {
  175. if (isset($_COOKIE["current_tab"])) $current_tab = $_COOKIE["current_tab"]; else $current_tab = '#tab-description';
  176. ?>
  177. <div id="tabs">
  178. <ul class="tabs">
  179. <?php do_action('jigoshop_product_tabs', $current_tab); ?>
  180. </ul>
  181. <?php do_action('jigoshop_product_tab_panels'); ?>
  182. </div>
  183. <?php
  184. }
  185. }
  186. /**
  187. * Product summary box
  188. **/
  189. if (!function_exists('jigoshop_template_single_price')) {
  190. function jigoshop_template_single_price( $post, $_product ) {
  191. ?><p class="price"><?php echo $_product->get_price_html(); ?></p><?php
  192. }
  193. }
  194. if (!function_exists('jigoshop_template_single_excerpt')) {
  195. function jigoshop_template_single_excerpt( $post, $_product ) {
  196. if ($post->post_excerpt) echo wpautop(wptexturize($post->post_excerpt));
  197. }
  198. }
  199. if (!function_exists('jigoshop_template_single_meta')) {
  200. function jigoshop_template_single_meta( $post, $_product ) {
  201. ?>
  202. <div class="product_meta"><?php if ($_product->is_type('simple')) : ?><span class="sku">SKU: <?php echo $_product->sku; ?>.</span> <?php endif; ?><?php echo $_product->get_categories( ', ', 'Posted in ', '.'); ?> <?php echo $_product->get_tags( ', ', 'Tagged as ', '.'); ?></div>
  203. <?php
  204. }
  205. }
  206. if (!function_exists('jigoshop_template_single_sharing')) {
  207. function jigoshop_template_single_sharing( $post, $_product ) {
  208. if (get_option('jigoshop_sharethis')) :
  209. echo '<div class="social">
  210. <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>
  211. <span class="st_email"></span><span class="st_twitter"></span><span class="st_sharethis"></span>
  212. </div>';
  213. endif;
  214. }
  215. }
  216. /**
  217. * Product Add to cart buttons
  218. **/
  219. if (!function_exists('jigoshop_template_single_add_to_cart')) {
  220. function jigoshop_template_single_add_to_cart( $post, $_product ) {
  221. do_action( $_product->product_type . '_add_to_cart' );
  222. }
  223. }
  224. if (!function_exists('jigoshop_simple_add_to_cart')) {
  225. function jigoshop_simple_add_to_cart() {
  226. global $_product; $availability = $_product->get_availability();
  227. if ($availability['availability']) : ?><p class="stock <?php echo $availability['class'] ?>"><?php echo $availability['availability']; ?></p><?php endif;
  228. ?>
  229. <form action="<?php echo $_product->add_to_cart_url(); ?>" class="cart" method="post">
  230. <div class="quantity"><input name="quantity" value="1" size="4" title="Qty" class="input_tiny qty" maxlength="12" /></div>
  231. <input type="submit" value="<?php _e('Add to cart', 'jigoshop'); ?>">
  232. <?php do_action('jigoshop_add_to_cart_form'); ?>
  233. </form>
  234. <?php
  235. }
  236. }
  237. if (!function_exists('jigoshop_downloadable_add_to_cart')) {
  238. function jigoshop_downloadable_add_to_cart() {
  239. global $_product; $availability = $_product->get_availability();
  240. if ($availability['availability']) : ?><p class="stock <?php echo $availability['class'] ?>"><?php echo $availability['availability']; ?></p><?php endif;
  241. ?>
  242. <form action="<?php echo $_product->add_to_cart_url(); ?>" class="cart" method="post">
  243. <button type="submit" class="button"><?php _e('Add to cart', 'jigoshop'); ?></button>
  244. <?php do_action('jigoshop_add_to_cart_form'); ?>
  245. </form>
  246. <?php
  247. }
  248. }
  249. if (!function_exists('jigoshop_grouped_add_to_cart')) {
  250. function jigoshop_grouped_add_to_cart() {
  251. global $_product;
  252. ?>
  253. <form action="<?php echo $_product->add_to_cart_url(); ?>" class="cart" method="post">
  254. <table cellspacing="0">
  255. <tbody>
  256. <?php foreach ($_product->children as $child) : $child_product = &new jigoshop_product( $child->ID ); $cavailability = $child_product->get_availability(); ?>
  257. <tr>
  258. <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>
  259. <td><label for="product-<?php echo $child_product->id; ?>"><?php
  260. if ($child_product->is_visible()) echo '<a href="'.get_permalink($child->ID).'">';
  261. echo $child_product->get_title();
  262. if ($child_product->is_visible()) echo '</a>';
  263. ?></label></td>
  264. <td class="price"><?php echo $child_product->get_price_html(); ?><small class="stock <?php echo $cavailability['class'] ?>"><?php echo $cavailability['availability']; ?></small></td>
  265. </tr>
  266. <?php endforeach; ?>
  267. </tbody>
  268. </table>
  269. <button type="submit" class="button"><?php _e('Add to cart', 'jigoshop'); ?></button>
  270. <?php do_action('jigoshop_add_to_cart_form'); ?>
  271. </form>
  272. <?php
  273. }
  274. }
  275. /**
  276. * Product Add to Cart forms
  277. **/
  278. if (!function_exists('jigoshop_add_to_cart_form_nonce')) {
  279. function jigoshop_add_to_cart_form_nonce() {
  280. jigoshop::nonce_field('add_to_cart');
  281. }
  282. }
  283. /**
  284. * Pagination
  285. **/
  286. if (!function_exists('jigoshop_pagination')) {
  287. function jigoshop_pagination() {
  288. global $wp_query;
  289. if ( $wp_query->max_num_pages > 1 ) :
  290. ?>
  291. <div class="navigation">
  292. <div class="nav-next"><?php next_posts_link( __( 'Next <span class="meta-nav">&rarr;</span>', 'jigoshop' ) ); ?></div>
  293. <div class="nav-previous"><?php previous_posts_link( __( '<span class="meta-nav">&larr;</span> Previous', 'jigoshop' ) ); ?></div>
  294. </div>
  295. <?php
  296. endif;
  297. }
  298. }
  299. /**
  300. * Product page tabs
  301. **/
  302. if (!function_exists('jigoshop_product_description_tab')) {
  303. function jigoshop_product_description_tab( $current_tab ) {
  304. ?>
  305. <li <?php if ($current_tab=='#tab-description') echo 'class="active"'; ?>><a href="#tab-description"><?php _e('Description', 'jigoshop'); ?></a></li>
  306. <?php
  307. }
  308. }
  309. if (!function_exists('jigoshop_product_attributes_tab')) {
  310. function jigoshop_product_attributes_tab( $current_tab ) {
  311. global $_product;
  312. if ($_product->has_attributes()) : ?><li <?php if ($current_tab=='#tab-attributes') echo 'class="active"'; ?>><a href="#tab-attributes"><?php _e('Additional Information', 'jigoshop'); ?></a></li><?php endif;
  313. }
  314. }
  315. if (!function_exists('jigoshop_product_reviews_tab')) {
  316. function jigoshop_product_reviews_tab( $current_tab ) {
  317. 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;
  318. }
  319. }
  320. /**
  321. * Product page tab panels
  322. **/
  323. if (!function_exists('jigoshop_product_description_panel')) {
  324. function jigoshop_product_description_panel() {
  325. echo '<div class="panel" id="tab-description">';
  326. echo '<h2>' . apply_filters('jigoshop_product_description_heading', __('Product Description', 'jigoshop')) . '</h2>';
  327. the_content();
  328. echo '</div>';
  329. }
  330. }
  331. if (!function_exists('jigoshop_product_attributes_panel')) {
  332. function jigoshop_product_attributes_panel() {
  333. global $_product;
  334. echo '<div class="panel" id="tab-attributes">';
  335. echo '<h2>' . apply_filters('jigoshop_product_description_heading', __('Additional Information', 'jigoshop')) . '</h2>';
  336. $_product->list_attributes();
  337. echo '</div>';
  338. }
  339. }
  340. if (!function_exists('jigoshop_product_reviews_panel')) {
  341. function jigoshop_product_reviews_panel() {
  342. echo '<div class="panel" id="tab-reviews">';
  343. comments_template();
  344. echo '</div>';
  345. }
  346. }
  347. /**
  348. * Jigoshop Product Thumbnail
  349. **/
  350. if (!function_exists('jigoshop_get_product_thumbnail')) {
  351. function jigoshop_get_product_thumbnail( $size = 'shop_small', $placeholder_width = 0, $placeholder_height = 0 ) {
  352. global $post;
  353. if (!$placeholder_width) $placeholder_width = jigoshop::get_var('shop_small_w');
  354. if (!$placeholder_height) $placeholder_height = jigoshop::get_var('shop_small_h');
  355. if ( has_post_thumbnail() ) return get_the_post_thumbnail($post->ID, $size); else return '<img class="scale-with-grid" src="'.jigoshop::plugin_url(). '/assets/images/placeholder.png" alt="Placeholder" width="'.$placeholder_width.'" height="'.$placeholder_height.'" />';
  356. }
  357. }
  358. /**
  359. * Jigoshop Related Products
  360. **/
  361. if (!function_exists('jigoshop_output_related_products')) {
  362. function jigoshop_output_related_products() {
  363. // 4 Related Products in 4 columns
  364. jigoshop_related_products( 2, 2 );
  365. }
  366. }
  367. if (!function_exists('jigoshop_related_products')) {
  368. function jigoshop_related_products( $posts_per_page = 4, $post_columns = 4, $orderby = 'rand' ) {
  369. global $_product, $columns, $per_page;
  370. // Pass vars to loop
  371. $per_page = $posts_per_page;
  372. $columns = $post_columns;
  373. $related = $_product->get_related();
  374. if (sizeof($related)>0) :
  375. echo '<div class="related products">';
  376. // echo '<h2>'.__('Related Products', 'jigoshop').'</h2>';
  377. $args = array(
  378. 'post_type' => 'product',
  379. 'ignore_sticky_posts' => 1,
  380. 'posts_per_page' => $per_page,
  381. 'orderby' => $orderby,
  382. 'post__in' => $related
  383. );
  384. $args = apply_filters('jigoshop_related_products_args', $args);
  385. query_posts($args);
  386. jigoshop_get_template_part( 'loop', 'shop' );
  387. echo '</div>';
  388. endif;
  389. wp_reset_query();
  390. }
  391. }
  392. /**
  393. * Jigoshop Shipping Calculator
  394. **/
  395. if (!function_exists('jigoshop_shipping_calculator')) {
  396. function jigoshop_shipping_calculator() {
  397. if (jigoshop_cart::needs_shipping()) :
  398. ?>
  399. <form class="shipping_calculator" action="<?php echo jigoshop_cart::get_cart_url(); ?>" method="post">
  400. <h4><a href="#" class="shipping-calculator-button"><?php _e('Calculate Shipping', 'jigoshop'); ?> <span>&darr;</span></a></h4>
  401. <section class="shipping-calculator-form">
  402. <p class="form-row">
  403. <select name="calc_shipping_country" id="calc_shipping_country" class="country_to_state" rel="calc_shipping_state">
  404. <option value=""><?php _e('Select a country&hellip;', 'jigoshop'); ?></option>
  405. <?php
  406. foreach(jigoshop_countries::get_allowed_countries() as $key=>$value) :
  407. echo '<option value="'.$key.'"';
  408. if (jigoshop_customer::get_shipping_country()==$key) echo 'selected="selected"';
  409. echo '>'.$value.'</option>';
  410. endforeach;
  411. ?>
  412. </select>
  413. </p>
  414. <div class="col2-set">
  415. <p class="form-row col-1">
  416. <?php
  417. $current_cc = jigoshop_customer::get_shipping_country();
  418. $current_r = jigoshop_customer::get_shipping_state();
  419. $states = jigoshop_countries::$states;
  420. if (isset( $states[$current_cc][$current_r] )) :
  421. // Dropdown
  422. ?>
  423. <span>
  424. <select name="calc_shipping_state" id="calc_shipping_state"><option value=""><?php _e('Select a state&hellip;', 'jigoshop'); ?></option><?php
  425. foreach($states[$current_cc] as $key=>$value) :
  426. echo '<option value="'.$key.'"';
  427. if ($current_r==$key) echo 'selected="selected"';
  428. echo '>'.$value.'</option>';
  429. endforeach;
  430. ?></select>
  431. </span>
  432. <?php
  433. else :
  434. // Input
  435. ?>
  436. <input type="text" class="input-text" value="<?php echo $current_r; ?>" placeholder="<?php _e('state', 'jigoshop'); ?>" name="calc_shipping_state" id="calc_shipping_state" />
  437. <?php
  438. endif;
  439. ?>
  440. </p>
  441. <p class="form-row col-2">
  442. <input type="text" class="input-text" value="<?php echo jigoshop_customer::get_shipping_postcode(); ?>" placeholder="<?php _e('Postcode/Zip', 'jigoshop'); ?>" title="<?php _e('Postcode', 'jigoshop'); ?>" name="calc_shipping_postcode" id="calc_shipping_postcode" />
  443. </p>
  444. </div>
  445. <p><button type="submit" name="calc_shipping" value="1" class="button"><?php _e('Update Totals', 'jigoshop'); ?></button></p>
  446. <?php jigoshop::nonce_field('cart') ?>
  447. </section>
  448. </form>
  449. <?php
  450. endif;
  451. }
  452. }
  453. /**
  454. * Jigoshop Login Form
  455. **/
  456. if (!function_exists('jigoshop_login_form')) {
  457. function jigoshop_login_form() {
  458. if (is_user_logged_in()) return;
  459. ?>
  460. <form method="post" class="login">
  461. <p class="form-row form-row-first">
  462. <label for="username"><?php _e('Username', 'jigoshop'); ?> <span class="required">*</span></label>
  463. <input type="text" class="input-text" name="username" id="username" />
  464. </p>
  465. <p class="form-row form-row-last">
  466. <label for="password"><?php _e('Password', 'jigoshop'); ?> <span class="required">*</span></label>
  467. <input class="input-text" type="password" name="password" id="password" />
  468. </p>
  469. <div class="clear"></div>
  470. <p class="form-row">
  471. <?php jigoshop::nonce_field('login', 'login') ?>
  472. <input type="submit" class="button" name="login" value="<?php _e('Login', 'jigoshop'); ?>" />
  473. <a class="lost_password" href="<?php echo home_url('wp-login.php?action=lostpassword'); ?>"><?php _e('Lost Password?', 'jigoshop'); ?></a>
  474. </p>
  475. </form>
  476. <?php
  477. }
  478. }
  479. /**
  480. * Jigoshop Login Form
  481. **/
  482. if (!function_exists('jigoshop_checkout_login_form')) {
  483. function jigoshop_checkout_login_form() {
  484. if (is_user_logged_in()) return;
  485. ?><p class="info"><?php _e('Already registered?', 'jigoshop'); ?> <a href="#" class="showlogin"><?php _e('Click here to login', 'jigoshop'); ?></a></p><?php
  486. jigoshop_login_form();
  487. }
  488. }
  489. /**
  490. * Jigoshop Breadcrumb
  491. **/
  492. if (!function_exists('jigoshop_breadcrumb')) {
  493. function jigoshop_breadcrumb(
  494. $delimiter = '<span class="sep">&raquo;</span>',
  495. $wrap_before = '<div id="breadcrumb">',
  496. $wrap_after = '</div>', $before = '',
  497. $after = '', $home = null) {
  498. global $post, $wp_query, $author;
  499. if( !$home ) $home = _x('Home', 'breadcrumb', 'jigoshop');
  500. $home_link = home_url();
  501. $prepend = '';
  502. if ( get_option('jigoshop_prepend_shop_page_to_urls')=="yes" && get_option('jigoshop_shop_page_id') )
  503. $prepend = $before . '<a href="' . get_permalink( get_option('jigoshop_shop_page_id') ) . '">' . get_the_title( get_option('jigoshop_shop_page_id') ) . '</a> ' . $after . $delimiter;
  504. if ( !is_home() && !is_front_page() || is_paged() ) :
  505. echo $wrap_before;
  506. echo $before . '<a class="home" href="' . $home_link . '">' . $home . '</a> ' . $after . $delimiter ;
  507. if ( is_category() ) :
  508. $cat_obj = $wp_query->get_queried_object();
  509. $this_category = $cat_obj->term_id;
  510. $this_category = get_category( $this_category );
  511. if ($thisCat->parent != 0) :
  512. $parent_category = get_category( $this_category->parent );
  513. echo get_category_parents($parent_category, TRUE, $delimiter );
  514. endif;
  515. echo $before . single_cat_title('', false) . $after;
  516. elseif ( is_tax('product_cat') ) :
  517. //echo $before . '<a href="' . get_post_type_archive_link('product') . '">' . ucwords(get_option('jigoshop_shop_slug')) . '</a>' . $after . $delimiter;
  518. $term = get_term_by( 'slug', get_query_var( 'term' ), get_query_var( 'taxonomy' ) );
  519. $parents = array();
  520. $parent = $term->parent;
  521. while ($parent):
  522. $parents[] = $parent;
  523. $new_parent = get_term_by( 'id', $parent, get_query_var( 'taxonomy' ));
  524. $parent = $new_parent->parent;
  525. endwhile;
  526. if(!empty($parents)):
  527. $parents = array_reverse($parents);
  528. foreach ($parents as $parent):
  529. $item = get_term_by( 'id', $parent, get_query_var( 'taxonomy' ));
  530. echo $before . '<a href="' . get_term_link( $item->slug, 'product_cat' ) . '">' . $item->name . '</a>' . $after . $delimiter;
  531. endforeach;
  532. endif;
  533. $queried_object = $wp_query->get_queried_object();
  534. echo $prepend . $before . $queried_object->name . $after;
  535. elseif ( is_tax('product_tag') ) :
  536. $queried_object = $wp_query->get_queried_object();
  537. echo $prepend . $before . __('Products tagged &ldquo;', 'jigoshop') . $queried_object->name . '&rdquo;' . $after;
  538. elseif ( is_day() ) :
  539. echo $before . '<a href="' . get_year_link(get_the_time('Y')) . '">' . get_the_time('Y') . '</a>' . $after . $delimiter;
  540. echo $before . '<a href="' . get_month_link(get_the_time('Y'),get_the_time('m')) . '">' . get_the_time('F') . '</a>' . $after . $delimiter;
  541. echo $before . get_the_time('d') . $after;
  542. elseif ( is_month() ) :
  543. echo $before . '<a href="' . get_year_link(get_the_time('Y')) . '">' . get_the_time('Y') . '</a>' . $after . $delimiter;
  544. echo $before . get_the_time('F') . $after;
  545. elseif ( is_year() ) :
  546. echo $before . get_the_time('Y') . $after;
  547. elseif ( is_post_type_archive('product') ) :
  548. $_name = get_option('jigoshop_shop_page_id') ? get_the_title( get_option('jigoshop_shop_page_id') ) : ucwords(get_option('jigoshop_shop_slug'));
  549. if (is_search()) :
  550. echo $before . '<a href="' . get_post_type_archive_link('product') . '">' . $_name . '</a>' . $delimiter . __('Search results for &ldquo;', 'jigoshop') . get_search_query() . '&rdquo;' . $after;
  551. else :
  552. echo $before . '<a href="' . get_post_type_archive_link('product') . '">' . $_name . '</a>' . $after;
  553. endif;
  554. elseif ( is_single() && !is_attachment() ) :
  555. if ( get_post_type() == 'product' ) :
  556. //echo $before . '<a href="' . get_post_type_archive_link('product') . '">' . ucwords(get_option('jigoshop_shop_slug')) . '</a>' . $after . $delimiter;
  557. echo $prepend;
  558. if ($terms = wp_get_object_terms( $post->ID, 'product_cat' )) :
  559. $term = current($terms);
  560. $parents = array();
  561. $parent = $term->parent;
  562. while ($parent):
  563. $parents[] = $parent;
  564. $new_parent = get_term_by( 'id', $parent, 'product_cat');
  565. $parent = $new_parent->parent;
  566. endwhile;
  567. if(!empty($parents)):
  568. $parents = array_reverse($parents);
  569. foreach ($parents as $parent):
  570. $item = get_term_by( 'id', $parent, 'product_cat');
  571. echo $before . '<a href="' . get_term_link( $item->slug, 'product_cat' ) . '">' . $item->name . '</a>' . $after . $delimiter;
  572. endforeach;
  573. endif;
  574. echo $before . '<a href="' . get_term_link( $term->slug, 'product_cat' ) . '">' . $term->name . '</a>' . $after . $delimiter;
  575. endif;
  576. echo $before . get_the_title() . $after;
  577. elseif ( get_post_type() != 'post' ) :
  578. $post_type = get_post_type_object(get_post_type());
  579. $slug = $post_type->rewrite;
  580. echo $before . '<a href="' . get_post_type_archive_link(get_post_type()) . '">' . $post_type->labels->singular_name . '</a>' . $after . $delimiter;
  581. echo $before . get_the_title() . $after;
  582. else :
  583. $cat = current(get_the_category());
  584. echo get_category_parents($cat, TRUE, $delimiter);
  585. echo $before . get_the_title() . $after;
  586. endif;
  587. elseif ( is_404() ) :
  588. echo $before . __('Error 404', 'jigoshop') . $after;
  589. elseif ( !is_single() && !is_page() && get_post_type() != 'post' ) :
  590. $post_type = get_post_type_object(get_post_type());
  591. if ($post_type) : echo $before . $post_type->labels->singular_name . $after; endif;
  592. elseif ( is_attachment() ) :
  593. $parent = get_post($post->post_parent);
  594. $cat = get_the_category($parent->ID); $cat = $cat[0];
  595. echo get_category_parents($cat, TRUE, '' . $delimiter);
  596. echo $before . '<a href="' . get_permalink($parent) . '">' . $parent->post_title . '</a>' . $after . $delimiter;
  597. echo $before . get_the_title() . $after;
  598. elseif ( is_page() && !$post->post_parent ) :
  599. echo $before . get_the_title() . $after;
  600. elseif ( is_page() && $post->post_parent ) :
  601. $parent_id = $post->post_parent;
  602. $breadcrumbs = array();
  603. while ($parent_id) {
  604. $page = get_page($parent_id);
  605. $breadcrumbs[] = '<a href="' . get_permalink($page->ID) . '">' . get_the_title($page->ID) . '</a>';
  606. $parent_id = $page->post_parent;
  607. }
  608. $breadcrumbs = array_reverse($breadcrumbs);
  609. foreach ($breadcrumbs as $crumb) :
  610. echo $crumb . '' . $delimiter;
  611. endforeach;
  612. echo $before . get_the_title() . $after;
  613. elseif ( is_search() ) :
  614. echo $before . __('Search results for &ldquo;', 'jigoshop') . get_search_query() . '&rdquo;' . $after;
  615. elseif ( is_tag() ) :
  616. echo $before . __('Posts tagged &ldquo;', 'jigoshop') . single_tag_title('', false) . '&rdquo;' . $after;
  617. elseif ( is_author() ) :
  618. $userdata = get_userdata($author);
  619. echo $before . __('Author: ', 'jigoshop') . $userdata->display_name . $after;
  620. endif;
  621. if ( get_query_var('paged') ) :
  622. echo ' (' . __('Page', 'jigoshop') . ' ' . get_query_var('paged') .')';
  623. endif;
  624. echo $wrap_after;
  625. endif;
  626. }
  627. }
  628. if (of_get_option('show_mini_cart')) {
  629. function st_header_extras() {
  630. $extras = "<div class=\"header_extras\">";
  631. $extras .= '<a href="'.jigoshop_cart::get_cart_url().'" class="minicart">';
  632. $extras .= '<span>';
  633. $extras .= jigoshop_cart::$cart_contents_count.' items';
  634. $extras .= '</span>';
  635. $extras .= jigoshop_cart::get_cart_total();
  636. $extras .= '</a>';
  637. $extras .= "</div>";
  638. echo apply_filters ('child_header_extras',$extras);
  639. }
  640. } // endif
  641. add_action('st_header','st_header_extras', 2);