Advertisement
Guest User

Untitled

a guest
May 24th, 2018
183
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 101.52 KB | None | 0 0
  1. <?php
  2.  
  3. if ( ! function_exists( 'mp_get_product_class' ) ) :
  4.  
  5. /**
  6. * Retrieve the list of classes for the product as an array.
  7. *
  8. * The class names are add are many. If the post is a sticky, then the 'sticky'
  9. * class name. The class 'hentry' is always added to each post. For each
  10. * category, the class will be added with 'category-' with category slug is
  11. * added. The tags are the same way as the categories with 'tag-' before the tag
  12. * slug. All classes are passed through the filter, 'post_class' with the list
  13. * of classes, followed by $class parameter value, with the post ID as the last
  14. * parameter.
  15. *
  16. *
  17. * @param string|array $class One or more classes to add to the class list.
  18. * @param int $post_id The post_id for the product. Optional if in the loop
  19. *
  20. * @return array Array of classes.
  21. */
  22. function mp_get_product_class( $class = '', $post_id = null ) {
  23. global $id;
  24. $post_id = ( null === $post_id ) ? $id : $post_id;
  25.  
  26. $post = get_post( $post_id );
  27.  
  28. $classes = array();
  29.  
  30. if ( empty( $post ) ) {
  31. return $classes;
  32. }
  33.  
  34. $classes[] = 'product-' . $post->ID;
  35. $classes[] = $post->post_type;
  36. $classes[] = 'type-' . $post->post_type;
  37.  
  38. // sticky for Sticky Posts
  39. if ( is_sticky( $post->ID ) ) {
  40. $classes[] = 'sticky';
  41. }
  42.  
  43. // hentry for hAtom compliace
  44. $classes[] = 'hentry';
  45.  
  46. // Categories
  47. $categories = get_the_terms( $post->ID, "product_category" );
  48. foreach ( (array) $categories as $cat ) {
  49. if ( empty( $cat->slug ) || ! isset( $cat->cat_ID ) ) {
  50. continue;
  51. }
  52. $classes[] = 'category-' . sanitize_html_class( $cat->slug, $cat->cat_ID );
  53. }
  54.  
  55. // Tags
  56. $tags = get_the_terms( $post->ID, "product_tag" );
  57. foreach ( (array) $tags as $tag ) {
  58. if ( empty( $tag->slug ) ) {
  59. continue;
  60. }
  61. $classes[] = 'tag-' . sanitize_html_class( $tag->slug, $tag->term_id );
  62. }
  63.  
  64. if ( ! empty( $class ) ) {
  65. if ( ! is_array( $class ) ) {
  66. $class = preg_split( '#\s+#', $class );
  67. }
  68. $classes = array_merge( $classes, $class );
  69. }
  70.  
  71. $classes = array_map( 'esc_attr', $classes );
  72.  
  73. return apply_filters( 'mp_get_product_class', $classes, $class, $post_id );
  74. }
  75.  
  76. endif;
  77.  
  78. if ( ! function_exists( 'mp_product_class' ) ) :
  79.  
  80. /**
  81. * Display the classes for the product div.
  82. *
  83. * @param bool $echo Whether to echo class.
  84. * @param string|array $class One or more classes to add to the class list.
  85. * @param int $post_id The post_id for the product. Optional if in the loop
  86. */
  87. function mp_product_class( $echo = true, $class = '', $post_id = null ) {
  88. // Separates classes with a single space, collates classes for post DIV
  89. $content = 'class="' . join( ' ', mp_get_product_class( $class, $post_id ) ) . '"';
  90.  
  91. $content = apply_filters( 'mp_product_class', $content, $class, $post_id );
  92.  
  93. if ( $echo ) {
  94. echo $content;
  95. } else {
  96. return $content;
  97. }
  98. }
  99.  
  100. endif;
  101.  
  102. if ( ! function_exists( 'mp_product_sku' ) ) :
  103. /*
  104. * function mp_product_sku
  105. *
  106. * @param bool $echo default true
  107. * @param int $post_id The post_id of the product. Optional if in the loop
  108. * @param string $seperator The seperator to put between skus, default ', '
  109. *
  110. * Returns or echos html of variation SKUs
  111. */
  112.  
  113. function mp_product_sku( $echo = true, $post_id = null ) {
  114. global $id, $mp;
  115. $post_id = ( null === $post_id ) ? $id : $post_id;
  116.  
  117. $sku = get_post_meta( $post_id, "sku", true );
  118. $html = '<span class="mp_product_skus">' . $sku . '</span>';
  119.  
  120. $html = apply_filters( 'mp_product_skus', $html, $post_id, $sku );
  121.  
  122. if ( $echo ) {
  123. echo $html;
  124. } else {
  125. return $html;
  126. }
  127. }
  128.  
  129. endif;
  130.  
  131.  
  132. if ( ! function_exists( 'mp_product_price' ) ) :
  133. /*
  134. * Displays the product price (and sale price)
  135. *
  136. * @param bool $echo Optional, whether to echo
  137. * @param int $post_id The post_id for the product. Optional if in the loop
  138. * @param sting $label A label to prepend to the price. Defaults to "Price: "
  139. */
  140.  
  141. function mp_product_price( $echo = true, $post_id = null, $label = true ) {
  142. global $id, $mp;
  143.  
  144. $price_html = '';
  145.  
  146. $product = new MP_Product( $post_id );
  147.  
  148. $label = ( $label === true ) ? __( 'Price: ', 'mp' ) : $label; //should be empty from 3.0
  149.  
  150. $price_html .= $product->display_price( false );
  151.  
  152. $price_html = apply_filters( 'mp_product_price_html', $price_html, $post_id, $label, $product->display_price( false ) );
  153.  
  154. if ( $echo ) {
  155. echo $price_html;
  156. } else {
  157. return $price_html;
  158. }
  159. }
  160.  
  161. endif;
  162.  
  163. if ( ! function_exists( 'mp_store_navigation' ) ) :
  164.  
  165. /**
  166. * Echos the current store navigation links.
  167. *
  168. * @param bool $echo Optional, whether to echo. Defaults to true
  169. */
  170. function mp_store_navigation( $echo = true ) {
  171. //navigation
  172. if ( ! mp_get_setting( 'disable_cart' ) ) {
  173. $nav = '<ul class="mp_store_navigation"><li class="page_item"><a href="' . mp_products_link( false, true ) . '" title="' . __( 'Products', 'mp' ) . '">' . __( 'Products', 'mp' ) . '</a></li>';
  174. $nav .= '<li class="page_item"><a href="' . mp_cart_link( false, true ) . '" title="' . __( 'Shopping Cart', 'mp' ) . '">' . __( 'Shopping Cart', 'mp' ) . '</a></li>';
  175. $nav .= '<li class="page_item"><a href="' . mp_orderstatus_link( false, true ) . '" title="' . __( 'Order Status', 'mp' ) . '">' . __( 'Order Status', 'mp' ) . '</a></li>
  176. </ul>';
  177. } else {
  178. $nav = '<ul class="mp_store_navigation">
  179. <li class="page_item"><a href="' . mp_products_link( false, true ) . '" title="' . __( 'Products', 'mp' ) . '">' . __( 'Products', 'mp' ) . '</a></li>
  180. </ul>';
  181. }
  182.  
  183. $nav = apply_filters( 'mp_store_navigation', $nav );
  184.  
  185. if ( $echo ) {
  186. echo $nav;
  187. } else {
  188. return $nav;
  189. }
  190. }
  191.  
  192. endif;
  193.  
  194. if ( ! function_exists( 'mp_orderstatus_link' ) ) :
  195.  
  196. /**
  197. * Echos the current order status link.
  198. *
  199. * @param bool $echo Optional, whether to echo. Defaults to true
  200. * @param bool $url Optional, whether to return a link or url. Defaults to show link.
  201. * @param string $link_text Optional, text to show in link.
  202. * @param string $order Optional, the order id to append to the link
  203. */
  204. function mp_orderstatus_link( $echo = true, $url = false, $link_text = '', $order_id = '' ) {
  205. $link = get_permalink( mp_get_setting( 'pages->order_status' ) );
  206. if ( ! $url ) {
  207. $text = ( $link_text ) ? $link_text : __( 'Check Order Status', 'mp' );
  208. $link = '<a href="' . $link . '" class="mp_orderstatus_link">' . $text . '</a>';
  209. }
  210.  
  211. $link = apply_filters( 'mp_orderstatus_link', $link, $echo, $url, $link_text );
  212.  
  213. if ( $echo ) {
  214. echo $link;
  215. } else {
  216. return $link;
  217. }
  218. }
  219.  
  220. endif;
  221.  
  222. if ( ! function_exists( 'mp_products_link' ) ) :
  223.  
  224. /**
  225. * Echos the current product list link.
  226. *
  227. * @param bool $echo Optional, whether to echo. Defaults to true
  228. * @param bool $url Optional, whether to return a link or url. Defaults to show link.
  229. * @param string $link_text Optional, text to show in link.
  230. */
  231. function mp_products_link( $echo = true, $url = false, $link_text = '' ) {
  232. $link = get_permalink( mp_get_setting( 'pages->products' ) );
  233.  
  234. if ( ! $url ) {
  235. $text = ( $link_text ) ? $link_text : __( 'View Products', 'mp' );
  236. $link = '<a href="' . $link . '" class="mp_products_link">' . $text . '</a>';
  237. }
  238.  
  239. $link = apply_filters( 'mp_products_link', $link, $echo, $url, $link_text );
  240.  
  241. if ( $echo ) {
  242. echo $link;
  243. } else {
  244. return $link;
  245. }
  246. }
  247.  
  248. endif;
  249.  
  250. if ( ! function_exists( 'mp_store_link' ) ) :
  251.  
  252. /**
  253. * Echos the current store link.
  254. *
  255. * @param bool $echo Optional, whether to echo. Defaults to true
  256. * @param bool $url Optional, whether to return a link or url. Defaults to show link.
  257. * @param string $link_text Optional, text to show in link.
  258. */
  259. function mp_store_link( $echo = true, $url = false, $link_text = '' ) {
  260. $link = get_permalink( mp_get_setting( 'pages->store' ) );
  261.  
  262. if ( ! $url ) {
  263. $text = ( $link_text ) ? $link_text : __( 'Visit Store', 'mp' );
  264. $link = '<a href="' . $link . '" class="mp_store_link">' . $text . '</a>';
  265. }
  266.  
  267. $link = apply_filters( 'mp_store_link', $link, $echo, $url, $link_text );
  268.  
  269. if ( $echo ) {
  270. echo $link;
  271. } else {
  272. return $link;
  273. }
  274. }
  275.  
  276. endif;
  277.  
  278. /**
  279. * Display or retrieve the HTML dropdown list of product categories.
  280. *
  281. * The list of arguments is below:
  282. * 'show_option_all' (string) - Text to display for showing all categories.
  283. * 'show_option_none' (string) - Text to display for showing no categories.
  284. * 'orderby' (string) default is 'ID' - What column to use for ordering the
  285. * categories.
  286. * 'order' (string) default is 'ASC' - What direction to order categories.
  287. * 'show_last_update' (bool|int) default is 0 - See {@link get_categories()}
  288. * 'show_count' (bool|int) default is 0 - Whether to show how many posts are
  289. * in the category.
  290. * 'hide_empty' (bool|int) default is 1 - Whether to hide categories that
  291. * don't have any posts attached to them.
  292. * 'child_of' (int) default is 0 - See {@link get_categories()}.
  293. * 'exclude' (string) - See {@link get_categories()}.
  294. * 'depth' (int) - The max depth.
  295. * 'tab_index' (int) - Tab index for select element.
  296. * 'name' (string) - The name attribute value for select element.
  297. * 'id' (string) - The ID attribute value for select element. Defaults to name if omitted.
  298. * 'class' (string) - The class attribute value for select element.
  299. * 'selected' (int) - Which category ID is selected.
  300. * 'taxonomy' (string) - The name of the taxonomy to retrieve. Defaults to category.
  301. *
  302. * The 'hierarchical' argument, which is disabled by default, will override the
  303. * depth argument, unless it is true. When the argument is false, it will
  304. * display all of the categories. When it is enabled it will use the value in
  305. * the 'depth' argument.
  306. *
  307. *
  308. * @param bool $echo Optional. Whether or not to echo.
  309. * @param string|array $args Optional. Override default arguments.
  310. */
  311. if ( ! function_exists( 'mp_dropdown_categories' ) ) {
  312.  
  313. function mp_dropdown_categories( $echo = true, $args = '' ) {
  314. $args['taxonomy'] = 'product_category';
  315. $args['echo'] = false;
  316. $args['id'] = 'mp_category_dropdown';
  317. $args['value_field'] = 'slug';
  318.  
  319. $dropdown = wp_dropdown_categories( $args );
  320. $dropdown .= '<script type="text/javascript">
  321. var dropdown = document.getElementById("mp_category_dropdown");
  322. function onCatChange() {
  323. location.href = "' . get_home_url() . '/?product_category="+dropdown.options[dropdown.selectedIndex].value;
  324. }
  325. dropdown.onchange = onCatChange;
  326. </script>';
  327. //get_category_link
  328.  
  329. $dropdown = apply_filters( 'mp_dropdown_categories', $dropdown, $args );
  330.  
  331. if ( $echo ) {
  332. echo $dropdown;
  333. } else {
  334. return $dropdown;
  335. }
  336. }
  337.  
  338. }
  339.  
  340. if ( ! function_exists( 'mp_main_site_id' ) ) {
  341.  
  342. function mp_main_site_id() {
  343. global $current_site;
  344. if ( MP_ROOT_BLOG !== false ) {
  345. return MP_ROOT_BLOG;
  346. } else {
  347. return $current_site->blog_id;
  348. }
  349. }
  350.  
  351. }
  352.  
  353. if ( ! function_exists( 'mp_number_format' ) ) {
  354.  
  355. function mp_number_format( $amount, $decimal_place, $force_basic = false ) {
  356.  
  357. if ( (int) ( $amount ) == (float) $amount ) {
  358. $int_decimals = 0;
  359. } else {
  360. $int_decimals = 2;
  361. }
  362.  
  363. $curr_decimal = mp_get_setting( 'curr_decimal', 1 );
  364. if( is_multisite() && mp_cart()->is_global ){
  365. $curr_decimal = mp_get_network_setting( 'global_curr_decimal' ) == 'off' ? 0 : 1;
  366. }
  367. $price_format = ( is_multisite() && mp_cart()->is_global ) ? mp_get_network_setting( 'global_price_format' ) : mp_get_setting( 'price_format' );
  368.  
  369. if ( $curr_decimal == 1 ) {
  370. $int_decimals = 2;
  371. } else {
  372. $int_decimals = 0;
  373. }
  374.  
  375. $decimals = apply_filters( 'mp_number_format_decimals', $int_decimals );
  376.  
  377. if ( $force_basic ) {
  378. $formatted = number_format( $amount, $int_decimals, $dec_point = ".", $thousands_sep = "" );
  379. } else {
  380. switch ( $price_format ) {
  381. case 'us' :
  382. $formatted = number_format( $amount, $decimals, $dec_point = ".", $thousands_sep = "," );
  383. break;
  384.  
  385. case 'eu' :
  386. $formatted = number_format( $amount, $decimals, $dec_point = ",", $thousands_sep = "." );
  387. break;
  388.  
  389. case 'frc' :
  390. $formatted = number_format( $amount, $decimals, $dec_point = ",", $thousands_sep = "&nbsp;" );
  391. break;
  392.  
  393. case 'frd' :
  394. $formatted = number_format( $amount, $decimals, $dec_point = ".", $thousands_sep = "&nbsp;" );
  395. break;
  396.  
  397. default ://us
  398. $formatted = number_format( $amount, $decimals, $dec_point = ".", $thousands_sep = "," );
  399. }
  400. }
  401.  
  402. return $formatted;
  403. }
  404.  
  405. }
  406.  
  407. if ( ! function_exists( 'mp_cart_widget' ) ) :
  408.  
  409. /**
  410. * Display a cart widget.
  411. *
  412. * The 'title' argument will accept a string and defaults is empty.
  413. * The 'custom_text' argument will accept a string and defaults is empty.
  414. *
  415. * @param bool $echo Optional. Whether or not to echo.
  416. * @param array|string $args Optional. Override default arguments.
  417. */
  418. function mp_cart_widget( $echo = true, $args = array() ) {
  419.  
  420. $mini_cart = '';
  421. $title = '';
  422. $custom_text = '';
  423. $cart_content = '';
  424.  
  425. $mini_cart .= apply_filters( 'mp_cart_widget_before', '<div class="mp_cart_widget">' );
  426.  
  427. if ( ! empty( $args['title'] ) ) {
  428. $title .= '<div class="mp_cart_widget_title">';
  429. $title .= $args['title'];
  430. $title .= '</div><!-- end .mp_cart_widget_title -->';
  431. };
  432.  
  433. $mini_cart .= apply_filters( 'mp_cart_widget_title', $title );
  434.  
  435. if ( ! empty( $args['custom_text'] ) ) {
  436. $custom_text .= '<div class="mp_cart_widget_custom_text">';
  437. $custom_text .= $args['custom_text'];
  438. $custom_text .= '</div><!-- end .mp_cart_widget_custom_text -->';
  439. };
  440.  
  441. $mini_cart .= apply_filters( 'mp_cart_widget_custom_text', $custom_text );
  442.  
  443. $cart_content .= '<div class="mp_cart_widget_content">';
  444. $cart_content .= MP_Cart::get_instance()->cart_products_html( 'widget', $args['show_product_image'], $args['show_product_qty'], $args['show_product_price'] );
  445. $cart_content .= '</div><!-- end .mp_cart_widget_content -->';
  446.  
  447. $mini_cart .= apply_filters( 'mp_cart_widget_content', $cart_content );
  448.  
  449. $mini_cart .= apply_filters( 'mp_cart_widget_after', '</div><!-- end .mp_cart_widget -->' );
  450.  
  451. if ( $echo ) {
  452. echo $mini_cart;
  453. } else {
  454. return $mini_cart;
  455. }
  456. }
  457.  
  458. endif;
  459.  
  460. if ( ! function_exists( 'mp_tag_cloud' ) ) :
  461.  
  462. /**
  463. * Display product tag cloud.
  464. *
  465. * The text size is set by the 'smallest' and 'largest' arguments, which will
  466. * use the 'unit' argument value for the CSS text size unit. The 'format'
  467. * argument can be 'flat' (default), 'list', or 'array'. The flat value for the
  468. * 'format' argument will separate tags with spaces. The list value for the
  469. * 'format' argument will format the tags in a UL HTML list. The array value for
  470. * the 'format' argument will return in PHP array type format.
  471. *
  472. * The 'orderby' argument will accept 'name' or 'count' and defaults to 'name'.
  473. * The 'order' is the direction to sort, defaults to 'ASC' and can be 'DESC'.
  474. *
  475. * The 'number' argument is how many tags to return. By default, the limit will
  476. * be to return the top 45 tags in the tag cloud list.
  477. *
  478. * The 'topic_count_text_callback' argument is a function, which, given the count
  479. * of the posts with that tag, returns a text for the tooltip of the tag link.
  480. *
  481. * The 'exclude' and 'include' arguments are used for the {@link get_tags()}
  482. * function. Only one should be used, because only one will be used and the
  483. * other ignored, if they are both set.
  484. *
  485. * @param bool $echo Optional. Whether or not to echo.
  486. * @param array|string $args Optional. Override default arguments.
  487. */
  488. function mp_tag_cloud( $echo = true, $args = array() ) {
  489.  
  490. $args['echo'] = false;
  491. $args['taxonomy'] = 'product_tag';
  492.  
  493. $cloud = '<div id="mp-tag-cloud">' . wp_tag_cloud( $args ) . '</div><!-- end mp-tag-cloud -->';
  494.  
  495. $cloud = apply_filters( 'mp_tag_cloud', $cloud, $args );
  496.  
  497. if ( $echo ) {
  498. echo $cloud;
  499. } else {
  500. return $cloud;
  501. }
  502. }
  503.  
  504. endif;
  505.  
  506. if ( ! function_exists( '_mp_order_status_overview' ) ) :
  507.  
  508. /**
  509. * Display the order status overview html.
  510. *
  511. * @since 3.0
  512. * @return string
  513. */
  514. function _mp_order_status_overview() {
  515. $history = array_filter( mp_get_order_history() );
  516. $page = get_query_var( 'mp_status_pagenumber', 1 );
  517. $per_page_value = mp_get_setting( 'per_page_order_history' );
  518. $per_page = isset( $per_page_value ) ? $per_page_value : get_option( 'posts_per_page' );
  519. $offset = ( $page - 1 ) * $per_page;
  520. $total_pages = ceil( count( $history ) / $per_page );
  521. $html = '
  522. <!-- Order History -->
  523. <section id="mp-order-history" class="mp_orders mp_orders-list">';
  524.  
  525. if ( count( $history ) > 0 ) {
  526. $history = array_slice( $history, $offset, $per_page );
  527. $html .= '
  528. <h2 class="mp_title">' . __( 'Order History', 'mp' ) . '</h2>' .
  529. '<div class="mp_order_details">';
  530. foreach ( $history as $timestamp => $order ) {
  531. $order = new MP_Order( $order['id'] );
  532. $html .= '<div class="mp_order">';
  533. $html .= $order->header( false );
  534. $html .= '</div><!-- end mo_order -->';
  535. }
  536.  
  537. $html .= '</div><!-- end mp_order_details -->';
  538.  
  539. if ( $total_pages > 1 ) {
  540. $big = 99999999;
  541. $html .= '<nav class="mp_listings_nav">';
  542. $html .= paginate_links( array(
  543. 'base' => str_replace( $big, '%#%', esc_url( get_pagenum_link( $big ) ) ),
  544. 'current' => $page,
  545. 'total' => $total_pages,
  546. ) );
  547. $html .= '</nav>';
  548. }
  549. }
  550.  
  551. $html .= '
  552. </section><!-- end mp-order-history -->';
  553.  
  554. return $html;
  555. }
  556.  
  557. endif;
  558.  
  559. if ( ! function_exists( '_mp_products_html' ) ) :
  560.  
  561. /**
  562. * Display products according to preference
  563. *
  564. * @since 3.0
  565. * @access public
  566. *
  567. * @param string $view Either "grid" or "list".
  568. * @param WP_Query $custom_query A WP_Query object.
  569. *
  570. * @return string
  571. */
  572. function _mp_products_html( $view, $custom_query, $related_products = false ) {
  573.  
  574. $html = '';
  575. if ( $related_products ) {
  576. $per_row = mp_get_setting( 'related_products->per_row', 3 );
  577. } else {
  578. $per_row = (int) mp_get_setting( 'per_row', 3 );
  579. }
  580.  
  581. $width = round( 100 / $per_row, 1 ) . '%';
  582. $column = 1;
  583.  
  584. //get image width
  585. if ( mp_get_setting( 'list_img_size' ) == 'custom' ) {
  586. $img_width = mp_get_setting( 'list_img_width' ) . 'px';
  587. } else {
  588. $size = mp_get_setting( 'list_img_size' );
  589. $img_width = get_option( $size . '_size_w' ) . 'px';
  590. }
  591.  
  592. while ( $custom_query->have_posts() ) : $custom_query->the_post();
  593. $product = new MP_Product();
  594.  
  595. $align = null;
  596. if ( 'list' == mp_get_setting( 'list_view' ) ) {
  597. $align = mp_get_setting( 'image_alignment_list' );
  598. }
  599.  
  600. $img = $product->image( false, 'list', null, $align, true );
  601.  
  602. $excerpt = mp_get_setting( 'show_excerpts' ) ? '<div class="mp_product_excerpt"><p>' . $product->excerpt() . '</div></p><!-- end mp_product_excerpt -->' : '';
  603. $mp_product_list_content = apply_filters( 'mp_product_list_content', $excerpt, $product->ID );
  604.  
  605. $pinit = $product->pinit_button( 'all_view' );
  606. $fb = $product->facebook_like_button( 'all_view' );
  607. $twitter = $product->twitter_button( 'all_view' );
  608.  
  609. $class = array();
  610. $class[] = ( strlen( $img ) > 0 ) ? 'mp_thumbnail' : '';
  611. $class[] = ( strlen( $excerpt ) > 0 ) ? 'mp_excerpt' : '';
  612. $class[] = ( $product->has_variations() ) ? 'mp_price_variations' : '';
  613. $class[] = ( $product->on_sale() ) ? 'mp_on_sale' : '';
  614.  
  615. if ( 'grid' == $view ) {
  616. if ( $column == 1 ) {
  617. $class[] = 'first';
  618. $html .= '<div class="mp_products_items">';
  619. $column ++;
  620. } elseif ( $column == $per_row ) {
  621. $class[] = 'last';
  622. $column = 1;
  623. } else {
  624. $column ++;
  625. }
  626. }
  627.  
  628. $class = array_filter( $class, create_function( '$s', 'return ( ! empty( $s ) );' ) );
  629.  
  630. $image_alignment = mp_get_setting( 'image_alignment_list' );
  631.  
  632. $align_class = ( $view == 'list' ) ? ' mp_product-image-' . ( ! empty( $image_alignment ) ? $image_alignment : 'alignleft' ) : '';
  633.  
  634. $html .= '
  635. <div class="mp_product_item' . ( ( 'grid' == $view ) ? ' mp_product_item-col-' . $per_row : '' ) . '">
  636. <div itemscope itemtype="http://schema.org/Product" class="mp_product' . ( ( strlen( $img ) > 0 ) ? ' mp_product-has-image' . $align_class : '' ) . ' ' . implode( $class, ' ' ) . '">
  637.  
  638. <div class="mp_product_images">
  639. ' . $img . '
  640. </div><!-- end mp_product_images -->
  641.  
  642. <div class="mp_product_details">
  643.  
  644. <div class="mp_product_meta">
  645. <h3 class="mp_product_name entry-title" itemprop="name">
  646. <a href="' . $product->url( false ) . '">' . $product->title( false ) . '</a>
  647. </h3>
  648. ' . $product->display_price( false ) . '
  649. ' . $mp_product_list_content . '
  650.  
  651. <div class="mp_social_shares">
  652. ' . $pinit . '
  653. ' . $fb . '
  654. ' . $twitter . '
  655. </div><!-- end mp_social_shares -->
  656.  
  657. </div><!-- end mp_product_meta -->
  658.  
  659. <div class="mp_product_callout">
  660. ' . $product->buy_button( false, 'list', array(), true ) . '
  661. ' . apply_filters( 'mp_product_list_meta', '', $product->ID ) . '
  662. </div><!-- end mp_product_callout -->
  663.  
  664. </div><!-- end mp_product_details -->
  665.  
  666. <div style="display:none">
  667. <span class="entry-title">' . $product->title( false ) . '</span> was last modified:
  668. <time class="updated">' . get_the_time( 'Y-m-d\TG:i' ) . '</time> by
  669. <span class="author vcard"><span class="fn">' . get_the_author_meta( 'display_name' ) . '</span></span>
  670. </div>
  671.  
  672. </div><!-- end mp_product -->
  673. </div><!-- end mp_product_item -->';
  674.  
  675. if ( $column == 1 && $view == 'grid' ) {
  676. $html .= '</div><!-- end mp_products_items -->';
  677. }
  678. endwhile;
  679.  
  680. if ( $column != 1 && $view == 'grid' ) {
  681. $html .= '</div><!-- end mp_products_items -->';
  682. }
  683.  
  684. /* if ( $view == 'grid' ) {
  685. $html .= ( $custom_query->found_posts > 0 ) ? '<div class="clear"></div>' : '';
  686. } */
  687.  
  688. wp_reset_postdata();
  689.  
  690. /**
  691. * Filter the product list html content
  692. *
  693. * @since 3.0
  694. *
  695. * @param string $html .
  696. * @param WP_Query $custom_query .
  697. */
  698.  
  699. return apply_filters( "_mp_products_html_{$view}", $html, $custom_query );
  700. }
  701.  
  702. endif;
  703.  
  704. if ( ! function_exists( '_mp_products_html_list' ) ) :
  705.  
  706. /**
  707. * Display product list in list layout
  708. *
  709. * @since 3.0
  710. *
  711. * @param WP_Query $custom_query
  712. *
  713. * @return string
  714. */
  715. function _mp_products_html_list( $custom_query ) {
  716. return _mp_products_html( 'list', $custom_query );
  717. }
  718.  
  719. endif;
  720.  
  721. if ( ! function_exists( '_mp_products_html_grid' ) ) :
  722.  
  723. /**
  724. * Display product list in grid layout
  725. *
  726. * @since 3.0
  727. *
  728. * @param WP_Query $custom_query
  729. *
  730. * @return string
  731. */
  732. function _mp_products_html_grid( $custom_query, $relate_products = false ) {
  733. return _mp_products_html( 'grid', $custom_query, $relate_products );
  734. }
  735.  
  736. endif;
  737.  
  738. if ( ! function_exists( 'mp_before_tax_price' ) ) :
  739.  
  740. /**
  741. * Get the price before taxes
  742. *
  743. * @since 3.0
  744. *
  745. * @param float $tax_price The price including tax.
  746. * @param float $rate Optional. The tax rate applied to the price.
  747. */
  748. function mp_before_tax_price( $tax_price, $rate = null ) {
  749. if ( ! mp_get_setting( 'tax->tax_inclusive' ) ) {
  750. // tax inclusve pricing is turned off - just return tax price
  751. return $tax_price;
  752. }
  753.  
  754. if ( is_null( $rate ) ) {
  755. $rate = mp_tax_rate();
  756. }
  757.  
  758. return $tax_price / ( floatval( $rate ) + 1 );
  759. }
  760.  
  761. endif;
  762.  
  763. if ( ! function_exists( 'mp_buy_button' ) ) :
  764.  
  765. /**
  766. * Display the buy or add to cart button
  767. *
  768. * @param bool $echo Optional, whether to echo
  769. * @param string $context Options are list or single
  770. * @param int $post_id The post_id for the product. Optional if in the loop.
  771. */
  772. function mp_buy_button( $echo = true, $context = 'list', $product_id = null ) {
  773. //_deprecated_function( 'mp_buy_button', '3.0', 'MP_Product::buy_button' );
  774.  
  775. $product = new MP_Product( $product_id );
  776. if ( ! $product->exists() ) {
  777. return;
  778. }
  779.  
  780. $button = $product->buy_button( false, $context, array(), true, true );
  781.  
  782. if ( $echo ) {
  783. echo $button;
  784. } else {
  785. return $button;
  786. }
  787. }
  788.  
  789. endif;
  790.  
  791. if ( ! function_exists( 'mp_cart_link' ) ) :
  792.  
  793. /**
  794. * Display the current shopping cart link. If global cart is on reflects global location
  795. * @since 3.0
  796. *
  797. * @param bool $echo Optional, whether to echo. Defaults to true.
  798. * @param bool $url Optional, whether to return a link or url. Defaults to show link.
  799. * @param string $link_text Optional, text to show in link.
  800. */
  801. function mp_cart_link( $echo = true, $url = false, $link_text = false ) {
  802. if ( mp_cart()->is_global && ! mp_is_main_site() ) {
  803. switch_to_blog( MP_ROOT_BLOG );
  804. $link = get_permalink( mp_get_setting( 'pages->cart' ) );
  805. restore_current_blog();
  806. } else {
  807. $link = get_permalink( mp_get_setting( 'pages->cart' ) );
  808. }
  809.  
  810. if ( ! $url ) {
  811. $text = ( $link_text ) ? $link_text : __( 'Shopping Cart', 'mp' );
  812. $link = '<a href="' . $link . '" class="mp_cart_link">' . $text . '</a>';
  813. }
  814.  
  815. /**
  816. * Filter the cart link
  817. *
  818. * @since 3.0
  819. *
  820. * @param string $link The current link.
  821. * @param bool $echo Optional, whether to echo. Defaults to true.
  822. * @param bool $url Optional, whether to return a link or url. Defaults to show link.
  823. * @param string $link_text Optional, text to show in link.
  824. */
  825. $link = apply_filters( 'mp_cart_link', $link, $echo, $url, $link_text );
  826.  
  827. if ( $echo ) {
  828. echo $link;
  829. } else {
  830. return $link;
  831. }
  832. }
  833.  
  834. endif;
  835.  
  836. if ( ! function_exists( 'mp_checkout_step_url' ) ) :
  837.  
  838. /**
  839. * Get the current shopping cart link with checkout step
  840. *
  841. * @since 3.0
  842. *
  843. * @param string $checkoutstep . Possible values: checkout-edit, shipping, checkout, confirm-checkout, confirmation
  844. */
  845. function mp_checkout_step_url( $checkout_step ) {
  846. return ( is_admin() ) ? '' : apply_filters( 'mp_checkout_step_url', mp_cart_link( false, true ) . trailingslashit( $checkout_step ), $checkout_step );
  847. }
  848.  
  849. endif;
  850.  
  851. if ( ! function_exists( 'mp_create_store_page' ) ) :
  852.  
  853. /**
  854. * Create a store page
  855. *
  856. * @since 3.0
  857. *
  858. * @param string $type The type of page to create.
  859. *
  860. * @return int $post_id The ID of the newly created page.
  861. */
  862. function mp_create_store_page( $type ) {
  863. $args = array();
  864. $defaults = array(
  865. 'post_status' => 'publish',
  866. 'post_type' => 'page',
  867. );
  868.  
  869. switch ( $type ) {
  870. case 'store' :
  871. $args = array(
  872. 'post_title' => __( 'Store', 'mp' ),
  873. 'post_content' => __( "Welcome to our online store! Feel free to browse around:\n\n[mp_store_navigation]\n\nCheck out our most popular products:\n\n[mp_popular_products]\n\nBrowse by category:\n\n[mp_list_categories]\n\nBrowse by tag:\n\n[mp_tag_cloud]", 'mp' ),
  874. );
  875. break;
  876.  
  877. case 'network_store_page' :
  878. $args = array(
  879. 'post_title' => __( 'Global Store', 'mp' ),
  880. 'post_content' => __( "Welcome to our market place!\n\nCheck out our network of products:\n\n[mp_list_global_products]\n\nBrowse by category:\n\n[mp_global_categories_list]\n\nBrowse by tag:\n\n[mp_global_tag_cloud]", 'mp' ),
  881. 'comment_status' => 'closed'
  882. );
  883. break;
  884. case 'network_categories' :
  885. $args = array(
  886. 'post_title' => __( 'Category', 'mp' ),
  887. 'post_content' => __( "[mp_global_categories_list]", 'mp' ),
  888. 'comment_status' => 'closed',
  889. 'post_parent' => mp_get_network_setting( 'pages->network_store_page', 0 ),
  890. );
  891. break;
  892. case 'network_tags' :
  893. $args = array(
  894. 'post_title' => __( 'Tag', 'mp' ),
  895. 'post_content' => __( "[mp_global_tag_cloud]", 'mp' ),
  896. 'comment_status' => 'closed',
  897. 'post_parent' => mp_get_network_setting( 'pages->network_store_page', 0 ),
  898. );
  899. break;
  900. case 'products' :
  901. $args = array(
  902. 'post_title' => __( 'Products', 'mp' ),
  903. 'post_content' => '[mp_list_products]',
  904. 'post_parent' => mp_get_setting( 'pages->store', 0 ),
  905. );
  906. break;
  907.  
  908. case 'cart' :
  909. $args = array(
  910. 'post_title' => __( 'Cart', 'mp' ),
  911. 'post_content' => '[mp_cart]',
  912. 'post_parent' => mp_get_setting( 'pages->store', 0 ),
  913. );
  914. break;
  915.  
  916. case 'checkout' :
  917. $args = array(
  918. 'post_title' => __( 'Checkout', 'mp' ),
  919. 'post_content' => '[mp_checkout]',
  920. 'post_parent' => mp_get_setting( 'pages->store', 0 )
  921. );
  922. break;
  923.  
  924. case 'order_status' :
  925. $args = array(
  926. 'post_title' => __( 'Order Status', 'mp' ),
  927. 'post_content' => "[mp_order_lookup_form]<h2>" . __( 'Order Search', 'mp' ) . "</h2><p>" . __( 'If you have your order ID you can look it up using the form below.', 'mp' ) . "</p>[/mp_order_lookup_form][mp_order_status]",
  928. 'post_parent' => mp_get_setting( 'pages->store', 0 )
  929. );
  930. break;
  931. }
  932.  
  933. $post_id = wp_insert_post( array_merge( $defaults, $args ) );
  934. MP_Pages_Admin::get_instance()->save_store_page_value( $type, $post_id, false );
  935.  
  936. return $post_id;
  937. }
  938.  
  939. endif;
  940.  
  941. if ( ! function_exists( 'mp_display_currency' ) ) :
  942.  
  943. /**
  944. * Format a number as currency without the symbol
  945. *
  946. * @since 3.0
  947. *
  948. * @param float $amount The amount to format.
  949. * @param int $dec_places Optional, the number of decimal places to show.
  950. *
  951. * @return string
  952. */
  953. function mp_display_currency( $amount, $dec_places = null ) {
  954. $amount = (float) $amount;
  955.  
  956. if ( is_null( $dec_places ) ) {
  957. $dec_places = 2;
  958. if ( $amount == (int) $amount ) {
  959. $dec_places = 0;
  960. }
  961. }
  962.  
  963. return number_format( $amount, $dec_places, '.', '' );
  964. }
  965.  
  966. endif;
  967.  
  968. if ( ! function_exists( 'mp_format_currency' ) ) :
  969.  
  970. /**
  971. * Formats currency
  972. *
  973. * @since 3.0
  974. *
  975. * @param string $currency The currency code to use for formatting (defaults to value set in currency settings)
  976. * @param float $amount The amount to format
  977. *
  978. * @return string
  979. */
  980. function mp_format_currency(
  981. $currency = '', $amount = false, $price_class = '', $currency_class = '',
  982. $price_holder_arguments = array(), $force_basic = false
  983. ) {
  984.  
  985. $currencies = mp()->currencies;
  986.  
  987. if ( empty( $currency ) ) {
  988. $currency = ( is_multisite() && mp_cart()->is_global ) ? mp_get_network_setting( 'global_currency', 'USD' ) : mp_get_setting( 'currency', 'USD' );
  989. }
  990.  
  991. $curr_symbol_position = mp_get_setting( 'curr_symbol_position' );
  992.  
  993. // If multisite use global currency symbol
  994. if( is_multisite() && mp_cart()->is_global ) {
  995. $global_currency = mp_get_network_setting( 'global_curr_symbol_position' );
  996.  
  997. // Check if we have global currency symbol
  998. if( ! empty( $global_currency ) ) {
  999. $curr_symbol_position = $global_currency;
  1000. }
  1001. }
  1002.  
  1003. // get the currency symbol
  1004. if ( $symbol = mp_arr_get_value( "$currency->1", $currencies ) ) {
  1005. // if many symbols are found, rebuild the full symbol
  1006. $symbols = array_map( 'trim', explode( ', ', $symbol ) );
  1007. if ( is_array( $symbols ) ) {
  1008. $symbol = '';
  1009. foreach ( $symbols as $temp ) {
  1010. $symbol .= '&#x' . $temp . ';';
  1011. }
  1012. } else {
  1013. $symbol = '&#x' . $symbol . ';';
  1014. }
  1015. }
  1016.  
  1017. /**
  1018. * Filter the currency symbol used to format curency
  1019. *
  1020. * @since 3.0
  1021. *
  1022. * @param string $symbol
  1023. * @param string $currency
  1024. */
  1025. $symbol = apply_filters( 'mp_format_currency_symbol', $symbol, $currency );
  1026.  
  1027. //check decimal option
  1028. if ( (int) ( $amount ) == (float) $amount ) {
  1029. $decimal_place = 0;
  1030. } else {
  1031. $decimal_place = 2;
  1032. }
  1033.  
  1034. //handle negative numbers
  1035. $negative_symbol = '';
  1036.  
  1037. if ( $amount < 0 ) {
  1038. $negative_symbol = '-';
  1039. $amount = abs( $amount );
  1040. }
  1041.  
  1042. if ( $amount === false ) {
  1043. // just return symbol
  1044. $formatted = $symbol;
  1045. } else {
  1046. // just in case so number_format_i18n doesn't throw an error if $amount is string instead of double
  1047. $amount = (float) $amount;
  1048. $price_holder_arguments_string = '';
  1049.  
  1050. if ( is_array( $price_holder_arguments ) && count( $price_holder_arguments ) > 0 ) {
  1051. foreach ( $price_holder_arguments as $argument_name => $argument_value ) {
  1052. $price_holder_arguments_string .= ' ' . esc_attr( $argument_name ) . '="' . esc_attr( $argument_value ) . '" ';
  1053. }
  1054. } else {
  1055. $price_holder_arguments_string = '';
  1056. }
  1057.  
  1058. if ( ! empty( $price_class ) ) {
  1059. $price_pre = '<span class="' . esc_attr( $price_class ) . '" ' . $price_holder_arguments_string . '>';
  1060. $price_post = '</span>';
  1061. } else {
  1062. $price_pre = '';
  1063. $price_post = '';
  1064. }
  1065.  
  1066. if ( ! empty( $currency_class ) ) {
  1067. $currency_pre = '<span class="' . esc_attr( $currency_class ) . '">';
  1068. $currency_post = '</span>';
  1069. } else {
  1070. $currency_pre = '';
  1071. $currency_post = '';
  1072. }
  1073.  
  1074. switch ( $curr_symbol_position ) {
  1075. case 1 :
  1076. $formatted = $negative_symbol . $currency_pre . $symbol . $currency_post . $price_pre . mp_number_format( $amount, $decimal_place, $force_basic ) . $price_post;
  1077. break;
  1078.  
  1079. case 2 :
  1080. $formatted = $negative_symbol . $currency_pre . $symbol . $currency_post . '&nbsp;' . $price_pre . mp_number_format( $amount, $decimal_place, $force_basic ) . $price_post;
  1081. break;
  1082.  
  1083. case 3 :
  1084. $formatted = $price_pre . mp_number_format( $amount, $decimal_place, $force_basic ) . $price_post . $currency_pre . $symbol . $currency_post;
  1085. break;
  1086.  
  1087. case 4 :
  1088. $formatted = $price_pre . mp_number_format( $amount, $decimal_place, $force_basic ) . $price_post . '&nbsp;' . $currency_pre . $symbol . $currency_post;
  1089. break;
  1090. }
  1091. }
  1092.  
  1093. /**
  1094. * Filter the formatted currency
  1095. *
  1096. * @since 3.0
  1097. *
  1098. * @param string $formatted
  1099. * @param string $currency
  1100. * @param string $symbol
  1101. * @param float $amount
  1102. */
  1103.  
  1104. return apply_filters( 'mp_format_currency', $formatted, $currency, $symbol, $amount );
  1105. }
  1106.  
  1107. endif;
  1108.  
  1109.  
  1110. if ( ! function_exists( 'mp_format_date' ) ) :
  1111.  
  1112. /**
  1113. * Format a date according to settings
  1114. *
  1115. * @since 3.0
  1116. *
  1117. * @param int $timestamp
  1118. * @param bool $date_only Optional, whether to return just the date part or include the time as well. Defaults to include time.
  1119. */
  1120. function mp_format_date( $timestamp, $date_only = false ) {
  1121. $format = get_option( 'date_format' );
  1122. if ( ! $date_only ) {
  1123. $format .= ' - ' . get_option( 'time_format' );
  1124. }
  1125.  
  1126. $date = get_date_from_gmt( date( 'Y-m-d H:i:s', $timestamp ), $format );
  1127.  
  1128. return $date;
  1129. //return date_i18n( $format, $timestamp);
  1130. }
  1131.  
  1132. endif;
  1133.  
  1134. if ( ! function_exists( 'mp_get_current_user_zipcode' ) ) :
  1135.  
  1136. /**
  1137. * Get the current user's zipcode
  1138. *
  1139. * @since 3.0
  1140. * @access public
  1141. * @return string The zipcode. False, if no zipcode could be retrieved.
  1142. */
  1143. function mp_get_current_user_zipcode() {
  1144. $user = wp_get_current_user();
  1145. $address = $user->get( 'mp_shipping_info' );
  1146. $zipcode = false;
  1147.  
  1148. if ( is_array( $address ) ) {
  1149. // Try to get from usermeta
  1150. $zipcode = mp_arr_get_value( 'zip', $address );
  1151. }
  1152.  
  1153. if ( false === $zipcode ) {
  1154. // Try to get from cookie
  1155. $zipcode = mp_get_cookie_value( 'zip' );
  1156. }
  1157.  
  1158. return $zipcode;
  1159. }
  1160.  
  1161. endif;
  1162.  
  1163. if ( ! function_exists( 'mp_get_current_user_city' ) ) :
  1164.  
  1165. /**
  1166. * Get the current user's zipcode
  1167. *
  1168. * @since 3.0
  1169. * @access public
  1170. * @return string The zipcode. False, if no zipcode could be retrieved.
  1171. */
  1172. function mp_get_current_user_city() {
  1173. $user = wp_get_current_user();
  1174. $address = $user->get( 'mp_shipping_info' );
  1175. $city = false;
  1176.  
  1177. if ( is_array( $address ) ) {
  1178. // Try to get from usermeta
  1179. $city = mp_arr_get_value( 'city', $address );
  1180. }
  1181.  
  1182. if ( false === $city ) {
  1183. // Try to get from cookie
  1184. $city = mp_get_cookie_value( 'city' );
  1185. }
  1186.  
  1187. return $city;
  1188. }
  1189.  
  1190. endif;
  1191.  
  1192. if ( ! function_exists( 'mp_get_user_address' ) ) :
  1193.  
  1194. /**
  1195. * Get full user address
  1196. *
  1197. * @since 3.0
  1198. *
  1199. * @param string $what Either shipping or billing.
  1200. * @param WP_User /int $user Optional, an WP_User object or a user ID. Defaults to the current user.
  1201. *
  1202. * @return array False, on error.
  1203. */
  1204. function mp_get_user_address( $what, $user = null ) {
  1205. if ( is_null( $user ) ) {
  1206. $user = wp_get_current_user();
  1207. } elseif ( ! $user instanceof WP_User && false === ( $user = get_user_by( 'id', $user ) ) ) {
  1208. return false;
  1209. }
  1210.  
  1211. if ( $_data = mp_get_session_value( "mp_{$what}_info" ) ) {
  1212. $data = $_data;
  1213. } elseif ( empty( $data ) && is_user_logged_in() ) {
  1214. $data = $user->get( "mp_{$what}_info" );
  1215. } else {
  1216. return false;
  1217. }
  1218.  
  1219. /* if ( !empty( $data ) ) {
  1220. foreach ( $data as $k => $v ) {
  1221. switch ( $k ) {
  1222. case 'shipping_option' :
  1223. case 'shipping_sub_option' :
  1224. case 'shipping_cost' :
  1225. unset( $data[ $k ] );
  1226. break;
  1227. }
  1228. }
  1229. } */
  1230.  
  1231. return $data;
  1232. }
  1233.  
  1234. endif;
  1235.  
  1236. if ( ! function_exists( 'mp_list_categories' ) ) :
  1237.  
  1238. /**
  1239. * Display or retrieve the HTML list of product categories.
  1240. *
  1241. * The list of arguments is below:
  1242. * 'show_option_all' (string) - Text to display for showing all categories.
  1243. * 'orderby' (string) default is 'ID' - What column to use for ordering the
  1244. * categories.
  1245. * 'order' (string) default is 'ASC' - What direction to order categories.
  1246. * 'show_last_update' (bool|int) default is 0 - See {@link
  1247. * walk_category_dropdown_tree()}
  1248. * 'show_count' (bool|int) default is 0 - Whether to show how many posts are
  1249. * in the category.
  1250. * 'hide_empty' (bool|int) default is 1 - Whether to hide categories that
  1251. * don't have any posts attached to them.
  1252. * 'use_desc_for_title' (bool|int) default is 1 - Whether to use the
  1253. * description instead of the category title.
  1254. * 'feed' - See {@link get_categories()}.
  1255. * 'feed_type' - See {@link get_categories()}.
  1256. * 'feed_image' - See {@link get_categories()}.
  1257. * 'child_of' (int) default is 0 - See {@link get_categories()}.
  1258. * 'exclude' (string) - See {@link get_categories()}.
  1259. * 'exclude_tree' (string) - See {@link get_categories()}.
  1260. * 'current_category' (int) - See {@link get_categories()}.
  1261. * 'hierarchical' (bool) - See {@link get_categories()}.
  1262. * 'title_li' (string) - See {@link get_categories()}.
  1263. * 'depth' (int) - The max depth.
  1264. *
  1265. * @param bool $echo Optional. Whether or not to echo.
  1266. * @param string|array $args Optional. Override default arguments.
  1267. */
  1268. function mp_list_categories( $echo = true, $args = array() ) {
  1269. $args['taxonomy'] = 'product_category';
  1270. $args['echo'] = false;
  1271.  
  1272. $list = '<ul id="mp_category_list">' . wp_list_categories( $args ) . '</ul>';
  1273.  
  1274. /**
  1275. * Filter the category list html
  1276. *
  1277. * @since 3.0
  1278. *
  1279. * @param string $list
  1280. * @param array $args
  1281. */
  1282. $list = apply_filters( 'mp_list_categories', $list, $args );
  1283.  
  1284. if ( $echo ) {
  1285. echo $list;
  1286. } else {
  1287. return $list;
  1288. }
  1289. }
  1290.  
  1291. endif;
  1292.  
  1293. if ( ! function_exists( 'mp_list_payment_options' ) ) :
  1294.  
  1295. /**
  1296. * List available payment options (if there is more than one)
  1297. *
  1298. * @since 3.0
  1299. *
  1300. * @param bool $echo Optional, whether to echo or return. Defaults to echo.
  1301. */
  1302. function mp_list_payment_options( $echo = true ) {
  1303.  
  1304. $gateways = MP_Gateway_API::get_active_gateways();
  1305. $html = '';
  1306.  
  1307. $cart = MP_Cart::get_instance();
  1308. $total = $cart->total( false );
  1309.  
  1310. $options = array();
  1311. foreach ( $gateways as $code => $gateway ) {
  1312. if ( $total == 0 ) {
  1313. if ( $code == 'free_orders' ) {
  1314. $options[ $code ] = $gateway->public_name;
  1315. } else {
  1316. //do not list other payment gateways
  1317. }
  1318. } else {
  1319. if ( $code !== 'free_orders' ) {//do not list free orders if total is > 0
  1320. $options[ $code ] = $gateway->public_name;
  1321. }
  1322. }
  1323. }
  1324. /**
  1325. * Filter the options array before formatting to html
  1326. *
  1327. * @since 3.0
  1328. *
  1329. * @param array $options
  1330. */
  1331. $options = (array) apply_filters( 'mp_payment_options_array', $options );
  1332.  
  1333. $index = 0;
  1334. foreach ( $options as $code => $label ) {
  1335. $checked = '';
  1336. if ( $selected = mp_get_session_value( 'mp_payment_method' ) ) {
  1337. if ( $selected == $code ) {
  1338. $checked = ' checked';
  1339. }
  1340. } elseif ( $index == 0 ) {
  1341. $checked = ' checked';
  1342. }
  1343.  
  1344. $input_id = 'mp-gateway-option-' . $code;
  1345. $html .= '
  1346. <label class="mp_form_label mp_form_label-checkout-option" for="' . $input_id . '"' . ( ( count( $options ) == 1 ) ? ' style="display:none"' : '' ) . '>
  1347. <input
  1348. data-mp-use-confirmation-step="' . ( ( $gateways[ $code ]->use_confirmation_step ) ? 'true' : 'false' ) . '"
  1349. id="' . $input_id . '"
  1350. type="radio"
  1351. name="payment_method"
  1352. value="' . $code . '"' . $checked . '
  1353. autocomplete="off">
  1354. <span></span>' . $label . '
  1355. </label>';
  1356.  
  1357. $index ++;
  1358. }
  1359.  
  1360. /**
  1361. * Filter the payment options html
  1362. *
  1363. * @since 3.0
  1364. *
  1365. * @param string $html The current html.
  1366. */
  1367. $html = apply_filters( 'mp_list_payment_options', $html );
  1368.  
  1369. if ( $echo ) {
  1370. echo $html;
  1371. } else {
  1372. return $html;
  1373. }
  1374. }
  1375.  
  1376. endif;
  1377.  
  1378. if ( ! function_exists( 'mp_list_plugin_shipping_options' ) ) :
  1379.  
  1380. /**
  1381. * Display an array of shipping plugin shipping options as html
  1382. *
  1383. * @since 3.0
  1384. *
  1385. * @param MP_Shipping_API $plugin A shipping plugin object.
  1386. * @param bool $echo Optional, whether to echo or return. Defaults to return.
  1387. *
  1388. * @return string
  1389. */
  1390. function mp_list_plugin_shipping_options( $plugin, $echo = false ) {
  1391. if ( ! $plugin instanceof MP_Shipping_API ) {
  1392. trigger_error( $plugin . ' is not an instance of MP_Shipping_API', E_USER_ERROR );
  1393. }
  1394.  
  1395. $what = ( mp_get_post_value( 'enable_shipping_address' ) ) ? 'shipping' : 'billing';
  1396. $shipping_option = mp_get_session_value( 'mp_shipping_info->shipping_option' );
  1397. $shipping_sub_option = mp_get_session_value( 'mp_shipping_info->shipping_sub_option' );
  1398.  
  1399. $address1 = mp_get_user_address_part( 'address1', $what );
  1400. $address2 = mp_get_user_address_part( 'address2', $what );
  1401. $city = mp_get_user_address_part( 'city', $what );
  1402. $state = mp_get_user_address_part( 'state', $what );
  1403. $zip = mp_get_user_address_part( 'zip', $what );
  1404. $country = mp_get_user_address_part( 'country', $what );
  1405.  
  1406. $cart = mp_cart();
  1407. $options = $plugin->shipping_options( $cart, $address1, $address2, $city, $state, $zip, $country );
  1408.  
  1409. $html = '';
  1410. foreach ( (array) $options as $method => $label ) {
  1411. $input_id = 'mp-shipping-option-' . $plugin->plugin_name . '-' . sanitize_title( $method );
  1412. $checked = ( $plugin->plugin_name == $shipping_option && $method == $shipping_sub_option ) ? ' checked' : '';
  1413. $input_name = ( mp_cart()->is_global ) ? 'shipping_method[' . mp_cart()->get_blog_id() . ']' : 'shipping_method';
  1414. $html .= '
  1415. <label class="mp_form_label mp_form_label-checkout-option" for="' . $input_id . '">
  1416. <input
  1417. id="' . $input_id . '"
  1418. type="radio"
  1419. name="' . $input_name . '"
  1420. value="' . $plugin->plugin_name . '->' . $method . '"
  1421. autocomplete="off"
  1422. data-rule-required="true"
  1423. data-msg-required="' . __( 'Please choose a shipping method', 'mp' ) . '"' .
  1424. $checked . ' />
  1425. <span></span>' . $label . '
  1426. </label>';
  1427. }
  1428.  
  1429. /**
  1430. * Filter the shipping options list html
  1431. *
  1432. * @since 3.0
  1433. *
  1434. * @param string $html Current html.
  1435. * @param array $options An array of shipping options.
  1436. */
  1437. $html = apply_filters( 'mp_list_shipping_options', $html, $options );
  1438.  
  1439. if ( $echo ) {
  1440. echo $html;
  1441. } else {
  1442. return $html;
  1443. }
  1444. }
  1445.  
  1446. endif;
  1447.  
  1448. if ( ! function_exists( 'mp_get_user_address_part' ) ) :
  1449.  
  1450. /**
  1451. * Get user address part
  1452. *
  1453. * @since 3.0
  1454. *
  1455. * @param string $what What to get (e.g. address1, address2, etc)
  1456. * @param string $type Either shipping or billing.
  1457. * @param WP_User /int $user Optional, an WP_User object or a user ID. Defaults to the current user.
  1458. *
  1459. * @return string
  1460. */
  1461. function mp_get_user_address_part( $what, $type, $user = null ) {
  1462.  
  1463. if ( is_null( $user ) ) {
  1464. $user = wp_get_current_user();
  1465. } elseif ( ! $user instanceof WP_User && false === ( $user = get_user_by( 'id', $user ) ) ) {
  1466. return false;
  1467. }
  1468.  
  1469. $meta = $user->get( "mp_{$type}_info" );
  1470.  
  1471. if ( 'first_name' == $what || 'last_name' == $what ) {
  1472. if ( 'first_name' == $what ) {
  1473. $first_name = mp_get_session_value( "mp_" . $type . "_info->first_name", mp_arr_get_value( 'first_name', $meta, '' ) );
  1474. if ( ! empty( $first_name ) ) {
  1475. return $first_name;
  1476. }
  1477. } else {
  1478. $last_name = mp_get_session_value( "mp_" . $type . "_info->last_name", mp_arr_get_value( 'last_name', $meta, '' ) );
  1479. if ( ! empty( $last_name ) ) {
  1480. return $last_name;
  1481. }
  1482. }
  1483.  
  1484. $name = mp_get_session_value( "mp_" . $type . "_info->name", $user->display_name );
  1485. $name_parts = explode( ' ', $name );
  1486.  
  1487. if ( 'first_name' == $what ) {
  1488. return mp_arr_get_value( '0', $name_parts, '' );
  1489. } else {
  1490. return mp_arr_get_value( '1', $name_parts, '' );
  1491. }
  1492.  
  1493. } elseif ( 'email' == $what ) {
  1494. $email = mp_get_session_value( "mp_" . $type . "_info->{$what}", mp_arr_get_value( $what, $meta, '' ) );
  1495. if ( ! empty( $email ) ) {
  1496. return $email;
  1497. } else {
  1498. return $user->user_email;
  1499. }
  1500. } else {
  1501. //echo 'type:'.$type;
  1502. return mp_get_session_value( "mp_" . $type . "_info->{$what}", mp_arr_get_value( $what, $meta, '' ) );
  1503. }
  1504. }
  1505.  
  1506. endif;
  1507.  
  1508. if ( ! function_exists( 'mp_get_states' ) ) :
  1509.  
  1510. /**
  1511. * Get an array of states/provinces for a given country
  1512. *
  1513. * @since 3.0
  1514. * @access public
  1515. *
  1516. * @param string $country A country code.
  1517. *
  1518. * @return string
  1519. */
  1520. function mp_get_states( $country ) {
  1521. $list = false;
  1522. $property = $country.'_provinces';
  1523. if ( property_exists( mp(), $property ) ) {
  1524. $list = mp()->$property;
  1525. }
  1526.  
  1527. /**
  1528. * Filter the state/province list
  1529. *
  1530. * @since 3.0
  1531. *
  1532. * @param array $list The current state/province list.
  1533. * @param string $country The current country.
  1534. */
  1535.  
  1536. return apply_filters( 'mp_get_states', $list, $country );
  1537. }
  1538.  
  1539. endif;
  1540.  
  1541. if ( ! function_exists( 'mp_get_image_size' ) ) :
  1542.  
  1543. /**
  1544. * Get the image size per presentation settings
  1545. *
  1546. * @since 3.0
  1547. *
  1548. * @param string $view Either "single" or "list".
  1549. *
  1550. * @return array
  1551. */
  1552. function mp_get_image_size( $view ) {
  1553. $prefix = ( $view == 'single' ) ? 'product' : 'list';
  1554. $size = mp_get_setting( $prefix . '_img_size' );
  1555.  
  1556. if ( $size == 'custom' ) {
  1557. $size = array(
  1558. 'label' => 'custom',
  1559. 'width' => intval( mp_get_setting( $prefix . '_img_size_custom->width' ) ),
  1560. 'height' => intval( mp_get_setting( $prefix . '_img_size_custom->height' ) ),
  1561. );
  1562. } else {
  1563. $size = array(
  1564. 'label' => $size,
  1565. 'width' => get_option( $size . '_size_w' ),
  1566. 'height' => get_option( $size . 'size_h' ),
  1567. );
  1568. }
  1569.  
  1570. return $size;
  1571. }
  1572.  
  1573. endif;
  1574.  
  1575. if ( ! function_exists( 'mp_get_order_history' ) ) :
  1576.  
  1577. /**
  1578. * Get order history for a given user
  1579. *
  1580. * @since 3.0
  1581. *
  1582. * @param int $user_id The ID of the user to retrieve order history for.
  1583. *
  1584. * @return array
  1585. */
  1586. function mp_get_order_history( $user_id = null ) {
  1587. if ( is_null( $user_id ) ) {
  1588. $user_id = get_current_user_id();
  1589. }
  1590.  
  1591. if ( is_multisite() ) {
  1592. global $blog_id;
  1593. $key = 'mp_order_history_' . $blog_id;
  1594. } else {
  1595. $key = 'mp_order_history';
  1596. }
  1597.  
  1598. if ( $user_id ) {
  1599. $orders = (array) get_user_meta( $user_id, $key, true );
  1600. } else {
  1601. //cookie values is serialize format, we will have to unserialize
  1602. $orders = maybe_unserialize( mp_get_cookie_value( $key, array() ) );
  1603. }
  1604.  
  1605. foreach ( $orders as $key => $order ) {
  1606. if ( ! empty( $key ) ) {
  1607. if ( ! empty( $order['id'] ) ) {
  1608. $mp_order = get_post( $order['id'] );
  1609.  
  1610. // if order is deleted or trashed, unset it
  1611. if ( empty( $mp_order ) || 'trash' === $mp_order->post_status || 'auto-draft' === $mp_order->post_status ) {
  1612. unset( $orders[ $key ] );
  1613. }
  1614. }
  1615. } else {
  1616. unset( $orders[ $key ] );
  1617. }
  1618. }
  1619.  
  1620. /**
  1621. * Filter the user's order history
  1622. *
  1623. * @since 3.0
  1624. *
  1625. * @param array $orders The current array of orders.
  1626. * @param int $user_id The user's ID.
  1627. */
  1628. $orders = (array) apply_filters( 'mp_get_order_history', $orders, $user_id );
  1629.  
  1630. // Put orders in reverse chronological order
  1631. krsort( $orders );
  1632.  
  1633. return $orders;
  1634. }
  1635.  
  1636. endif;
  1637.  
  1638. if ( ! function_exists( 'mp_store_page_uri' ) ) {
  1639.  
  1640. /**
  1641. * Get a store page uri
  1642. *
  1643. * @since 3.0
  1644. *
  1645. * @param string $page The page to get the uri for.
  1646. * @param bool $echo Optional, whether to echo or return. Defaults to echo.
  1647. */
  1648. function mp_store_page_uri( $page, $echo = true ) {
  1649. $url = $append = '';
  1650.  
  1651. if ( $page == 'confirm_order' ) {
  1652. $append = 'confirm/';
  1653. $page = 'checkout';
  1654. }
  1655.  
  1656. if ( $post_id = mp_get_setting( "pages->{$page}" ) ) {
  1657. $url = trailingslashit( get_page_uri( $post_id ) ) . $append;
  1658. }
  1659.  
  1660. if ( $echo ) {
  1661. echo $url;
  1662. } else {
  1663. return $url;
  1664. }
  1665. }
  1666.  
  1667. }
  1668.  
  1669. if ( ! function_exists( 'mp_store_page_url' ) ) :
  1670.  
  1671. /**
  1672. * Get a store page url
  1673. *
  1674. * @since 3.0
  1675. *
  1676. * @param string $page The page to get the URL for.
  1677. * @param bool $echo Optional, whether to echo or return. Defaults to echo.
  1678. */
  1679. function mp_store_page_url( $page, $echo = true ) {
  1680. $url = $append = '';
  1681.  
  1682. if ( $page == 'confirm_order' ) {
  1683. $append = 'confirm/';
  1684. $page = 'checkout';
  1685. }
  1686.  
  1687. if ( $post_id = mp_get_setting( "pages->{$page}" ) ) {
  1688. $url = trailingslashit( get_permalink( $post_id ) ) . $append;
  1689. }
  1690.  
  1691. if ( $echo ) {
  1692. echo $url;
  1693. } else {
  1694. return $url;
  1695. }
  1696. }
  1697.  
  1698. endif;
  1699.  
  1700. if ( ! function_exists( 'mp_tax_rate' ) ) :
  1701.  
  1702. /**
  1703. * Get the tax rate per settings
  1704. *
  1705. * @since 3.0
  1706. *
  1707. * @param bool $echo Optional, whether to echo or return. Defaults to return.
  1708. */
  1709. function mp_tax_rate( $echo = false ) {
  1710. //get address
  1711. $state = mp_get_user_address_part( 'state', 'shipping' );
  1712. $country = mp_get_user_address_part( 'country', 'shipping' );
  1713. $tax_rate = 0;
  1714.  
  1715. if ( empty( $country ) ) {
  1716. $country = mp_get_setting( 'base_country' );
  1717. }
  1718.  
  1719. if ( empty( $state ) ) {
  1720. $state = mp_get_setting( 'base_province' );
  1721. }
  1722.  
  1723. switch ( $country ) {//mp_get_setting( 'base_country' )
  1724. case 'US':
  1725. // USA taxes are only for orders delivered inside the state
  1726. if ( $country == 'US' && $state == mp_get_setting( 'base_province' ) ) {
  1727. $tax_rate = (float) mp_get_setting( 'tax->rate' );
  1728. }
  1729. break;
  1730.  
  1731. case 'CA':
  1732. //Canada tax is for all orders in country, based on province shipped to. We're assuming the rate is a combination of GST/PST/etc.
  1733. if ( $country == 'CA' && array_key_exists( $state, mp()->CA_provinces ) ) {
  1734. if ( $_tax_rate = mp_get_setting( "tax->canada_rate->$state" ) ) {
  1735. $tax_rate = (float) $_tax_rate;
  1736. }
  1737. }
  1738. break;
  1739.  
  1740. case 'AU':
  1741. //Australia taxes orders in country
  1742. if ( $country == 'AU' ) {
  1743. $tax_rate = (float) mp_get_setting( 'tax->rate' );
  1744. }
  1745. break;
  1746.  
  1747. default:
  1748. //EU countries charge VAT within the EU
  1749. if ( in_array( mp_get_setting( 'base_country' ), mp()->eu_countries ) ) {
  1750. if ( in_array( $country, mp()->eu_countries ) ) {
  1751. $tax_rate = (float) mp_get_setting( 'tax->rate' );
  1752. }
  1753. } else {
  1754. //all other countries use the tax outside preference
  1755. //if ( mp_get_setting( 'tax->tax_outside' ) || (!mp_get_setting( 'tax->tax_outside' ) && $country == mp_get_setting( 'base_country' )) ) {
  1756. $tax_rate = (float) mp_get_setting( 'tax->rate' );
  1757. //}
  1758. }
  1759. break;
  1760. }
  1761.  
  1762. //$tax_rate = (float) mp_get_setting( 'tax->rate' );
  1763.  
  1764. if ( empty( $tax_rate ) ) {
  1765. $tax_rate = 0;
  1766. }
  1767.  
  1768. /**
  1769. * Filter the tax rate
  1770. *
  1771. * @since 3.0
  1772. *
  1773. * @param float
  1774. * @param float $tax_rate The current tax rate.
  1775. */
  1776. $tax_rate = (float) apply_filters( 'mp_tax_rate', $tax_rate );
  1777.  
  1778. if ( $echo ) {
  1779. echo $tax_rate;
  1780. } else {
  1781. return $tax_rate;
  1782. }
  1783. }
  1784.  
  1785. endif;
  1786.  
  1787. if ( ! function_exists( 'mp_weight_label' ) ) :
  1788.  
  1789. /**
  1790. * Display the appropriate weight label (kgs/lbs) according to settings
  1791. *
  1792. * @since 3.0
  1793. *
  1794. * @param int /float $val
  1795. *
  1796. * @return string
  1797. */
  1798. function mp_weight_label( $val = null ) {
  1799. $units = ( 'english' == mp_get_setting( 'shipping->system' ) ) ? 'lbs' : 'kgs';
  1800. $html = '<span class="mp-weight-label">' . ( ( ! is_null( $val ) ) ? $val : '' ) . '<span class="mp-units">' . $units . '</span>' . '</span>';
  1801.  
  1802. /**
  1803. * Filter the weight label
  1804. *
  1805. * @since 3.0
  1806. *
  1807. * @param string $html
  1808. * @param int /float $val
  1809. * @param string $units Either "kgs" or "lbs".
  1810. */
  1811. $html = apply_filters( 'mp_weight_label', $html, $val, $units );
  1812.  
  1813. return $html;
  1814. }
  1815.  
  1816. endif;
  1817.  
  1818. if ( ! function_exists( 'mp_dimension_label' ) ) :
  1819.  
  1820. /**
  1821. * Display the appropriate dimension label (in/cm) according to settings
  1822. *
  1823. * @since 3.0
  1824. *
  1825. * @param int /float $val
  1826. */
  1827. function mp_dimension_label( $val = null ) {
  1828. $units = ( 'english' == mp_get_setting( 'shipping->system' ) ) ? 'in' : 'cm';
  1829. $html = '<span class="mp-dimension-label">' . ( ( ! is_null( $val ) ) ? $val : '' ) . '<span class="mp-units">' . $units . '</span>' . '</span>';
  1830.  
  1831. /**
  1832. * Filter the dimension label
  1833. *
  1834. * @since 3.0
  1835. *
  1836. * @param string $html
  1837. * @param int /float $val
  1838. * @param string $units Either "in" or "cm".
  1839. */
  1840. $html = apply_filters( 'mp_dimension_label', $html, $val, $units );
  1841.  
  1842. return $html;
  1843. }
  1844.  
  1845. endif;
  1846.  
  1847.  
  1848. if ( ! function_exists( 'mp_is_shop_page' ) ) :
  1849.  
  1850. /**
  1851. * Check if current page is a shop page
  1852. *
  1853. * @since 3.0
  1854. *
  1855. * @param array /string $page The specific page to check - e.g. "cart".
  1856. *
  1857. * @return bool
  1858. */
  1859. function mp_is_shop_page( $page = null ) {
  1860. return ( is_admin() ) ? false : MP_Public::get_instance()->is_store_page( $page );
  1861. }
  1862.  
  1863. endif;
  1864.  
  1865. if ( ! function_exists( 'mp_list_products' ) ) :
  1866.  
  1867. /**
  1868. * Display a list of products according to preference
  1869. *
  1870. * @since 3.0
  1871. *
  1872. * @param bool $echo Optional, whether to echo or return
  1873. * @param bool $paginate Optional, whether to paginate
  1874. * @param int $page Optional, The page number to display in the product list if $paginate is set to true.
  1875. * @param int $per_page Optional, How many products to display in the product list if $paginate is set to true.
  1876. * @param string $order_by Optional, What field to order products by. Can be: title, date, ID, author, price, sales, rand
  1877. * @param string $order Optional, Direction to order products by. Can be: DESC, ASC
  1878. * @param string $category Optional, limit to a product category
  1879. * @param string $tag Optional, limit to a product tag
  1880. * @param bool $list_view Optional, show as list. Default to presentation settings
  1881. * @param bool $filters Optional, show filters
  1882. */
  1883. function mp_list_products() {
  1884. // Init args
  1885. $func_args = func_get_args();
  1886. $args = mp_parse_args( $func_args, mp()->defaults['list_products'] );
  1887. $args['nopaging'] = false;
  1888.  
  1889. // Init query params
  1890. $query = array(
  1891. 'post_type' => MP_Product::get_post_type(),
  1892. 'post_status' => 'publish',
  1893. );
  1894.  
  1895. // Setup taxonomy query
  1896. $tax_query = array();
  1897. if ( ! is_null( $args['category'] ) || ! is_null( $args['tag'] ) ) {
  1898. if ( ! is_null( $args['category'] ) ) {
  1899. $tax_query[] = array(
  1900. 'taxonomy' => 'product_category',
  1901. 'field' => 'slug',
  1902. 'terms' => sanitize_title( $args['category'] ),
  1903. );
  1904. }
  1905.  
  1906. if ( ! is_null( $args['tag'] ) ) {
  1907. $tax_query[] = array(
  1908. 'taxonomy' => 'product_tag',
  1909. 'field' => 'slug',
  1910. 'terms' => sanitize_title( $args['tag'] ),
  1911. );
  1912. }
  1913. } elseif ( get_query_var( 'taxonomy' ) == 'product_category' ) {
  1914. $tax_query[] = array(
  1915. 'taxonomy' => 'product_category',
  1916. 'field' => 'slug',
  1917. 'terms' => get_query_var( 'term' ),
  1918. );
  1919. } elseif ( get_query_var( 'taxonomy' ) == 'product_tag' ) {
  1920. $tax_query[] = array(
  1921. 'taxonomy' => 'product_tag',
  1922. 'field' => 'slug',
  1923. 'terms' => get_query_var( 'term' ),
  1924. );
  1925. }
  1926.  
  1927. if ( count( $tax_query ) > 1 ) {
  1928. $query['tax_query'] = array_merge( array( 'relation' => 'AND' ), $tax_query );
  1929. } elseif ( count( $tax_query ) == 1 ) {
  1930. $query['tax_query'] = $tax_query;
  1931. }
  1932.  
  1933. // Setup pagination
  1934. if ( ( ! is_null( $args['paginate'] ) && ! $args['paginate'] ) || ( is_null( $args['paginate'] ) && ! mp_get_setting( 'paginate' ) ) ) {
  1935. $query['nopaging'] = $args['nopaging'] = true;
  1936. } else {
  1937. // Figure out per page
  1938. if ( ! is_null( $args['per_page'] ) ) {
  1939. $query['posts_per_page'] = intval( $args['per_page'] );
  1940. } else {
  1941. //$query[ 'posts_per_page' ] = intval( $args[ 'per_page' ] );
  1942. $query['posts_per_page'] = intval( mp_get_setting( 'per_page' ) );
  1943. }
  1944.  
  1945. // Figure out page
  1946. if ( ! is_null( $args['page'] ) ) {
  1947. $query['paged'] = intval( $args['page'] );
  1948. } elseif ( get_query_var( 'paged' ) != '' ) {
  1949. $query['paged'] = $args['page'] = intval( get_query_var( 'paged' ) );
  1950. } elseif ( get_query_var( 'page' ) != '' ) {
  1951. $query['paged'] = $args['page'] = intval( get_query_var( 'page' ) );
  1952. }
  1953.  
  1954. /*//Get session values for order and order_by
  1955. if ( session_id() == '' ) {
  1956. if (version_compare(phpversion(), '5.4.0', '<')) {
  1957. if(session_id() == '') {
  1958. @session_start();
  1959. }
  1960. }
  1961. else
  1962. {
  1963. if (session_status() == PHP_SESSION_NONE) {
  1964. @session_start();
  1965. }
  1966. }
  1967. }*/
  1968.  
  1969. if( !isset( $_SESSION ) ){
  1970. $_SESSION = array();
  1971. }
  1972.  
  1973. $order_by = isset( $_SESSION['mp_product_list_order_by'] ) ? $_SESSION['mp_product_list_order_by'] : '';
  1974. $order = isset( $_SESSION['mp_product_list_order'] ) ? $_SESSION['mp_product_list_order'] : '';
  1975.  
  1976. if ( ! empty( $order_by ) && ! empty( $order ) ) {
  1977. $query['orderby'] = $order_by;
  1978. $query['order'] = $order;
  1979.  
  1980. $args['order_by'] = $order_by;
  1981. $args['order'] = $order;
  1982. }
  1983.  
  1984. // Get order by
  1985. if ( ! is_null( $args['order_by'] ) ) {
  1986. if ( 'price' == $args['order_by'] ) {
  1987. $query['meta_key'] = 'sort_price';
  1988. $query['orderby'] = 'meta_value_num';
  1989. } else if ( 'sales' == $args['order_by'] ) {
  1990. $query['meta_key'] = 'mp_sales_count';
  1991. $query['orderby'] = 'meta_value_num';
  1992. } else {
  1993. $query['orderby'] = $args['order_by'];
  1994. }
  1995. } elseif ( 'price' == mp_get_setting( 'order_by' ) ) {
  1996. $query['meta_key'] = 'sort_price';
  1997. $query['orderby'] = 'meta_value_num';
  1998. } elseif ( 'sales' == mp_get_setting( 'order_by' ) ) {
  1999. $query['meta_key'] = 'mp_sales_count';
  2000. $query['orderby'] = 'meta_value_num';
  2001. } else {
  2002. $query['orderby'] = mp_get_setting( 'order_by' );
  2003. }
  2004. }
  2005.  
  2006. // Get order direction
  2007. $query['order'] = mp_get_setting( 'order' );
  2008. if ( ! is_null( $args['order'] ) ) {
  2009. $query['order'] = $args['order'];
  2010. }
  2011.  
  2012. // Filter by featured
  2013. if ( (bool) $args['featured'] ) {
  2014. $query['meta_query'][] = array(
  2015. 'key' => 'featured',
  2016. 'value' => '1',
  2017. 'compare' => '=',
  2018. );
  2019. }
  2020.  
  2021. if( mp_get_setting( 'inventory_remove' ) )
  2022. {
  2023. $query['meta_query'][] = array(
  2024. array(
  2025. 'relation' => 'OR',
  2026. array(
  2027. 'key' => 'inventory_tracking',
  2028. 'value' => '0',
  2029. 'compare' => '=',
  2030. ),
  2031. array(
  2032. 'relation' => 'OR',
  2033. array(
  2034. 'key' => 'inv_out_of_stock_purchase',
  2035. 'value' => '1',
  2036. 'compare' => '=',
  2037. ),
  2038. array(
  2039. 'key' => 'inventory',
  2040. 'value' => '0',
  2041. 'compare' => '>',
  2042. )
  2043. )
  2044. )
  2045. );
  2046. }
  2047.  
  2048. // The Query
  2049. $custom_query = new WP_Query( $query );
  2050. // Get layout type
  2051. $layout_type = mp_get_setting( 'list_view' );
  2052. if ( ! is_null( $args['list_view'] ) ) {
  2053. $layout_type = $args['list_view'] ? 'list' : 'grid';
  2054. }
  2055.  
  2056. //$layout_type_output = (( 'grid' == $layout_type ) ? 'mp_products-grid' : 'mp_products-list');
  2057. // Build content
  2058. $content = '';
  2059.  
  2060. if ( ! mp_doing_ajax() ) {
  2061. $per_page = ( is_null( $args['per_page'] ) ) ? null : $args['per_page'];
  2062. $content .= ( $args['filters'] || ( is_null( $args['filters'] ) && 1 != mp_get_setting( 'hide_products_filter' ) ) ) ? mp_products_filter( false, $per_page, $custom_query ) : '';
  2063. }
  2064.  
  2065. $content .= '<!-- MP Product List --><section id="mp-products" class="hfeed mp_products mp_products-' . $layout_type . '">';
  2066.  
  2067. if ( $last = $custom_query->post_count ) {
  2068. $content .= $layout_type == 'grid' ? _mp_products_html_grid( $custom_query ) : _mp_products_html_list( $custom_query );
  2069. } else {
  2070. $content .= '<div id="mp-products-empty">' . apply_filters( 'mp_product_list_none', __( 'No Products', 'mp' ) ) . '</div><!-- end mp-no-products -->';
  2071. }
  2072.  
  2073. $content .= '</section><!-- end mp-products -->';
  2074.  
  2075. $content .= ( ! $args['nopaging'] ) ? mp_products_nav( false, $custom_query ) : '';
  2076.  
  2077. /**
  2078. * Filter product list html
  2079. *
  2080. * @since 3.0
  2081. *
  2082. * @param string $content The current html content.
  2083. * @param array $args The arguments passed to mp_list_products
  2084. */
  2085. $content = apply_filters( 'mp_list_products', $content, $args );
  2086.  
  2087. if ( $args['echo'] ) {
  2088. echo $content;
  2089. } else {
  2090. return $content;
  2091. }
  2092. }
  2093.  
  2094. endif;
  2095.  
  2096. if ( ! function_exists( 'mp_order_lookup_form' ) ) :
  2097.  
  2098. /**
  2099. * Display a form for looking up orders
  2100. *
  2101. * @since 3.0
  2102. *
  2103. * @param array $args {
  2104. * Optional, an array of arguments.
  2105. *
  2106. * @type bool $echo Optional, whether to echo or return. Defaults to echo.
  2107. * @type string $content Optional, the content to display before the form.
  2108. * }
  2109. */
  2110. function mp_order_lookup_form( $args = array() ) {
  2111. $_args = array_replace_recursive( array(
  2112. 'echo' => true,
  2113. 'content' => '',
  2114. ), $args );
  2115.  
  2116. extract( $_args );
  2117.  
  2118. if ( get_query_var( 'mp_order_id' ) ) {
  2119. return '';
  2120. }
  2121.  
  2122. $guest_email = '';
  2123.  
  2124. //Add guest email field
  2125. if( ! is_user_logged_in() ){
  2126. $guest_email = '<br/><input type="text" class="mp_form_input" id="mp-guest_email-input" name="guest_email" placeholder="' . __( 'Guest Email', 'mp' ) . '">';
  2127. }
  2128.  
  2129. $form = '
  2130. <form id="mp-order-lookup-form" class="mp_form mp_form-order-lookup" method="post" action="' . admin_url( 'admin-ajax.php?action=mp_lookup_order' ) . '">
  2131. <div class="mp_form_content">' . $content . '</div>
  2132. <div class="mp_form_group">
  2133. <div class="mp_form_group_input">
  2134. <input type="text" class="mp_form_input" id="mp-order-id-input" name="order_id" placeholder="' . __( 'Order ID', 'mp' ) . '">
  2135. ' . $guest_email . '
  2136. </div>
  2137. <div class="mp_form_group_btn">
  2138. <button class="mp_button" type="submit">' . __( 'Look Up', 'mp' ) . '</button>
  2139. </div>
  2140. </div>
  2141. </form><!-- end mp-order-lookup-form -->';
  2142.  
  2143. /**
  2144. * Filter the order lookup form html
  2145. *
  2146. * @since 3.0
  2147. *
  2148. * @param string $form The form HTML.
  2149. * @param array $args Any arguments passed to the function.
  2150. */
  2151. $form = apply_filters( 'mp_order_lookup_form', $form, $args );
  2152.  
  2153. if ( $echo ) {
  2154. echo $form;
  2155. } else {
  2156. return $form;
  2157. }
  2158. }
  2159.  
  2160. endif;
  2161.  
  2162. if ( ! function_exists( 'mp_order_status' ) ) :
  2163.  
  2164. /**
  2165. * Display the order status page html
  2166. *
  2167. * @since 3.0
  2168. *
  2169. * @param array $args {
  2170. * Optional, an array of arguments.
  2171. *
  2172. * @type bool $echo Optional, whether to echo or return. Defaults to echo.
  2173. * @type string $order_id Optional, the specific order ID to show. If empty, defaults to order status overview page.
  2174. * }
  2175. */
  2176. function mp_order_status( $args ) {
  2177. $args = array_replace_recursive( array(
  2178. 'echo' => false,
  2179. 'order_id' => get_query_var( 'mp_order_id', null ),
  2180. 'guest_email' => get_query_var( 'mp_guest_email', null ),
  2181. ), $args );
  2182.  
  2183. extract( $args );
  2184.  
  2185. $html = '';
  2186.  
  2187. //check does user logged in
  2188. if ( is_user_logged_in() ) {
  2189. if ( is_null( $order_id ) ) {
  2190. $html .= _mp_order_status_overview();
  2191. } else {
  2192. $order = new MP_Order( $order_id );
  2193. if ( $order->exists() ) {
  2194. //only owner and store admins can see
  2195. if ( $order->post_author != get_current_user_id() && !current_user_can( apply_filters( 'mp_store_settings_cap', 'read_store_order' ) ) ) {
  2196. $html .= __( 'Oops! We couldn\'t locate any orders matching that order number. Please verify the order number and try again.', 'mp' );
  2197. $html .= _mp_order_status_overview();
  2198. } else {
  2199. $html .= $order->details( false );
  2200. }
  2201. } else {
  2202. $html .= __( 'Oops! We couldn\'t locate any orders matching that order number. Please verify the order number and try again.', 'mp' );
  2203. $html .= _mp_order_status_overview();
  2204. }
  2205. }
  2206. } else {
  2207. if ( ! is_null( $order_id ) ) {
  2208. if( ! is_null ( $guest_email ) ) {
  2209. // If email and order provided matches, show the order status page
  2210. $order = new MP_Order( $order_id );
  2211. if ( $order->exists() && ( md5( $order->get_meta( 'mp_billing_info->email', '' ) ) == $guest_email || md5( $order->get_meta( 'mp_shipping_info->email', '' ) ) == $guest_email ) ) {
  2212. $html .= $order->details( false );
  2213. } else {
  2214. $html .= __( 'Oops! We couldn\'t locate any orders matching that order number. Please verify the order number and try again.', 'mp' );
  2215. }
  2216. } else {
  2217. $html .= __( 'Oops! We couldn\'t locate any orders matching that order number. Please verify the order number and try again.', 'mp' );
  2218. }
  2219. }
  2220. }
  2221.  
  2222. if ( $echo ) {
  2223. echo $html;
  2224. } else {
  2225. return $html;
  2226. }
  2227. }
  2228.  
  2229. endif;
  2230.  
  2231. if ( ! function_exists( 'mp_pinit_button' ) ) :
  2232.  
  2233. /**
  2234. * Pinterest PinIt button
  2235. *
  2236. * @param int $product_id
  2237. * @param string $context
  2238. * @param bool $echo
  2239. */
  2240. function mp_pinit_button( $product_id = null, $context = 'single_view', $echo = false ) {
  2241. _deprecated_function( 'mp_pinit_button', '3.0', 'MP_Product::pinit_button()' );
  2242.  
  2243. $product = new MP_Product( $product_id );
  2244. $snippet = $product->pinit_button( $context, false );
  2245.  
  2246. if ( $echo ) {
  2247. echo $snippet;
  2248. } else {
  2249. return $snippet;
  2250. }
  2251. }
  2252.  
  2253. endif;
  2254.  
  2255. if ( ! function_exists( 'mp_featured_products' ) ) :
  2256.  
  2257. /**
  2258. * Displays a list of popular products ordered by sales.
  2259. *
  2260. * @since 3.0
  2261. *
  2262. * @uses mp_list_products()
  2263. *
  2264. * @param bool $echo Optional, whether to echo or return
  2265. * @param bool $paginate Optional, whether to paginate
  2266. * @param int $page Optional, The page number to display in the product list if $paginate is set to true.
  2267. * @param int $per_page Optional, How many products to display in the product list if $paginate is set to true.
  2268. * @param string $order_by Optional, What field to order products by. Can be: title, date, ID, author, price, sales, rand
  2269. * @param string $order Optional, Direction to order products by. Can be: DESC, ASC
  2270. * @param string $category Optional, limit to a product category
  2271. * @param string $tag Optional, limit to a product tag
  2272. * @param bool $list_view Optional, show as list. Default to presentation settings
  2273. * @param bool $filters Optional, show filters
  2274. */
  2275. function mp_featured_products() {
  2276. $func_args = func_get_args();
  2277. $args = mp_parse_args( $func_args, mp()->defaults['list_products'] );
  2278. $echo = $args['echo'];
  2279.  
  2280. // force echo to false to get content from mp_list_products()
  2281. // force featured to true to filter only featured in mp_list_products()
  2282. $args['echo'] = false;
  2283. $args['nopaging'] = false;
  2284. $args['featured'] = true;
  2285. $content = mp_list_products($args);
  2286.  
  2287. /**
  2288. * Filter the featured products html
  2289. *
  2290. * @since 3.0
  2291. *
  2292. * @param string $content The current HTML markup.
  2293. * @param array $args mp_featured_products short code attributes.
  2294. */
  2295. $content = apply_filters( 'mp_featured_products', $content, $args );
  2296.  
  2297.  
  2298. if ( $echo ) {
  2299. echo $content;
  2300. } else {
  2301. return $content;
  2302. }
  2303. }
  2304.  
  2305. endif;
  2306.  
  2307. if ( ! function_exists( 'mp_popular_products' ) ) :
  2308.  
  2309. /**
  2310. * Displays a list of popular products ordered by sales.
  2311. *
  2312. * @since 3.0
  2313. *
  2314. * @param bool $echo Optional, whether to echo or return
  2315. * @param int $num Optional, max number of products to display. Defaults to 5
  2316. */
  2317. function mp_popular_products( $echo = true, $num = 5 ) {
  2318. $num = (int) $num;
  2319. $custom_query = new WP_Query( array(
  2320. 'post_type' => MP_Product::get_post_type(),
  2321. 'post_status' => 'publish',
  2322. 'posts_per_page' => $num,
  2323. 'meta_query' => array(
  2324. array(
  2325. 'key' => 'mp_sales_count',
  2326. 'value' => '0',
  2327. 'compare' => '>',
  2328. 'type' => 'NUMERIC',
  2329. ),
  2330. ),
  2331. 'orderby' => 'meta_value_num',
  2332. 'meta_key' => 'mp_sales_count',
  2333. 'order' => 'DESC',
  2334. ) );
  2335.  
  2336. $content = '
  2337. <ul id="mp_popular_products">';
  2338.  
  2339. if ( $custom_query->have_posts() ) {
  2340. while ( $custom_query->have_posts() ) : $custom_query->the_post();
  2341. $content .= '
  2342. <li><a href="' . get_permalink() . '">' . get_the_title() . '</a></li>';
  2343. endwhile;
  2344. wp_reset_postdata();
  2345. } else {
  2346. $content .= '
  2347. <li>' . __( 'No Products', 'mp' ) . '</li>';
  2348. }
  2349.  
  2350. $content .= '
  2351. </ul>';
  2352.  
  2353. /**
  2354. * Filter the popular products html
  2355. *
  2356. * @since 3.0
  2357. *
  2358. * @param string $content The current HTML markup.
  2359. * @param int $num The number of products to display.
  2360. */
  2361. $content = apply_filters( 'mp_popular_products', $content, $num );
  2362.  
  2363. if ( $echo ) {
  2364. echo $content;
  2365. } else {
  2366. return $content;
  2367. }
  2368. }
  2369.  
  2370. endif;
  2371.  
  2372.  
  2373. if ( ! function_exists( 'mp_product' ) ) {
  2374. /*
  2375. * Displays a single product according to preference
  2376. *
  2377. * @param bool $echo Optional, whether to echo or return
  2378. * @param int $product_id the ID of the product to display. Optional if in the loop.
  2379. * @param bool $title Whether to display the title
  2380. * @param bool/string $content Whether and what type of content to display. Options are false, 'full', or 'excerpt'. Default 'full'
  2381. * @param bool/string $image Whether and what context of image size to display. Options are false, 'single', or 'list'. Default 'single'
  2382. * @param bool $meta Whether to display the product meta
  2383. */
  2384.  
  2385. function mp_product(
  2386. $echo = true, $product_id = null, $title = true, $content = 'full', $image = 'single',
  2387. $meta = true
  2388. ) {
  2389. global $wp_query;
  2390.  
  2391. if ( function_exists( 'icl_object_id' ) ) {
  2392. $product_id = icl_object_id( $product_id, MP_Product::get_post_type(), false );
  2393. }
  2394.  
  2395. $product = new MP_Product( $product_id );
  2396. if ( ! $product->exists() ) {
  2397. return;
  2398. }
  2399. $form_id = 'mp_buy_form_' . $product_id;
  2400.  
  2401. $variation = false;
  2402. $pinit = $product->pinit_button( 'single_view' );
  2403. $fb = $product->facebook_like_button( 'single_view' );
  2404. $twitter = $product->twitter_button( 'single_view' );
  2405.  
  2406. $display_description = ( ! empty( $content ) && (bool) $content );
  2407.  
  2408. $has_image = false;
  2409. if ( ! $product->has_variations() ) {
  2410. $values = get_post_meta( $product->ID, 'mp_product_images', true );
  2411. if ( $values ) {
  2412. $has_image = true;
  2413. }
  2414. } else {
  2415. $variation_id = intval( get_post_meta( $product->ID, 'default_variation', true ) );
  2416. if( get_query_var( 'mp_variation_id' ) != '' && is_numeric( get_query_var( 'mp_variation_id' ) ) ) $variation_id = get_query_var( 'mp_variation_id' );
  2417.  
  2418. if( is_numeric( $variation_id ) ){
  2419. $variation = new MP_Product( $variation_id );
  2420. if ( ! $variation->exists() ) {
  2421. $variation = false;
  2422. }
  2423. }
  2424.  
  2425. foreach ( $product->get_variation_ids() as $id ) {
  2426. $post_thumbnail_id = get_post_thumbnail_id( $id );
  2427. if ( $post_thumbnail_id ) {
  2428. $has_image = true;
  2429. break;
  2430. }
  2431. }
  2432.  
  2433. // if ( ! $has_image ) {
  2434. // $values = get_post_meta( $product->ID, 'mp_product_images', true );
  2435. // if ( $values ) {
  2436. // $has_image = true;
  2437. // }
  2438. // }
  2439. }
  2440.  
  2441. $image_alignment = mp_get_setting( 'image_alignment_single' );
  2442.  
  2443. $return = '
  2444. <!-- MP Single Product -->
  2445. <section id="mp-single-product-' . $product->ID . '" class="mp-single-product" itemscope itemtype="http://schema.org/Product">
  2446. <div class="mp_product mp_single_product' . ( $has_image ? ' mp_single_product-has-image mp_single_product-image-' . ( ! empty( $image_alignment ) ? $image_alignment : 'aligncenter' ) . '' : '' ) . ( $product->has_variations() ? ' mp_single_product-has-variations' : '' ) . '">';
  2447.  
  2448. $values = get_post_meta( $product->ID, 'mp_product_images', true );
  2449.  
  2450. if ( mp_get_setting( 'product_img_size' ) == 'custom' ) {
  2451. $size = array(
  2452. mp_get_setting( 'product_img_size_custom->width' ),
  2453. mp_get_setting( 'product_img_size_custom->height' )
  2454. );
  2455. } else {
  2456. $size = mp_get_setting( 'product_img_size' );
  2457. }
  2458.  
  2459. $lightbox_code = '';
  2460. $show_lightbox = mp_get_setting( 'show_lightbox' );
  2461.  
  2462. if ( $show_lightbox == 1 && mp_get_setting( 'disable_large_image' ) != 1 ) {
  2463. $lightbox_code = "onSliderLoad: function(el) {
  2464. el.lightGallery({
  2465. selector: '#mp-product-gallery .lslide',
  2466. thumbnail: true,
  2467. zoom: true,
  2468. });
  2469. }";
  2470. }
  2471.  
  2472. $lightbox_code = apply_filters( 'mp_single_product_image_lightbox', $lightbox_code );
  2473.  
  2474. $post = get_post();
  2475.  
  2476. if ( $image && $has_image && ! post_password_required( $post ) ) {
  2477. if ( ! $product->has_variations() ) {
  2478.  
  2479. if ( $values ) {
  2480.  
  2481. $return .= '<div class="mp_single_product_images">';
  2482.  
  2483. $return .= "<script>
  2484. jQuery(document).ready(function() {
  2485. jQuery('#mp-product-gallery').lightSlider({
  2486. gallery:true,
  2487. item:1,
  2488. loop:true,
  2489. thumbItem:5,
  2490. slideMargin:0,
  2491. enableDrag: true,
  2492. currentPagerPosition:'left',
  2493. " . $lightbox_code . "
  2494. });
  2495. });
  2496. </script>";
  2497.  
  2498. $return .= '<ul id="mp-product-gallery" class="mp_product_gallery">';
  2499.  
  2500. $values = explode( ',', $values );
  2501.  
  2502. if ( $image != "single" ) {
  2503. foreach ( $values as $value ) {
  2504.  
  2505. if ( preg_match( '/http:|https:/', $value ) ) {
  2506. $img_url = array( esc_url( $value ) );
  2507. } else {
  2508. //$img_url = wp_get_attachment_image_src( $value, $size );
  2509. $original_image = wp_get_attachment_image_src( $value, 'full' );
  2510. $img_url = mp_resize_image( $value, $original_image[0], $size );
  2511. }
  2512.  
  2513. $return .= '<li data-thumb="' . $img_url[0] . '" data-src ="' . $original_image[0] . '"><img src="' . $img_url[0] . '"></li>';
  2514. }
  2515. } else {
  2516. if ( ! empty( $values[0] ) ) {
  2517.  
  2518. if ( preg_match( '/http:|https:/', $values[0] ) ) {
  2519. $img_url = array( esc_url( $values[0] ) );
  2520. } else {
  2521. $original_image = wp_get_attachment_image_src( $values[0], 'full' );
  2522. $img_url = mp_resize_image( $values[0], $original_image[0], $size );
  2523. }
  2524.  
  2525. $return .= '<li data-thumb="' . $img_url[0] . '" data-src ="' . $original_image[0] . '"><img src="' . $img_url[0] . '"></li>';
  2526. }
  2527. }
  2528.  
  2529. $return .= '</ul><!-- end mp_product_gallery -->';
  2530.  
  2531. $return .= '</div><!-- end mp_single_product_images -->';
  2532. }
  2533. } else {
  2534. $return .= '<div class="mp_single_product_images">';
  2535. $return .= ( $variation ) ? $variation->image( false, 'single', $size, $image_alignment ) : $product->image( false, 'single', $size, $image_alignment );
  2536. $return .= '</div><!-- end mp_single_product_images -->';
  2537. }
  2538. }
  2539.  
  2540. if ( $image && ! post_password_required( $post ) ) {
  2541. $return .= '<div class="mp_single_product_details">';
  2542.  
  2543. $return .= '<span style="display:none" class="date updated">' . get_the_time( $product->ID ) . '</span>'; // mp_product_class(false, 'mp_product', $post->ID)
  2544. }
  2545.  
  2546.  
  2547. if ( $title ) {
  2548. $return .= ' <h1 itemprop="name" class="mp_product_name entry-title"><a href="' . $product->url( false ) . '">' . $product->title( false ) . '</a></h1>';
  2549.  
  2550. // If post password required and it doesn't match the cookie.
  2551. if ( post_password_required( $post ) )
  2552. $return .= get_the_password_form( $post );
  2553. }
  2554.  
  2555. if ( $meta && ! post_password_required( $post ) ) {
  2556. $return .= '<div class="mp_product_meta">';
  2557.  
  2558. // Price
  2559. $return .= ( $variation ) ? $variation->display_price( false ) : $product->display_price( false );
  2560.  
  2561. if ( mp_get_setting( 'show_single_excerpt' ) == 1 && $display_description ) {
  2562. // Excerpt
  2563. if ( ! $variation ) {
  2564. $return .= '<div class="mp_product_excerpt">';
  2565. $return .= mp_get_the_excerpt( $product_id, apply_filters( 'mp_get_the_excerpt_length', 18 ) );
  2566. $return .= '</div><!-- end mp_product_excerpt -->';
  2567. } else {
  2568. $return .= '<div class="mp_product_excerpt mp_product_excerpt-variation">';
  2569. $return .= mp_get_the_excerpt( $variation_id, apply_filters( 'mp_get_the_excerpt_length', 18 ), true );
  2570. $return .= '</div><!-- end mp_product_excerpt -->';
  2571. }
  2572. }
  2573.  
  2574. if ( mp_get_setting( 'show_single_categories' ) == 1 ) {
  2575. $return .= mp_category_list( $product_id, '<div class="mp_product_categories">' . __( 'Categorized in ', 'mp' ), ', ', '</div>' );
  2576. }
  2577.  
  2578. $return .= '</div><!-- end mp_product_meta-->';
  2579.  
  2580. // Callout
  2581. $return .= '<div class="mp_product_callout">';
  2582.  
  2583. // Button
  2584. $selected_atts = array();
  2585.  
  2586. if ( $variation && isset( $variation_id ) && false !== get_post_meta( $variation_id, 'default_variation' ) ) {
  2587. $atts = $variation->get_attributes();
  2588.  
  2589. foreach ( $atts as $slug => $att ) {
  2590. $selected_atts[ $slug ] = key( $att['terms'] );
  2591. }
  2592. }
  2593.  
  2594. $return .= $product->buy_button( false, 'single', $selected_atts );
  2595.  
  2596. if ( mp_get_setting( 'show_single_tags' ) == 1 ) {
  2597. $return .= mp_tag_list( $product_id, '<div class="mp_product_tags">' . __( 'Tagged in ', 'mp' ), ', ', '</div>' );
  2598. }
  2599.  
  2600. $return .= '</div><!-- end mp_product_callout-->';
  2601.  
  2602. $return .= '<div class="mp_social_shares">';
  2603. $return .= $pinit;
  2604. $return .= $fb;
  2605. $return .= $twitter;
  2606. $return .= '</div><!-- end mp_social_shares -->';
  2607. }
  2608.  
  2609. if ( $image && ! post_password_required( $post ) ) {
  2610. $return .= '</div><!-- end mp_single_product_details-->';
  2611. }
  2612.  
  2613. if ( ! post_password_required( $post ) ) {
  2614. $return .= '<div class="mp_single_product_extra">';
  2615.  
  2616. if ( ! $display_description && isset( $product->content_tabs['mp-product-overview'] ) ) {
  2617. unset( $product->content_tabs['mp-product-overview'] );
  2618. }
  2619.  
  2620. $return .= $product->content_tab_labels( false );
  2621.  
  2622. $index = 0;
  2623.  
  2624. if ( $display_description ) {
  2625. $return .= '
  2626. <div id="mp-product-overview' . '-' . $product->ID . '" class="mp_product_tab_content mp_product_tab_content-overview mp_product_tab_content-current">';
  2627.  
  2628. $return .= '
  2629. <div itemprop="description" class="mp_product_tab_content_text">';
  2630.  
  2631. if ( $content == 'excerpt' ) {
  2632. $return .= ( $variation ) ? mp_get_the_excerpt( $variation_id, apply_filters( 'mp_get_the_excerpt_length', 18 ), true ) : $product->excerpt();
  2633. } else {
  2634. $product_description = ( ! $product->post_content && $variation ) ? $product->get_variation()->post_content : $product->post_content;
  2635. $return .= apply_filters( 'the_content', $product_description );
  2636. }
  2637.  
  2638. $return .= '
  2639. </div><!-- end mp_product_tab_content_text -->
  2640. </div><!-- end mp-product-overview -->';
  2641. $index ++;
  2642. }
  2643.  
  2644.  
  2645. // Remove overview tab as it's already been manually output above
  2646. unset( $product->content_tabs['mp-product-overview'] );
  2647.  
  2648. $func_args = func_get_args();
  2649. $args = mp_parse_args( $func_args, mp()->defaults['list_products'] );
  2650.  
  2651. foreach ( $product->content_tabs as $slug => $label ) {
  2652. switch ( $slug ) {
  2653. case 'mp-related-products' :
  2654. $view = mp_get_setting( 'related_products->view' );
  2655. if ( mp_get_setting( 'related_products->show' ) ) {
  2656. $layout_type = mp_get_setting( 'list_view' );
  2657. if ( ! is_null( $args['list_view'] ) ) {
  2658. $layout_type = $args['list_view'] ? 'list' : 'grid';
  2659. }
  2660. $return .= '
  2661. <div id="mp-related-products-' . $product->ID . '" class="' . ( ( $index == 0 ) ? 'mp_product_tab_content-current' : '' ) . ' mp-multiple-products mp_product_tab_content mp_product_tab_content-related-products">
  2662. <div class="mp_product_tab_content_products mp_products mp_products-related ' . ( isset( $view ) ? 'mp_products-' . $view : 'mp_products-list' ) . '">' . $product->related_products() . ' </div>
  2663. </div><!-- end mp-related-products -->';
  2664. }
  2665. break;
  2666.  
  2667. default :
  2668. /**
  2669. * Filter the content tab html
  2670. *
  2671. * @since 3.0
  2672. *
  2673. * @param string
  2674. * @param string $slug The tab slug.
  2675. */
  2676. $tab = apply_filters( 'mp_content_tab_html', '', $slug );
  2677.  
  2678. $return .= '
  2679. <div id="' . esc_attr( $slug ) . '-' . $product->ID . '" class="' . ( ( $index == 0 ) ? 'mp_product_tab_content-current' : '' ) . ' mp_product_tab_content mp_product_tab_content-html" style="display:none">
  2680. <div class="mp_product_tab_content_html">' . $tab . '</div><!-- end mp_product_tab_content_html -->
  2681. </div><!-- end ' . esc_attr( $slug ) . ' -->';
  2682. break;
  2683. }
  2684. $index ++;
  2685. }
  2686. $return .= '</div><!-- end mp_single_product_extra -->';
  2687. }
  2688.  
  2689. $return .= '
  2690.  
  2691. </div><!-- end mp_product/mp_single_product -->
  2692. </section><!-- end mp-single-product -->';
  2693.  
  2694. /**
  2695. * Filter the product html
  2696. *
  2697. * @since 3.0
  2698. *
  2699. * @param string $return The current product html.
  2700. * @param int $product ->ID The product's ID.
  2701. * @param bool $title Whether to display the title.
  2702. * @param bool /string $content Whether and what type of content to display. Options are false, 'full', or 'excerpt'. Default 'full'.
  2703. * @param bool /string $image Whether and what context of image size to display. Options are false, 'single', or 'list'. Default 'single'.
  2704. * @param bool $meta Whether to display the product meta.
  2705. */
  2706. $return = apply_filters( 'mp_product', $return, $product->ID, $title, $content, $image, $meta );
  2707.  
  2708. if ( $echo ) {
  2709. echo $return;
  2710. } else {
  2711. return $return;
  2712. }
  2713.  
  2714. }
  2715.  
  2716. }
  2717.  
  2718. if ( ! function_exists( 'mp_product_excerpt' ) ) :
  2719.  
  2720. /**
  2721. * Replaces wp_trim_excerpt in MP custom loops
  2722. *
  2723. * @param string $excerpt
  2724. * @param string $content
  2725. * @param int $product_id
  2726. * @param string $excerpt_more
  2727. *
  2728. * @return string
  2729. */
  2730. function mp_product_excerpt( $excerpt, $content, $product_id, $excerpt_more = null ) {
  2731. _deprecated_function( 'mp_product_excerpt', '3.0', 'MP_Product::excerpt()' );
  2732. $product = new MP_Product( $product_id );
  2733.  
  2734. return $product->excerpt( $excerpt_more, $excerpt, $content );
  2735. }
  2736.  
  2737. endif;
  2738.  
  2739. if ( ! function_exists( 'mp_product_image' ) ) :
  2740. /*
  2741. * Get the product image
  2742. *
  2743. * @param bool $echo Optional, whether to echo
  2744. * @param string $context Options are list, single, or widget
  2745. * @param int $post_id The post_id for the product. Optional if in the loop
  2746. * @param int $size An optional width/height for the image if contect is widget
  2747. * @param string $align The alignment of the image. Defaults to settings.
  2748. */
  2749.  
  2750. function mp_product_image( $echo = true, $context = 'list', $post_id = null, $size = null, $align = null ) {
  2751. _deprecated_function( 'mp_product_image', '3.0', 'MP_Product::image()' );
  2752.  
  2753. $product = new MP_Product( $post_id );
  2754. //$image = MP_Product::image( false, $context, $size, $align );
  2755. $image = $product->image( false, $context, $size, $align );
  2756.  
  2757. if ( $echo ) {
  2758. echo $image;
  2759. } else {
  2760. return $image;
  2761. }
  2762. }
  2763.  
  2764. endif;
  2765.  
  2766. if ( ! function_exists( 'mp_products_nav' ) ) :
  2767.  
  2768. /**
  2769. * Get the current product list/grid navigation
  2770. *
  2771. * @param bool $echo Optional, whether to echo. Defaults to true
  2772. * @param WP_Query object $custom_query
  2773. */
  2774. function mp_products_nav( $echo = true, $custom_query ) {
  2775. $html = '';
  2776.  
  2777. if ( $custom_query->max_num_pages > 1 ) {
  2778. $big = 999999999;
  2779.  
  2780. $html = '
  2781. <nav class="mp_listings_nav">';
  2782.  
  2783. /* $html .= paginate_links( array(
  2784. 'base' => '%_%',
  2785. 'format' => '?paged=%#%',
  2786. 'total' => $custom_query->max_num_pages,
  2787. 'current' => max( 1, $custom_query->get( 'paged' ) ),
  2788. 'prev_text' => __( 'Prev', 'mp' ),
  2789. 'next_text' => __( 'Next', 'mp' ),
  2790. ) ); */
  2791.  
  2792. //echo 'current_page:'.$custom_query->get( 'paged' );
  2793.  
  2794. $html .= paginate_links( array(
  2795. 'base' => '?paged=%#%', //'%_%',
  2796. 'format' => '', //?paged=%#%
  2797. 'total' => $custom_query->max_num_pages,
  2798. 'current' => max( 1, $custom_query->get( 'paged' ) ),
  2799. 'show_all' => false,
  2800. 'prev_next' => true,
  2801. 'prev_text' => __( 'Prev', 'mp' ),
  2802. 'next_text' => __( 'Next', 'mp' ),
  2803. 'add_args' => true,
  2804. 'add_fragment' => '',
  2805. ) );
  2806.  
  2807. $html .= '
  2808. </nav>';
  2809. }
  2810.  
  2811. /**
  2812. * Filter the products nav html
  2813. *
  2814. * @since 3.0
  2815. *
  2816. * @param string $html
  2817. * @param WP_Query $custom_query
  2818. */
  2819. $html = apply_filters( 'mp_products_nav', $html, $custom_query );
  2820.  
  2821. if ( $echo ) {
  2822. echo $html;
  2823. } else {
  2824. return $html;
  2825. }
  2826. }
  2827.  
  2828. endif;
  2829.  
  2830. if ( ! function_exists( 'mp_products_filter' ) ) :
  2831.  
  2832. /**
  2833. * Display product filters
  2834. *
  2835. * @since 3.0
  2836. *
  2837. * @param bool $hidden Are the filters hidden or visible?
  2838. * @param int $per_page The number of posts per page
  2839. * @param WP_Query $query
  2840. *
  2841. * @return string
  2842. */
  2843. function mp_products_filter( $hidden = false, $per_page = null, $query = null ) {
  2844. $default = '-1';
  2845. if ( $query instanceof WP_Query && $query->get( 'taxonomy' ) == 'product_category' ) {
  2846. $term = get_term_by( 'slug', $query->get( 'term' ), $query->get( 'taxonomy' ) );
  2847. $default = $term->term_id;
  2848. } elseif ( 'product_category' == get_query_var( 'taxonomy' ) ) {
  2849. $term = get_queried_object(); //must do this for number tags
  2850. $default = $term->term_id;
  2851. }
  2852.  
  2853. $terms = wp_dropdown_categories( array(
  2854. 'name' => 'product_category',
  2855. 'class' => 'mp_select2',
  2856. 'id' => 'mp-product-category',
  2857. 'taxonomy' => 'product_category',
  2858. 'show_option_none' => __( 'Show All', 'mp' ),
  2859. 'show_count' => 1,
  2860. 'orderby' => 'name',
  2861. 'selected' => $default,
  2862. 'echo' => 0,
  2863. 'hierarchical' => true
  2864. ) );
  2865.  
  2866. if( !isset( $_SESSION ) ){
  2867. $_SESSION = array();
  2868. }
  2869.  
  2870. if ( $query instanceof WP_Query ) {
  2871. $current_order = strtolower( $query->get( 'order_by' ) . '-' . $query->get( 'order' ) );
  2872. } else {
  2873. $current_order = '';
  2874. }
  2875.  
  2876. if ( isset( $_SESSION['mp_product_list_order_by'] ) && isset( $_SESSION['mp_product_list_order'] ) ) {
  2877. $current_order = $_SESSION['mp_product_list_order_by'] . '-' . $_SESSION['mp_product_list_order'];
  2878. }
  2879.  
  2880. $options = array(
  2881. array( '0', '', __( 'Default', 'mp' ) ),
  2882. array( 'date', 'desc', __( 'Release Date (Latest to Oldest)', 'mp' ) ),
  2883. array( 'date', 'asc', __( 'Release Date (Oldest to Latest)', 'mp' ) ),
  2884. array( 'title', 'asc', __( 'Name (A-Z)', 'mp' ) ),
  2885. array( 'title', 'desc', __( 'Name (Z-A)', 'mp' ) ),
  2886. array( 'price', 'asc', __( 'Price (Low to High)', 'mp' ) ),
  2887. array( 'price', 'desc', __( 'Price (High to Low)', 'mp' ) ),
  2888. array( 'sales', 'desc', __( 'Popularity (Most Popular - Least Popular)', 'mp' ) ),
  2889. array( 'sales', 'asc', __( 'Popularity (Least Popular - Most Popular)', 'mp' ) )
  2890. );
  2891.  
  2892. $options_html = '';
  2893. foreach ( $options as $k => $t ) {
  2894. $value = $t[0] . '-' . $t [1];
  2895. $options_html .= '<option value="' . $value . '" ' . selected( $value, $current_order, false ) . '>' . $t[2] . '</option>';
  2896. }
  2897.  
  2898.  
  2899. $return = '
  2900. <a id="mp-product-top"></a>
  2901. <!-- Products Filter -->
  2902. <section class="mp_products_filter">
  2903. <form id="mp-products-filter-form" name="mp_products_filter_form" class="mp_form mp_form-products-filter" method="get">
  2904.  
  2905. <div class="mp_form_fields">
  2906. <div class="mp_form_field mp_products_filter_field mp_products_filter_category" data-placeholder="' . __( 'Product Category', 'mp' ) . '">
  2907. <label for="mp_product_category" class="mp_form_label">' . __( 'Category', 'mp' ) . '</label>
  2908. ' . $terms . '
  2909. </div><!-- mp_listing_products_category -->
  2910.  
  2911. <div class="mp_form_field mp_products_filter_field mp_products_filter_orderby">
  2912. <label for="mp_sort_orderby" class="mp_form_label">' . __( 'Order By', 'mp' ) . '</label>
  2913. <select id="mp_sort_orderby" class="mp_select2" name="order">
  2914. ' . $options_html . '
  2915. </select>
  2916. </div><!-- mp_products_filter_orderby -->
  2917. </div>
  2918.  
  2919. ' . ( ( is_null( $per_page ) ) ? '' : '<input type="hidden" name="per_page" value="' . $per_page . '">' ) . '
  2920. <input type="hidden" name="page" value="' . max( get_query_var( 'paged' ), 1 ) . '">
  2921.  
  2922. </form><!-- mp_products_filter_form -->
  2923. </section><!-- end mp_products_filter -->
  2924. ';
  2925.  
  2926. return apply_filters( 'mp_products_filter', $return );
  2927.  
  2928.  
  2929. }
  2930.  
  2931. endif;
  2932.  
  2933. if ( ! function_exists( 'mp_province_field' ) ) :
  2934. /*
  2935. * Display state/province dropdown field
  2936. *
  2937. * @param string $country two-digit country code
  2938. * @param string $selected state code form value to be shown/selected
  2939. */
  2940.  
  2941. function mp_province_field( $country = 'US', $selected = null ) {
  2942. _deprecated_function( 'mp_province_field', '3.0', 'MP_Checkout::province_field' );
  2943. }
  2944.  
  2945. endif;
  2946.  
  2947. if ( ! function_exists( 'mp_related_products' ) ) :
  2948.  
  2949. /**
  2950. * Get related products
  2951. *
  2952. * @since 3.0
  2953. *
  2954. * @param int $product_id .
  2955. * @param string $relate_by Optional, how to relate the products - either by category, tag, or both.
  2956. * @param bool $echo Echo or return.
  2957. * @param int $limit . Optional The number of products we want to retrieve.
  2958. * @param bool $simple_list Optional, whether to show the related products based on the "list_view" setting or as a simple unordered list.
  2959. */
  2960. function mp_related_products() {
  2961. _deprecated_function( 'mp_related_products', '3.0', 'MP_Product::related_products()' );
  2962.  
  2963. $defaults = array(
  2964. 'product_id' => null,
  2965. 'echo' => false,
  2966. 'relate_by' => mp_get_setting( 'related_products->relate_by' ),
  2967. 'limit' => mp_get_setting( 'related_products->show_limit' ),
  2968. 'simple_list' => mp_get_setting( 'related_products->simple_list' ),
  2969. );
  2970. $args = array_replace_recursive( $defaults, array_combine( array_keys( $defaults ), func_get_args() ) );
  2971. $html = '';
  2972.  
  2973. if ( ! is_null( $args['product_id'] ) ) {
  2974. $product = new MP_Product( $args['product_id'] );
  2975.  
  2976. if ( $product->exists() ) {
  2977. $args['echo'] = false;
  2978. $html .= $product->related_products( $args );
  2979. }
  2980. }
  2981.  
  2982. if ( $args['echo'] ) {
  2983. echo $html;
  2984. } else {
  2985. return $html;
  2986. }
  2987. }
  2988.  
  2989. endif;
  2990.  
  2991. if ( ! function_exists( 'mp_get_store_email' ) ) :
  2992.  
  2993. /**
  2994. * Get the store admin email address
  2995. *
  2996. * @since 3.0
  2997. * @return string
  2998. */
  2999. function mp_get_store_email() {
  3000. return ( $email = mp_get_setting( 'store_email' ) ) ? $email : get_option( 'admin_email' );
  3001. }
  3002.  
  3003. endif;
  3004.  
  3005. if ( ! function_exists( 'mp_send_email' ) ) :
  3006.  
  3007. /**
  3008. * Send an email
  3009. *
  3010. * @since 3.0
  3011. *
  3012. * @param string $email The email address to send to.
  3013. * @param string $subject The subject of the email.
  3014. * @param string $msg The email message.
  3015. * @param array $attachments
  3016. *
  3017. * @return bool
  3018. */
  3019. function mp_send_email( $email, $subject, $msg, $attachments = array() ) {
  3020. return MP_Mailer::get_instance()->send( $email, $subject, $msg, $attachments );
  3021. }
  3022.  
  3023. endif;
  3024.  
  3025. function mp_get_the_excerpt( $id = false, $length = 55, $variation = false ) {
  3026. global $post;
  3027.  
  3028. if ( empty( $post ) ) {
  3029. $post = new StdClass;
  3030. $post->ID = 0;
  3031. $post->post_excerpt = '';
  3032. $post->post_content = '';
  3033. }
  3034.  
  3035. $old_post = $post;
  3036.  
  3037. if ( $id != $post->ID ) {
  3038. $post = get_page( $id );
  3039. }
  3040.  
  3041. $excerpt = trim( $post->post_excerpt );
  3042.  
  3043. if ( ! $excerpt ) {
  3044. $excerpt = $post->post_content;
  3045. }
  3046.  
  3047. if ( $variation ) {
  3048. $parent_post_id = wp_get_post_parent_id( $id );
  3049. $parent_post = get_post( $parent_post_id );
  3050. if ( ! empty( $parent_post->post_excerpt ) ) {
  3051. $excerpt = $parent_post->post_excerpt;
  3052. } else {
  3053. $excerpt = $parent_post->post_content;
  3054. }
  3055. }
  3056.  
  3057. $excerpt = strip_shortcodes( $excerpt );
  3058. //$excerpt = apply_filters( 'the_content', $excerpt );
  3059. $excerpt = str_replace( ']]>', ']]&gt;', $excerpt );
  3060. $excerpt = strip_tags( $excerpt );
  3061. $excerpt_length = apply_filters( 'excerpt_length', $length );
  3062. //update from excerpt_more to mp_excerpt more, as the behavior of product except does'nt exactl
  3063. $excerpt_more = apply_filters( 'mp_excerpt_more', '...' );
  3064.  
  3065. $words = preg_split( "/[\n\r\t ]+/", $excerpt, $excerpt_length + 1, PREG_SPLIT_NO_EMPTY );
  3066. if ( count( $words ) > $excerpt_length ) {
  3067. array_pop( $words );
  3068. $excerpt = implode( ' ', $words );
  3069. $excerpt = $excerpt . $excerpt_more;
  3070. } else {
  3071. $excerpt = implode( ' ', $words );
  3072. }
  3073.  
  3074. $post = $old_post;
  3075.  
  3076. return apply_filters( 'the_excerpt', $excerpt );
  3077. }
  3078.  
  3079. function mp_all_countries_allowed() {
  3080. if ( is_array( mp_get_setting( 'shipping->allowed_countries', '' ) ) ) {
  3081. $allowed_countries = mp_get_setting( 'shipping->allowed_countries', '' );
  3082. } else {
  3083. $allowed_countries = explode( ',', mp_get_setting( 'shipping->allowed_countries', '' ) );
  3084. }
  3085. $key = array_search( 'all_countries', $allowed_countries );
  3086. if ( is_numeric( $key ) ) {
  3087. return true;
  3088. } else {
  3089. return false;
  3090. }
  3091. }
  3092.  
  3093. if ( ! function_exists( 'mp_show_cart' ) ) {
  3094. /**
  3095. * @param string $context
  3096. * @param null $checkoutstep
  3097. * @param bool|true $echo
  3098. *
  3099. * @return string
  3100. */
  3101. function mp_show_cart( $context = '', $checkoutstep = null, $echo = true ) {
  3102. $content = '';
  3103.  
  3104. if ( get_the_ID() == mp_get_setting( 'pages->checkout' ) && $context != 'widget' ) {
  3105. $content = MP_Checkout::get_instance()->display( array(
  3106. 'echo' => false
  3107. ) );
  3108. } elseif ( get_the_ID() == mp_get_setting( 'pages->cart' ) ) {
  3109. $content = MP_Cart::get_instance()->display( array(
  3110. 'echo' => false
  3111. ) );
  3112. }
  3113.  
  3114. if ( $echo ) {
  3115. echo $content;
  3116. } else {
  3117. return $content;
  3118. }
  3119. }
  3120. }
  3121.  
  3122. if ( ! function_exists( 'mp_items_in_cart' ) ) :
  3123. /**
  3124. * Determine if there are any items in the cart
  3125. *
  3126. * @retuns bool whether items are in the cart for the current user.
  3127. */
  3128. function mp_items_in_cart() {
  3129. if ( mp_items_count_in_cart() ) {
  3130. return true;
  3131. } else {
  3132. return false;
  3133. }
  3134. }
  3135. endif;
  3136.  
  3137. if ( ! function_exists( 'mp_items_count_in_cart' ) ) :
  3138. /**
  3139. * Determine count of any items in the cart
  3140. *
  3141. * @retuns int number of items that are in the cart for the current user.
  3142. */
  3143. function mp_items_count_in_cart() {
  3144. return mp_cart()->item_count( false, false );
  3145. }
  3146. endif;
  3147.  
  3148. if ( ! function_exists( 'mp_category_list' ) ) :
  3149. /**
  3150. * Retrieve product's category list in either HTML list or custom format.
  3151. *
  3152. * @param int $product_id Optional. Post ID to retrieve categories.
  3153. * @param string $before Optional. Before list.
  3154. * @param string $sep Optional. Separate items using this.
  3155. * @param string $after Optional. After list.
  3156. */
  3157. function mp_category_list( $product_id = false, $before = '', $sep = ', ', $after = '' ) {
  3158. $terms = get_the_term_list( $product_id, 'product_category', $before, $sep, $after );
  3159. if ( $terms ) {
  3160. return $terms;
  3161. } else {
  3162. $return = __( 'Uncategorized', 'mp' );
  3163. }
  3164.  
  3165. return apply_filters( 'mp_category_list', $return, $product_id, $before, $sep, $after );
  3166. }
  3167. endif;
  3168.  
  3169.  
  3170. if ( ! function_exists( 'mp_tag_list' ) ) :
  3171. /**
  3172. * Retrieve product's tag list in either HTML list or custom format.
  3173. *
  3174. * @param int $product_id Optional. Post ID to retrieve categories.
  3175. * @param string $before Optional. Before list.
  3176. * @param string $sep Optional. Separate items using this.
  3177. * @param string $after Optional. After list.
  3178. */
  3179. function mp_tag_list( $product_id = false, $before = '', $sep = ', ', $after = '' ) {
  3180. $return = '';
  3181. $terms = get_the_term_list( $product_id, 'product_tag', $before, $sep, $after );
  3182. if ( $terms ) {
  3183. return $terms;
  3184. }
  3185.  
  3186. return apply_filters( 'mp_tag_list', $return, $product_id, $before, $sep, $after );
  3187. }
  3188. endif;
  3189.  
  3190. if ( ! function_exists( 'mp_get_plugin_slug' ) ) {
  3191. function mp_get_plugin_slug() {
  3192. if ( file_exists( dirname( __FILE__ ) . '/includes/admin/dash-notice/wpmudev-dash-notification.php' ) ) {
  3193. return 'marketpress/marketpress.php';
  3194. } else {
  3195. return 'wordpress-ecommerce/marketpress.php';
  3196. }
  3197. }
  3198. }
  3199.  
  3200. if ( ! function_exists( 'mp_product_title' ) ) :
  3201. /*
  3202. * function mp_product_title
  3203. * Displays a title of a single product according to preference
  3204. *
  3205. * @param bool $echo Optional, whether to echo or return
  3206. * @param int $product_id the ID of the product to display
  3207. * @param bool $link Whether to display title with or without a link
  3208. * @param bool $formated Whether to display formated text (i.e h3 with a class) or not (just pure text)
  3209. * @param string $html_tag title surrounding HTML tag (i.e. <h3>title</h3>)
  3210. * @param string $css_class add custom css class to the title
  3211. * @param string $microdata add additional information to HTML content which is more descriptive and suitable for search engines (learn more here http://schema.org/docs/gs.html)
  3212. */
  3213.  
  3214. function mp_product_title( $product_id, $echo = true, $link = false, $formated = true, $html_tag = 'h3', $css_class = 'mp_product_name', $microdata = 'itemprop="name"' ) {
  3215. global $mp;
  3216.  
  3217. $post = get_post( $product_id );
  3218.  
  3219. if ( $link ) {
  3220. $title = '<a href="' . get_permalink( $post->ID ) . '">' . $post->post_title . '</a>';
  3221. } else {
  3222. $title = $post->post_title;
  3223. }
  3224.  
  3225. if ( $formated ) {
  3226. $before_title = '<' . $html_tag . ' ' . $microdata . ' class="entry-title ' . $css_class . '">';
  3227. $after_title = '</' . $html_tag . '>';
  3228. } else {
  3229. $before_title = '<span class="entry-title">';
  3230. $after_title = '</span>';
  3231. }
  3232.  
  3233. $return = apply_filters( 'mp_product_title', $before_title . $title . $after_title, $product_id, $link, $formated, $html_tag, $css_class, $microdata );
  3234.  
  3235. if ( $echo ) {
  3236. echo $return;
  3237. } else {
  3238. return $return;
  3239. }
  3240. }
  3241. endif;
  3242.  
  3243.  
  3244. if ( ! function_exists( 'mp_product_description' ) ) :
  3245. /*
  3246. * function mp_product_description
  3247. * Displays a title of a single product according to preference
  3248. *
  3249. * @param bool $echo Optional, whether to echo or return
  3250. * @param int $product_id the ID of the product to display
  3251. * @param bool/string $content Whether and what type of content to display. Options are false, 'full', or 'excerpt'. Default 'full'
  3252. * @param string $html_tag title surrounding HTML tag (i.e. <div>title</div>)
  3253. * @param string $css_class add custom css class to the description
  3254. * @param string $microdata add additional information to HTML content which is more descriptive and suitable for search engines (learn more here http://schema.org/docs/gs.html)
  3255. */
  3256.  
  3257. function mp_product_description( $product_id, $echo = true, $content = 'full', $html_tag = true, $css_class = 'mp_product_content', $microdata = 'itemprop="description"' ) {
  3258. global $mp;
  3259.  
  3260. $post = get_post( $product_id );
  3261. $description = '';
  3262.  
  3263. if ( $content == 'excerpt' ) {
  3264. $description .= $post->post_excerpt;
  3265. } else {
  3266. $description .= apply_filters( 'the_content', $post->post_content );
  3267. }
  3268.  
  3269. if ( $html_tag ) {
  3270. $before_description = '<div ' . $microdata . ' class="' . $css_class . '">';
  3271. $after_description = '</div>';
  3272. } else {
  3273. $before_description = '';
  3274. $after_description = '';
  3275. }
  3276.  
  3277. $return = apply_filters( 'mp_product_description', $before_description . $description . $after_description, $product_id, $content, $html_tag, $css_class, $microdata );
  3278.  
  3279. if ( $echo ) {
  3280. echo $return;
  3281. } else {
  3282. return $return;
  3283. }
  3284. }
  3285. endif;
  3286.  
  3287.  
  3288. if ( ! function_exists( 'mp_product_meta' ) ) :
  3289. /*
  3290. * function mp_product_meta
  3291. * Displays the product meta box
  3292. *
  3293. * @param bool $echo Optional, whether to echo or return
  3294. * @param string $context Options are list or single
  3295. * @param int $product_id The post_id for the product. Optional if in the loop
  3296. * @param sting $label A label to prepend to the price. Defaults to "Price: "
  3297. * @param string $html_tag title surrounding HTML tag (i.e. <div>title</div>)
  3298. * @param string $css_class add custom css class to the description
  3299. */
  3300.  
  3301. function mp_product_meta( $echo = true, $context = 'context', $label = true, $product_id = null, $html_tag = true, $css_class = 'mp_product_meta' ) {
  3302.  
  3303. if ( $html_tag ) {
  3304. $content = '<div class="' . $css_class . '">';
  3305. }
  3306. $content .= mp_product_price( false, $product_id, $label );
  3307. $content .= mp_buy_button( false, $context, $product_id );
  3308. if ( $html_tag ) {
  3309. $content .= '</div>';
  3310. }
  3311.  
  3312. $content = apply_filters( 'mp_product_meta', $content, $context, $label, $product_id, $html_tag, $css_class );
  3313.  
  3314. if ( $echo ) {
  3315. echo $content;
  3316. } else {
  3317. return $content;
  3318. }
  3319. }
  3320. endif;
  3321.  
  3322. if ( ! function_exists( 'mp_get_ajax_url' ) ) {
  3323. function mp_get_ajax_url( $path = 'admin-ajax.php' ) {
  3324. $ajax_url = admin_url( $path );
  3325. if ( ! is_ssl() && force_ssl_admin() ) {
  3326. //this case the frontend is non ssl, meanwhile backend is ssl, and that will make the cookies
  3327. //wrong, need to fix it
  3328. $ajax_url = admin_url( $path, 'http' );
  3329. }
  3330.  
  3331. if( defined( 'DOMAINMAP_BASEFILE' ) ) {
  3332. global $wpdb;
  3333. $blog_id = get_current_blog_id();
  3334.  
  3335. switch_to_blog(1);
  3336. $domain = $wpdb->get_var( $wpdb->prepare(
  3337. "SELECT domain from {$wpdb->prefix}domain_mapping WHERE blog_id = %d",
  3338. absint( $blog_id )
  3339. ));
  3340. restore_current_blog();
  3341.  
  3342. $schema = is_ssl() ? 'https://' : 'http://';
  3343. if( is_ssl() && force_ssl_admin() ) {
  3344. $schema = 'http://';
  3345. }
  3346. $ajax_url = $schema . $domain . '/wp-admin/' . $path;
  3347. }
  3348.  
  3349. return $ajax_url;
  3350. }
  3351. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement