/jigoshop_shortcodes.php

https://github.com/steveclarkcouk/jigoshop · PHP · 256 lines · 2 code · 1 blank · 253 comment · 0 complexity · 616993b5347afbf829e05cd4db18a9ed MD5 · raw file

  1. <?php
  2. /**
  3. * Jigoshop shortcodes
  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 (c) 2011 Jigowatt Ltd.
  15. * @license http://jigoshop.com/license/commercial-edition
  16. */
  17. foreach(glob( dirname(__FILE__)."/shortcodes/*.php" ) as $filename) include_once($filename);
  18. //### Recent Products #########################################################
  19. function jigoshop_recent_products( $atts ) {
  20. global $columns, $per_page;
  21. extract( shortcode_atts( array(
  22. 'per_page' => get_option('jigoshop_catalog_per_page'),
  23. 'columns' => get_option('jigoshop_catalog_columns'),
  24. 'orderby' => get_option('jigoshop_catalog_sort_orderby'),
  25. 'order' => get_option('jigoshop_catalog_sort_direction')
  26. ), $atts));
  27. $args = array(
  28. 'post_type' => 'product',
  29. 'post_status' => 'publish',
  30. 'ignore_sticky_posts' => 1,
  31. 'posts_per_page' => $per_page,
  32. 'orderby' => $orderby,
  33. 'order' => $order,
  34. 'meta_query' => array(
  35. array(
  36. 'key' => 'visibility',
  37. 'value' => array( 'catalog', 'visible' ),
  38. 'compare' => 'IN'
  39. )
  40. )
  41. );
  42. query_posts( $args );
  43. ob_start();
  44. jigoshop_get_template_part( 'loop', 'shop' );
  45. wp_reset_query();
  46. return ob_get_clean();
  47. }
  48. //### Multiple Products #########################################################
  49. function jigoshop_products( $atts ){
  50. global $columns;
  51. if ( empty( $atts )) return;
  52. extract( shortcode_atts( array(
  53. 'per_page' => get_option('jigoshop_catalog_per_page'),
  54. 'columns' => get_option('jigoshop_catalog_columns'),
  55. 'orderby' => get_option('jigoshop_catalog_sort_orderby'),
  56. 'order' => get_option('jigoshop_catalog_sort_direction')
  57. ), $atts));
  58. $args = array(
  59. 'post_type' => 'product',
  60. 'post_status' => 'publish',
  61. 'ignore_sticky_posts' => 1,
  62. 'orderby' => $orderby,
  63. 'order' => $order,
  64. 'meta_query' => array(
  65. array(
  66. 'key' => 'visibility',
  67. 'value' => array( 'catalog', 'visible' ),
  68. 'compare' => 'IN'
  69. )
  70. )
  71. );
  72. if ( isset( $atts['skus'] )){
  73. $skus = explode( ',', $atts['skus'] );
  74. array_walk( $skus, create_function('&$val', '$val = trim($val);') );
  75. $args['meta_query'][] = array(
  76. 'key' => 'sku',
  77. 'value' => $skus,
  78. 'compare' => 'IN'
  79. );
  80. }
  81. if ( isset( $atts['ids'] )){
  82. $ids = explode( ',', $atts['ids'] );
  83. array_walk( $ids, create_function('&$val', '$val = trim($val);') );
  84. $args['post__in'] = $ids;
  85. }
  86. query_posts( $args );
  87. ob_start();
  88. jigoshop_get_template_part( 'loop', 'shop' );
  89. wp_reset_query();
  90. return ob_get_clean();
  91. }
  92. //### Single Product ############################################################
  93. function jigoshop_product( $atts ){
  94. if ( empty( $atts )) return;
  95. $args = array(
  96. 'post_type' => 'product',
  97. 'posts_per_page' => 1,
  98. 'post_status' => 'publish',
  99. 'meta_query' => array(
  100. array(
  101. 'key' => 'visibility',
  102. 'value' => array( 'catalog', 'visible' ),
  103. 'compare' => 'IN'
  104. )
  105. )
  106. );
  107. if ( isset( $atts['sku'] )){
  108. $args['meta_query'][] = array(
  109. 'key' => 'sku',
  110. 'value' => $atts['sku'],
  111. 'compare' => '='
  112. );
  113. }
  114. if ( isset( $atts['id'] )){
  115. $args['p'] = $atts['id'];
  116. }
  117. query_posts( $args );
  118. ob_start();
  119. jigoshop_get_template_part( 'loop', 'shop' );
  120. wp_reset_query();
  121. return ob_get_clean();
  122. }
  123. //### Featured Products #########################################################
  124. function jigoshop_featured_products( $atts ) {
  125. global $columns, $per_page;
  126. extract( shortcode_atts( array(
  127. 'per_page' => get_option('jigoshop_catalog_per_page'),
  128. 'columns' => get_option('jigoshop_catalog_columns'),
  129. 'orderby' => get_option('jigoshop_catalog_sort_orderby'),
  130. 'order' => get_option('jigoshop_catalog_sort_direction')
  131. ), $atts));
  132. $args = array(
  133. 'post_type' => 'product',
  134. 'post_status' => 'publish',
  135. 'ignore_sticky_posts' => 1,
  136. 'posts_per_page' => $per_page,
  137. 'orderby' => $orderby,
  138. 'order' => $order,
  139. 'meta_query' => array(
  140. array(
  141. 'key' => 'visibility',
  142. 'value' => array( 'catalog', 'visible' ),
  143. 'compare' => 'IN'
  144. ),
  145. array(
  146. 'key' => 'featured',
  147. 'value' => 'yes'
  148. )
  149. )
  150. );
  151. query_posts( $args );
  152. ob_start();
  153. jigoshop_get_template_part( 'loop', 'shop' );
  154. wp_reset_query();
  155. return ob_get_clean();
  156. }
  157. //### Category #########################################################
  158. function jigoshop_product_category( $atts ) {
  159. global $columns, $per_page;
  160. if ( empty( $atts ) ) return;
  161. extract( shortcode_atts( array(
  162. 'slug' => '',
  163. 'per_page' => get_option('jigoshop_catalog_per_page'),
  164. 'columns' => get_option('jigoshop_catalog_columns'),
  165. 'orderby' => get_option('jigoshop_catalog_sort_orderby'),
  166. 'order' => get_option('jigoshop_catalog_sort_direction')
  167. ), $atts));
  168. if ( ! $slug ) return;
  169. $args = array(
  170. 'post_type' => 'product',
  171. 'post_status' => 'publish',
  172. 'ignore_sticky_posts' => 1,
  173. 'posts_per_page' => $per_page,
  174. 'orderby' => $orderby,
  175. 'order' => $order,
  176. 'meta_query' => array(
  177. array(
  178. 'key' => 'visibility',
  179. 'value' => array( 'catalog', 'visible' ),
  180. 'compare' => 'IN'
  181. )
  182. ),
  183. 'tax_query' => array(
  184. array(
  185. 'taxonomy' => 'product_cat',
  186. 'field' => 'slug',
  187. 'terms' => esc_attr( $slug ),
  188. 'operator' => 'IN'
  189. )
  190. )
  191. );
  192. query_posts( $args );
  193. ob_start();
  194. jigoshop_get_template_part( 'loop', 'shop' );
  195. wp_reset_query();
  196. return ob_get_clean();
  197. }
  198. //### Shortcodes #########################################################
  199. add_shortcode('product', 'jigoshop_product');
  200. add_shortcode('products', 'jigoshop_products');
  201. add_shortcode('recent_products', 'jigoshop_recent_products');
  202. add_shortcode('featured_products', 'jigoshop_featured_products');
  203. add_shortcode('jigoshop_category', 'jigoshop_product_category');
  204. add_shortcode('jigoshop_cart', 'get_jigoshop_cart');
  205. add_shortcode('jigoshop_checkout', 'get_jigoshop_checkout');
  206. add_shortcode('jigoshop_order_tracking', 'get_jigoshop_order_tracking');
  207. add_shortcode('jigoshop_my_account', 'get_jigoshop_my_account');
  208. add_shortcode('jigoshop_edit_address', 'get_jigoshop_edit_address');
  209. add_shortcode('jigoshop_change_password', 'get_jigoshop_change_password');
  210. add_shortcode('jigoshop_view_order', 'get_jigoshop_view_order');
  211. add_shortcode('jigoshop_pay', 'get_jigoshop_pay');
  212. add_shortcode('jigoshop_thankyou', 'get_jigoshop_thankyou');