function mp_product($echo = true, $product_id, $title = true, $content = 'full', $image = 'single', $meta = true) { global $mp; if (function_exists('icl_object_id')) { $product_id = icl_object_id($product_id, 'product', false); } $post = get_post($product_id); $return = '<div itemscope itemtype="http://schema.org/Product" ' . mp_product_class(false, 'mp_product', $post->ID) . '>'; $return .= '<span style="display:none" class="date updated">' . get_the_time($product_id) . '</span>'; if ($title) { $return .= '<h3 itemprop="name" class="mp_product_name entry-title"><a href="' . get_permalink($post->ID) . '">' . $post->post_title . '</a></h3>'; } if ($content) { $return .= '<div itemprop="description" class="mp_product_content">'; if ($image) { $return .= mp_product_image(false, $image, $post->ID); } if ($content == 'excerpt') { $return .= $mp->product_excerpt($post->post_excerpt, $post->post_content, $post->ID); } else { $return .= apply_filters('the_content', $post->post_content); } $return .= '</div>'; } if ($meta) { //price $return .= mp_product_price(false, $post->ID); //button $return .= mp_buy_button(false, 'single', $post->ID); } $return .= '</div>'; $return = apply_filters('mp_product', $return, $product_id, $title, $content, $image, $meta); if ($echo) { echo $return; } else { return $return; } }
/** * Displays the product featured image * * @param string $context Options are list, single, or widget * @param int $product_id The post_id for the product. Optional if in the loop * @param int $size An optional width/height for the image if contect is widget */ function mp_product_image_sc($atts) { extract(shortcode_atts(array('context' => 'single', 'product_id' => NULL, 'size' => NULL), $atts)); return mp_product_image(false, $context, $product_id, $size); }
function widget($args, $instance) { global $mp; if ($instance['only_store_pages'] && !mp_is_shop_page()) { return; } extract($args); echo $before_widget; $title = $instance['title']; if (!empty($title)) { echo $before_title . apply_filters('widget_title', $title) . $after_title; } if (!empty($instance['custom_text'])) { echo '<div id="custom_text">' . $instance['custom_text'] . '</div>'; } /* setup our custom query */ //setup taxonomy if applicable if ($instance['taxonomy_type'] == 'category') { $taxonomy_query = '&product_category=' . $instance['taxonomy']; } else { if ($instance['taxonomy_type'] == 'tag') { $taxonomy_query = '&product_tag=' . $instance['taxonomy']; } else { $taxonomy_query = ''; } } //figure out perpage if (isset($instance['num_products']) && intval($instance['num_products']) > 0) { $paginate_query = '&posts_per_page=' . intval($instance['num_products']) . '&paged=1'; } else { $paginate_query = '&posts_per_page=10&paged=1'; } //get order by if ($instance['order_by']) { if ($instance['order_by'] == 'price') { $order_by_query = '&meta_key=mp_price&orderby=meta_value_num'; } else { if ($instance['order_by'] == 'sales') { $order_by_query = '&meta_key=mp_sales_count&orderby=meta_value_num'; } else { $order_by_query = '&orderby=' . $instance['order_by']; } } } else { $order_by_query = '&orderby=title'; } //get order direction if ($instance['order']) { $order_query = '&order=' . $instance['order']; } else { $order_query = '&orderby=DESC'; } //The Query $custom_query = new WP_Query('post_type=product' . $taxonomy_query . $paginate_query . $order_by_query . $order_query); //do we have products? if (count($custom_query->posts)) { echo '<ul id="mp_product_list" class="">'; foreach ($custom_query->posts as $post) { $btnclass = mpt_load_mp_btn_color(); echo '<li ' . mp_product_class(false, 'mp_product', $post->ID) . '>'; echo '<div class="row-fluid">'; if ($instance['show_thumbnail']) { echo '<div class="span4">'; mp_product_image(true, 'widget', $post->ID, $instance['size']); echo '</div>'; echo '<div class="span8">'; } else { echo '<div class="span12">'; } echo '<p class="mp_product_name"><a href="' . get_permalink($post->ID) . '">' . esc_attr($post->post_title) . '</a></p>'; if ($instance['show_excerpt']) { echo '<div class="mp_product_content">' . $mp->product_excerpt($post->post_excerpt, $post->post_content, $post->ID) . '</div>'; } if ($instance['show_price'] || $instance['show_button']) { echo '<div class="mp_product_meta' . ($instance['show_excerpt'] ? ' align-right' : '') . '">'; if ($instance['show_price']) { echo flexmarket_product_price(false, $post->ID, '', '', 'widget'); } if ($instance['show_button']) { echo flexmarket_buy_button(false, 'list', $post->ID, $btnclass . ' btn-small'); } echo '</div>'; } echo '</div>'; //End span echo '</div>'; // End Row-fluid echo '</li>'; } echo '</ul>'; } else { ?> <div class="widget-error"> <?php _e('No Products', 'mp'); ?> </div> <?php } echo $after_widget; }
function _mp_global_products_html_grid($results, $args) { global $mp, $post; $html = ''; $inline_style = !($mp->get_setting('store_theme') == 'none' || current_theme_supports('mp_style')); $current_blog_id = get_current_blog_id(); $current_post = $post; //thumbnail width $width = (double) $args['thumbnail_size']; foreach ($results as $index => $result) { switch_to_blog($result->blog_id); $post = get_post($result->post_id); setup_postdata($post); $img = mp_product_image(false, 'list', $post->ID, $args['thumbnail_size']); $excerpt = ''; if ($args['text'] == 'excerpt') { $excerpt = '<p class="mp_excerpt">' . $mp->product_excerpt($post->post_excerpt, $post->post_content, $post->ID, '') . '</p>'; } elseif ($args['text'] == 'content') { $excerpt = get_the_content(); } $mp_product_list_content = apply_filters('mp_product_list_content', $excerpt, $post->ID); $pinit = mp_pinit_button($post->ID, 'all_view'); $class = array(); $class[] = strlen($img) > 0 ? 'mp_thumbnail' : ''; $class[] = strlen($excerpt) > 0 ? 'mp_excerpt' : ''; $class[] = mp_has_variations($post->ID) ? 'mp_price_variations' : ''; $html .= ' <div itemscope itemtype="http://schema.org/Product" class="hentry mp_one_tile ' . implode($class, ' ') . '"> <div class="mp_one_product"' . ($inline_style ? ' style="width: ' . $width . 'px;"' : '') . '> <div class="mp_product_detail"' . ($inline_style ? ' style="width: ' . $width . 'px;"' : '') . '> ' . $img . ' ' . $pinit . ' <h3 class="mp_product_name entry-title"> <a href="' . get_permalink($post->ID) . '">' . $post->post_title . '</a> </h3> <div>' . $mp_product_list_content . '</div> </div> <div class="mp_price_buy"' . ($inline_style ? ' style="width: ' . $width . 'px;"' : '') . '> ' . ($args['show_price'] ? mp_product_price(false, $post->ID) : '') . ' <a class="mp_link_buynow" href="' . get_permalink($post->ID) . '">' . __('Buy Now »', 'mp') . '</a> ' . apply_filters('mp_product_list_meta', '', $post->ID) . ' </div> <div style="display:none" > <span class="entry-title">' . get_the_title() . '</span> was last modified: <time class="updated">' . get_the_time('Y-m-d\\TG:i') . '</time> by <span class="author vcard"><span class="fn">' . get_the_author_meta('display_name') . '</span></span> </div> </div> </div>'; } $html .= count($results) > 0 ? '<div class="clear"></div>' : ''; $post = $current_post; //wp_reset_postdata() doesn't work here switch_to_blog($current_blog_id); return apply_filters('_mp_global_products_html_grid', $html, $results); }
function mp_list_products($echo = true, $paginate = '', $page = '', $per_page = '', $order_by = '', $order = '', $category = '', $tag = '') { global $wp_query, $mp; $settings = get_option('mp_settings'); //setup taxonomy if applicable if ($category) { $taxonomy_query = '&product_category=' . sanitize_title($category); } else { if ($tag) { $taxonomy_query = '&product_tag=' . sanitize_title($tag); } else { if ($wp_query->query_vars['taxonomy'] == 'product_category' || $wp_query->query_vars['taxonomy'] == 'product_tag') { $taxonomy_query = '&' . $wp_query->query_vars['taxonomy'] . '=' . get_query_var($wp_query->query_vars['taxonomy']); } } } //setup pagination $paged = false; if ($paginate) { $paged = true; } else { if ($paginate === '') { if ($settings['paginate']) { $paged = true; } else { $paginate_query = '&nopaging=true'; } } else { $paginate_query = '&nopaging=true'; } } //get page details if ($paged) { //figure out perpage if (intval($per_page)) { $paginate_query = '&posts_per_page=' . intval($per_page); } else { $paginate_query = '&posts_per_page=' . $settings['per_page']; } //figure out page if ($wp_query->query_vars['paged']) { $paginate_query .= '&paged=' . intval($wp_query->query_vars['paged']); } if (intval($page)) { $paginate_query .= '&paged=' . intval($page); } else { if ($wp_query->query_vars['paged']) { $paginate_query .= '&paged=' . intval($wp_query->query_vars['paged']); } } } //get order by if (!$order_by) { if ($settings['order_by'] == 'price') { $order_by_query = '&meta_key=mp_price_sort&orderby=meta_value_num'; } else { if ($settings['order_by'] == 'sales') { $order_by_query = '&meta_key=mp_sales_count&orderby=meta_value_num'; } else { $order_by_query = '&orderby=' . $settings['order_by']; } } } else { if ('price' == $order_by) { $order_by_query = '&meta_key=mp_price_sort&orderby=meta_value_num'; } else { $order_by_query = '&orderby=' . $order_by; } } //get order direction if (!$order) { $order_query = '&order=' . $settings['order']; } else { $order_query = '&order=' . $order; } //The Query $custom_query = new WP_Query('post_type=product&post_status=publish' . $taxonomy_query . $paginate_query . $order_by_query . $order_query); //allows pagination links to work get_posts_nav_link() if ($wp_query->max_num_pages == 0 || $taxonomy_query) { $wp_query->max_num_pages = $custom_query->max_num_pages; } $content = '<div id="mp_product_list">'; if ($last = count($custom_query->posts)) { $count = 1; foreach ($custom_query->posts as $post) { //add last css class for styling grids if ($count == $last) { $class = array('mp_product', 'last-product'); } else { $class = 'mp_product'; } $content .= '<div ' . mp_product_class(false, $class, $post->ID) . '>'; $content .= '<h3 class="mp_product_name"><a href="' . get_permalink($post->ID) . '">' . $post->post_title . '</a></h3>'; $content .= '<div class="mp_product_content">'; $product_content = mp_product_image(false, 'list', $post->ID); if ($settings['show_excerpt'] == 1) { $product_content .= $mp->product_excerpt($post->post_excerpt, $post->post_content, $post->ID); } $content .= apply_filters('mp_product_list_content', $product_content, $post->ID); $content .= '</div>'; $content .= '<div class="mp_product_meta">'; //price $meta = mp_product_price(false, $post->ID); //button $meta .= mp_buy_button(false, 'list', $post->ID); $content .= apply_filters('mp_product_list_meta', $meta, $post->ID); $content .= '</div>'; $content .= '</div>'; $count++; } } else { $content .= '<div id="mp_no_products">' . apply_filters('mp_product_list_none', __('No Products', 'mp')) . '</div>'; } $content .= '</div>'; if ($echo) { echo $content; } else { return $content; } }
function framemarket_mp_order_status() { global $mp, $wp_query; $settings = get_option('mp_settings'); echo $settings['msg']['order_status']; $order_id = $wp_query->query_vars['order_id'] ? $wp_query->query_vars['order_id'] : $_GET['order_id']; if (!empty($order_id)) { //get order $order = $mp->get_order($order_id); if ($order) { //valid order echo '<hr/><h2><em>' . sprintf(__('Order Details (%s):', 'mp'), htmlentities($order_id)) . '</em></h2>'; ?> <h3><?php _e('Current Status', 'mp'); ?> </h3> <ul> <?php //get times $received = date(get_option('date_format') . ' - ' . get_option('time_format'), $order->mp_received_time); if ($order->mp_paid_time) { $paid = date(get_option('date_format') . ' - ' . get_option('time_format'), $order->mp_paid_time); } if ($order->mp_shipped_time) { $shipped = date(get_option('date_format') . ' - ' . get_option('time_format'), $order->mp_shipped_time); } if ($order->post_status == 'order_received') { echo '<li>' . __('Received:', 'mp') . ' <strong>' . $received . '</strong></li>'; } else { if ($order->post_status == 'order_paid') { echo '<li>' . __('Paid:', 'mp') . ' <strong>' . $paid . '</strong></li>'; echo '<li>' . __('Received:', 'mp') . ' <strong>' . $received . '</strong></li>'; } else { if ($order->post_status == 'order_shipped' || $order->post_status == 'order_closed') { echo '<li>' . __('Shipped:', 'mp') . ' <strong>' . $shipped . '</strong></li>'; echo '<li>' . __('Paid:', 'mp') . ' <strong>' . $paid . '</strong></li>'; echo '<li>' . __('Received:', 'mp') . ' <strong>' . $received . '</strong></li>'; } } } $order_paid = $order->post_status != 'order_received'; $max_downloads = intval($settings['max_downloads']) ? intval($settings['max_downloads']) : 5; ?> </ul> <hr/> <h3><?php _e('Payment Information:', 'mp'); ?> </h3> <ul> <li> <?php _e('Payment Method:', 'mp'); ?> <strong><?php echo $order->mp_payment_info['gateway_public_name']; ?> </strong> </li> <li> <?php _e('Payment Type:', 'mp'); ?> <strong><?php echo $order->mp_payment_info['method']; ?> </strong> </li> <li> <?php _e('Transaction ID:', 'mp'); ?> <strong><?php echo $order->mp_payment_info['transaction_id']; ?> </strong> </li> <li> <?php _e('Payment Total:', 'mp'); ?> <strong><?php echo $mp->format_currency($order->mp_payment_info['currency'], $order->mp_payment_info['total']) . ' ' . $order->mp_payment_info['currency']; ?> </strong> </li> </ul> <hr/> <h3><?php _e('Order Information:', 'mp'); ?> </h3> <table id="mp-order-product-table" class="mp_cart_contents"> <thead><tr> <th class="mp_cart_col_thumb"> </th> <th class="mp_cart_col_product"><?php _e('Item', 'mp'); ?> </th> <th class="mp_cart_col_quant"><?php _e('Quantity', 'mp'); ?> </th> <th class="mp_cart_col_price"><?php _e('Price', 'mp'); ?> </th> <th class="mp_cart_col_subtotal"><?php _e('Subtotal', 'mp'); ?> </th> <th class="mp_cart_col_downloads"><?php _e('Download', 'mp'); ?> </th> </tr></thead> <tbody> <?php if (is_array($order->mp_cart_info) && count($order->mp_cart_info)) { foreach ($order->mp_cart_info as $product_id => $variations) { //for compatibility for old orders from MP 1.x if (isset($variations['name'])) { $data = $variations; echo '<tr>'; echo ' <td class="mp_cart_col_thumb">' . mp_product_image(false, 'widget', $product_id) . '</td>'; echo ' <td class="mp_cart_col_product"><a href="' . get_permalink($product_id) . '">' . esc_attr($data['name']) . '</a></td>'; echo ' <td class="mp_cart_col_quant">' . number_format_i18n($data['quantity']) . '</td>'; echo ' <td class="mp_cart_col_price">' . $mp->format_currency('', $data['price']) . '</td>'; echo ' <td class="mp_cart_col_subtotal">' . $mp->format_currency('', $data['price'] * $data['quantity']) . '</td>'; echo ' <td class="mp_cart_col_downloads"></td>'; echo '</tr>'; } else { foreach ($variations as $variation => $data) { echo '<tr>'; echo ' <td class="mp_cart_col_thumb">' . mp_product_image(false, 'widget', $product_id) . '</td>'; echo ' <td class="mp_cart_col_product"><a href="' . get_permalink($product_id) . '">' . esc_attr($data['name']) . '</a></td>'; echo ' <td class="mp_cart_col_quant">' . number_format_i18n($data['quantity']) . '</td>'; echo ' <td class="mp_cart_col_price">' . $mp->format_currency('', $data['price']) . '</td>'; echo ' <td class="mp_cart_col_subtotal">' . $mp->format_currency('', $data['price'] * $data['quantity']) . '</td>'; if (is_array($data['download']) && ($download_url = $mp->get_download_url($product_id, $order->post_title))) { if ($order_paid) { //check for too many downloads if (intval($data['download']['downloaded']) < $max_downloads) { echo ' <td class="mp_cart_col_downloads"><a href="' . $download_url . '">' . __('Download»', 'mp') . '</a></td>'; } else { echo ' <td class="mp_cart_col_downloads">' . __('Limit Reached', 'mp') . '</td>'; } } else { echo ' <td class="mp_cart_col_downloads">' . __('Awaiting Payment', 'mp') . '</td>'; } } else { echo ' <td class="mp_cart_col_downloads"></td>'; } echo '</tr>'; } } } } else { echo '<tr><td colspan="6">' . __('No products could be found for this order', 'mp') . '</td></tr>'; } ?> </tbody> </table> <ul> <?php //coupon line if ($order->mp_discount_info) { ?> <li><?php _e('Coupon Discount:', 'mp'); ?> <strong><?php echo $order->mp_discount_info['discount']; ?> </strong></li> <?php } ?> <?php //shipping line if ($order->mp_shipping_total) { ?> <li><?php _e('Shipping:', 'mp'); ?> <strong><?php echo $mp->format_currency('', $order->mp_shipping_total); ?> </strong></li> <?php } ?> <?php //tax line if ($order->mp_tax_total) { ?> <li><?php _e('Taxes:', 'mp'); ?> <strong><?php echo $mp->format_currency('', $order->mp_tax_total); ?> </strong></li> <?php } ?> <li><?php _e('Order Total:', 'mp'); ?> <strong><?php echo $mp->format_currency('', $order->mp_order_total); ?> </strong></li> </ul> <hr/> <h3><?php _e('Shipping Information:', 'mp'); ?> </h3> <table> <tr> <td align="right"><?php _e('Full Name:', 'mp'); ?> </td><td> <?php echo esc_attr($order->mp_shipping_info['name']); ?> </td> </tr> <tr> <td align="right"><?php _e('Address:', 'mp'); ?> </td> <td><?php echo esc_attr($order->mp_shipping_info['address1']); ?> </td> </tr> <?php if ($order->mp_shipping_info['address2']) { ?> <tr> <td align="right"><?php _e('Address 2:', 'mp'); ?> </td> <td><?php echo esc_attr($order->mp_shipping_info['address2']); ?> </td> </tr> <?php } ?> <tr> <td align="right"><?php _e('City:', 'mp'); ?> </td> <td><?php echo esc_attr($order->mp_shipping_info['city']); ?> </td> </tr> <?php if ($order->mp_shipping_info['state']) { ?> <tr> <td align="right"><?php _e('State/Province/Region:', 'mp'); ?> </td> <td><?php echo esc_attr($order->mp_shipping_info['state']); ?> </td> </tr> <?php } ?> <tr> <td align="right"><?php _e('Postal/Zip Code:', 'mp'); ?> </td> <td><?php echo esc_attr($order->mp_shipping_info['zip']); ?> </td> </tr> <tr> <td align="right"><?php _e('Country:', 'mp'); ?> </td> <td><?php echo $mp->countries[$order->mp_shipping_info['country']]; ?> </td> </tr> <?php if ($order->mp_shipping_info['phone']) { ?> <tr> <td align="right"><?php _e('Phone Number:', 'mp'); ?> </td> <td><?php echo esc_attr($order->mp_shipping_info['phone']); ?> </td> </tr> <?php } ?> </table> <?php mp_orderstatus_link(true, false, __('« Back', 'mp')); ?> <?php } else { //not valid order id echo '<hr/><h3>' . __('Invalid Order ID. Please try again:', 'mp') . '</h3>'; ?> <form action="<?php mp_orderstatus_link(true, true); ?> " method="get"> <label><?php _e('Enter your 12-digit Order ID number:', 'mp'); ?> <br /> <input type="text" name="order_id" id="order_id" class="input" value="" size="20" /></label> <input type="submit" id="order-id-submit" value="<?php _e('Look Up »', 'mp'); ?> " /> </form> <?php } } else { //get from usermeta $user_id = get_current_user_id(); if ($user_id) { if (is_multisite()) { global $blog_id; $meta_id = 'mp_order_history_' . $blog_id; } else { $meta_id = 'mp_order_history'; } $orders = get_user_meta($user_id, $meta_id, true); } else { //get from cookie if (is_multisite()) { global $blog_id; $cookie_id = 'mp_order_history_' . $blog_id . '_' . COOKIEHASH; } else { $cookie_id = 'mp_order_history_' . COOKIEHASH; } if (isset($_COOKIE[$cookie_id])) { $orders = unserialize($_COOKIE[$cookie_id]); } } if (is_array($orders) && count($orders)) { krsort($orders); //list orders echo '<hr/><h3>' . __('Your Recent Orders:', 'mp') . '</h3>'; echo '<ul id="mp-order-list">'; foreach ($orders as $timestamp => $order) { echo ' <li><strong>' . date(get_option('date_format') . ' - ' . get_option('time_format'), $timestamp) . ':</strong> <a href="./' . trailingslashit($order['id']) . '">' . $order['id'] . '</a> - ' . $mp->format_currency('', $order['total']) . '</li>'; } echo '</ul>'; ?> <form action="<?php mp_orderstatus_link(true, true); ?> " method="get"> <label><?php _e('Or enter your 12-digit Order ID number:', 'mp'); ?> <br /> <input type="text" name="order_id" id="order_id" class="input" value="" size="20" /></label> <input type="submit" id="order-id-submit" value="<?php _e('Look Up »', 'mp'); ?> " /> </form> <?php } else { if (!is_user_logged_in()) { ?> <table class="mp_cart_login"> <thead><tr> <th class="mp_cart_login" colspan="2"><?php _e('Have a User Account? Login To View Your Order History:', 'mp'); ?> </th> <th> </th> </tr></thead> <tbody> <tr> <td class="mp_cart_login"> <form name="loginform" id="loginform" action="<?php echo wp_login_url(); ?> " method="post"> <label><?php _e('Username', 'mp'); ?> <br /> <input type="text" name="log" id="user_login" class="input" value="" size="20" /></label> <br /> <label><?php _e('Password', 'mp'); ?> <br /> <input type="password" name="pwd" id="user_pass" class="input" value="" size="20" /></label> <br /> <input type="submit" name="wp-submit" id="mp_login_submit" value="<?php _e('Login »', 'mp'); ?> " /> <input type="hidden" name="redirect_to" value="<?php mp_orderstatus_link(true, true); ?> " /> </form> </td> <td class="mp_cart_or_label"><?php _e('or', 'mp'); ?> </td> <td class="mp_cart_checkout"> <form action="<?php mp_orderstatus_link(true, true); ?> " method="get"> <label><?php _e('Enter your 12-digit Order ID number:', 'mp'); ?> <br /> <input type="text" name="order_id" id="order_id" class="input" value="" size="20" /></label> <input type="submit" id="order-id-submit" value="<?php _e('Look Up »', 'mp'); ?> " /> </form> </td> </tr> </tbody> </table> <?php } else { ?> <form action="<?php mp_orderstatus_link(true, true); ?> " method="get"> <label><?php _e('Enter your 12-digit Order ID number:', 'mp'); ?> <br /> <input type="text" name="order_id" id="order_id" class="input" value="" size="20" /></label> <input type="submit" id="order-id-submit" value="<?php _e('Look Up »', 'mp'); ?> " /> </form> <?php } } } }
/** * Echos the order status page. Use in the mp_orderstatus.php template. * */ function flexmarket_order_status($btnclass = '') { global $mp, $wp_query, $blog_id; $bid = is_multisite() ? $blog_id : 1; // FPM: Used for Custom Field Processing echo do_shortcode($mp->get_setting('msg->order_status')); $order_id = isset($wp_query->query_vars['order_id']) ? $wp_query->query_vars['order_id'] : (isset($_GET['order_id']) ? $_GET['order_id'] : ''); if (!empty($order_id)) { //get order $order = $mp->get_order($order_id); if ($order) { //valid order echo '<h2 class="page-header"><em>' . sprintf(__('Order Details (%s):', 'mp'), htmlentities($order_id)) . '</em></h2>'; ?> <div class="row-fluid"> <div class="span6 well well-small well-shadow" style="min-height: 250px;"> <h3 class="page-header"><?php _e('Current Status', 'mp'); ?> </h3> <ul> <?php //get times $received = isset($order->mp_received_time) ? date_i18n(get_option('date_format') . ' - ' . get_option('time_format'), $order->mp_received_time) : ''; if (!empty($order->mp_paid_time)) { $paid = date_i18n(get_option('date_format') . ' - ' . get_option('time_format'), $order->mp_paid_time); } if (!empty($order->mp_shipped_time)) { $shipped = date_i18n(get_option('date_format') . ' - ' . get_option('time_format'), $order->mp_shipped_time); } if ($order->post_status == 'order_received') { echo '<li>' . __('Received:', 'mp') . ' <strong>' . $received . '</strong></li>'; } else { if ($order->post_status == 'order_paid') { echo '<li>' . __('Paid:', 'mp') . ' <strong>' . $paid . '</strong></li>'; echo '<li>' . __('Received:', 'mp') . ' <strong>' . $received . '</strong></li>'; } else { if ($order->post_status == 'order_shipped' || $order->post_status == 'order_closed') { echo '<li>' . __('Shipped:', 'mp') . ' <strong>' . $shipped . '</strong></li>'; echo '<li>' . __('Paid:', 'mp') . ' <strong>' . $paid . '</strong></li>'; echo '<li>' . __('Received:', 'mp') . ' <strong>' . $received . '</strong></li>'; } } } $order_paid = $order->post_status != 'order_received'; $max_downloads = $mp->get_setting('max_downloads', 5); ?> </ul> </div><!-- / span6 --> <div class="span6 well well-small well-shadow" style="min-height: 250px;"> <h3 class="page-header"><?php _e('Payment Information:', 'mp'); ?> </h3> <ul> <li> <?php _e('Payment Method:', 'mp'); ?> <strong><?php echo $order->mp_payment_info['gateway_public_name']; ?> </strong> </li> <li> <?php _e('Payment Type:', 'mp'); ?> <strong><?php echo $order->mp_payment_info['method']; ?> </strong> </li> <li> <?php _e('Transaction ID:', 'mp'); ?> <strong><?php echo $order->mp_payment_info['transaction_id']; ?> </strong> </li> <li> <?php _e('Payment Total:', 'mp'); ?> <strong><?php echo $mp->format_currency($order->mp_payment_info['currency'], $order->mp_payment_info['total']) . ' ' . $order->mp_payment_info['currency']; ?> </strong> </li> </ul> </div><!-- / span6 --> </div><!-- / row-fluid --> <div class="clear padding20"></div> <h3><?php _e('Order Information:', 'mp'); ?> </h3> <table id="mp-order-product-table" class="mp_cart_contents table table-striped table-bordered table-hover"> <thead><tr> <th class="mp_cart_col_thumb"> </th> <th class="mp_cart_col_product"><?php _e('Item', 'mp'); ?> </th> <th class="mp_cart_col_quant"><?php _e('Quantity', 'mp'); ?> </th> <th class="mp_cart_col_price"><?php _e('Price', 'mp'); ?> </th> <th class="mp_cart_col_subtotal"><?php _e('Subtotal', 'mp'); ?> </th> <th class="mp_cart_col_downloads"><?php _e('Download', 'mp'); ?> </th> </tr></thead> <tbody> <?php if (is_array($order->mp_cart_info) && count($order->mp_cart_info)) { foreach ($order->mp_cart_info as $product_id => $variations) { //for compatibility for old orders from MP 1.x if (isset($variations['name'])) { $data = $variations; echo '<tr>'; echo ' <td class="mp_cart_col_thumb">' . mp_product_image(false, 'widget', $product_id) . '</td>'; echo ' <td class="mp_cart_col_product"><a href="' . apply_filters('mp_product_url_display_in_cart', get_permalink($product_id), $product_id) . '">' . apply_filters('mp_product_name_display_in_cart', $data['name'], $product_id) . '</a>' . '</td>'; // Added WPML (This differs than other code) echo ' <td class="mp_cart_col_quant">' . number_format_i18n($data['quantity']) . '</td>'; echo ' <td class="mp_cart_col_price">' . $mp->format_currency('', $data['price']) . '</td>'; echo ' <td class="mp_cart_col_subtotal">' . $mp->format_currency('', $data['price'] * $data['quantity']) . '</td>'; echo ' <td class="mp_cart_col_downloads"></td>'; echo '</tr>'; } else { foreach ($variations as $variation => $data) { echo '<tr>'; echo ' <td class="mp_cart_col_thumb">' . mp_product_image(false, 'widget', $product_id) . '</td>'; echo ' <td class="mp_cart_col_product"><a href="' . apply_filters('mp_product_url_display_in_cart', get_permalink($product_id), $product_id) . '">' . apply_filters('mp_product_name_display_in_cart', $data['name'], $product_id) . '</a>'; // Output product custom field information $cf_key = $bid . ':' . $product_id . ':' . $variation; if (isset($order->mp_shipping_info['mp_custom_fields'][$cf_key])) { $cf_item = $order->mp_shipping_info['mp_custom_fields'][$cf_key]; $mp_custom_field_label = get_post_meta($product_id, 'mp_custom_field_label', true); if (isset($mp_custom_field_label[$variation])) { $label_text = $mp_custom_field_label[$variation]; } else { $label_text = __('Product Personalization:', 'mp'); } echo '<div class="mp_cart_custom_fields">' . $label_text . '<br />'; foreach ($cf_item as $item) { echo (!empty($item) ? '<i class="icon-minus opacity5"></i> ' : '') . $item . '<br/>'; } echo '</div>'; } echo '</td>'; // Added WPML (This differs than other code) echo ' <td class="mp_cart_col_quant">' . number_format_i18n($data['quantity']) . '</td>'; echo ' <td class="mp_cart_col_price">' . $mp->format_currency('', $data['price']) . '</td>'; echo ' <td class="mp_cart_col_subtotal">' . $mp->format_currency('', $data['price'] * $data['quantity']) . '</td>'; if (is_array($data['download']) && ($download_url = $mp->get_download_url($product_id, $order->post_title))) { if ($order_paid) { //check for too many downloads if (intval($data['download']['downloaded']) < $max_downloads) { echo ' <td class="mp_cart_col_downloads"><a href="' . $download_url . '">' . __('Download»', 'mp') . '</a></td>'; } else { echo ' <td class="mp_cart_col_downloads">' . __('Limit Reached', 'mp') . '</td>'; } } else { echo ' <td class="mp_cart_col_downloads">' . __('Awaiting Payment', 'mp') . '</td>'; } } else { echo ' <td class="mp_cart_col_downloads"></td>'; } echo '</tr>'; } } } } else { echo '<tr><td colspan="6">' . __('No products could be found for this order', 'mp') . '</td></tr>'; } ?> </tbody> </table> <div class="clear padding5"></div> <table class="table table-striped table-bordered table-hover"> <?php //coupon line if ($order->mp_discount_info) { ?> <tr> <td class="align-right span8"><?php _e('Coupon Discount:', 'mp'); ?> </td> <td class="span4"><strong><?php echo $order->mp_discount_info['discount']; ?> </strong></td> </tr> <?php } ?> <?php //shipping line if ($order->mp_shipping_total) { ?> <tr> <td class="align-right span8"><?php _e('Shipping:', 'mp'); ?> </td> <td class="span4"><strong><?php echo $mp->format_currency('', $order->mp_shipping_total); ?> </strong></td> </tr> <?php } ?> <?php //tax line if ($order->mp_tax_total) { ?> <tr> <td class="align-right span8"><?php _e('Taxes:', 'mp'); ?> </td> <td class="span4"><strong><?php echo $mp->format_currency('', $order->mp_tax_total); ?> </strong></td> </tr> <?php } ?> <tr> <td class="align-right span8"><?php _e('Order Total:', 'mp'); ?> </td> <td class="span4"><strong><?php echo $mp->format_currency('', $order->mp_order_total); ?> </strong></td> </tr> </table> <div class="clear padding10"></div> <?php if (!defined('MP_HIDE_ORDERSTATUS_SHIPPING')) { ?> <h3><?php _e('Shipping Information:', 'mp'); ?> </h3> <table class="table table-striped table-bordered table-hover"> <tr> <td class="span4 align-right" align="right"><?php _e('Full Name:', 'mp'); ?> </td><td> <?php echo esc_attr($order->mp_shipping_info['name']); ?> </td> </tr> <tr> <td class="span4 align-right" align="right"><?php _e('Address:', 'mp'); ?> </td> <td><?php echo esc_attr($order->mp_shipping_info['address1']); ?> </td> </tr> <?php if ($order->mp_shipping_info['address2']) { ?> <tr> <td class="span4 align-right" align="right"><?php _e('Address 2:', 'mp'); ?> </td> <td><?php echo esc_attr($order->mp_shipping_info['address2']); ?> </td> </tr> <?php } ?> <tr> <td class="span4 align-right" align="right"><?php _e('City:', 'mp'); ?> </td> <td><?php echo esc_attr($order->mp_shipping_info['city']); ?> </td> </tr> <?php if ($order->mp_shipping_info['state']) { ?> <tr> <td class="span4 align-right" align="right"><?php _e('State/Province/Region:', 'mp'); ?> </td> <td><?php echo esc_attr($order->mp_shipping_info['state']); ?> </td> </tr> <?php } ?> <tr> <td class="span4 align-right" align="right"><?php _e('Postal/Zip Code:', 'mp'); ?> </td> <td><?php echo esc_attr($order->mp_shipping_info['zip']); ?> </td> </tr> <tr> <td class="span4 align-right" align="right"><?php _e('Country:', 'mp'); ?> </td> <td><?php echo $mp->countries[$order->mp_shipping_info['country']]; ?> </td> </tr> <?php if ($order->mp_shipping_info['phone']) { ?> <tr> <td class="span4 align-right" align="right"><?php _e('Phone Number:', 'mp'); ?> </td> <td><?php echo esc_attr($order->mp_shipping_info['phone']); ?> </td> </tr> <?php } ?> <?php if (isset($order->mp_shipping_info['tracking_num'])) { ?> <tr> <td class="span4 align-right" align="right"><?php _e('Tracking Number:', 'mp'); ?> </td> <td><?php echo mp_tracking_link($order->mp_shipping_info['tracking_num'], $order->mp_shipping_info['method']); ?> </td> </tr> <?php } ?> </table> <?php } ?> <?php if (isset($order->mp_order_notes)) { ?> <h3><?php _e('Order Notes:', 'mp'); ?> </h3> <div class="well"> <?php echo wpautop($order->mp_order_notes); ?> </div> <?php } ?> <?php do_action('mp_order_status_output', $order); ?> <a class="btn btn-large<?php echo $btnclass; ?> " href="<?php mp_orderstatus_link(true, true); ?> " ><?php _e('« Back', 'mp'); ?> </a> <?php } else { //not valid order id echo '<h3>' . __('Invalid Order ID. Please try again:', 'mp') . '</h3>'; ?> <form action="<?php mp_orderstatus_link(true, true); ?> " method="get"> <label><?php _e('Enter your 12-digit Order ID number:', 'mp'); ?> <br /> <input type="text" name="order_id" id="order_id" class="input" value="" size="20" /></label> <input type="submit" class="btn<?php echo $btnclass; ?> " id="order-id-submit" value="<?php _e('Look Up »', 'mp'); ?> " /> </form> <?php } } else { //get from usermeta $user_id = get_current_user_id(); if ($user_id) { if (is_multisite()) { global $blog_id; $meta_id = 'mp_order_history_' . $blog_id; } else { $meta_id = 'mp_order_history'; } $orders = get_user_meta($user_id, $meta_id, true); } else { //get from cookie if (is_multisite()) { global $blog_id; $cookie_id = 'mp_order_history_' . $blog_id . '_' . COOKIEHASH; } else { $cookie_id = 'mp_order_history_' . COOKIEHASH; } if (isset($_COOKIE[$cookie_id])) { $orders = unserialize($_COOKIE[$cookie_id]); } } if (is_array($orders) && count($orders)) { krsort($orders); //list orders echo '<h3>' . __('Your Recent Orders:', 'mp') . '</h3>'; echo '<ul id="mp-order-list">'; foreach ($orders as $timestamp => $order) { echo ' <li><strong>' . date_i18n(get_option('date_format') . ' - ' . get_option('time_format'), $timestamp) . ':</strong> <a href="./' . trailingslashit($order['id']) . '">' . $order['id'] . '</a> - ' . $mp->format_currency('', $order['total']) . '</li>'; } echo '</ul>'; ?> <div class="clear padding20"></div> <form action="<?php mp_orderstatus_link(true, true); ?> " method="get"> <label><?php _e('Or enter your 12-digit Order ID number:', 'mp'); ?> <br /> <input type="text" name="order_id" id="order_id" class="input" value="" size="20" /></label> <input type="submit" id="order-id-submit" class="btn<?php echo $btnclass; ?> " value="<?php _e('Look Up »', 'mp'); ?> " /> </form> <?php } else { if (!is_user_logged_in()) { ?> <table class="mp_cart_login table table-striped"> <thead><tr> <th class="mp_cart_login" colspan="2"><?php _e('Have a User Account? Login To View Your Order History:', 'mp'); ?> </th> <th> </th> </tr></thead> <tbody> <tr> <td class="mp_cart_login"> <div class="padding20"></div> <form name="loginform" id="loginform" action="<?php echo wp_login_url(); ?> " method="post" class="form-inline"> <label><?php _e('Username', 'mp'); ?> <input type="text" name="log" id="user_login" class="input" value="" size="20" /></label> <label><?php _e('Password', 'mp'); ?> <input type="password" name="pwd" id="user_pass" class="input" value="" size="20" /></label> <input type="submit" name="wp-submit" class="btn<?php echo $btnclass; ?> " id="mp_login_submit" value="<?php _e('Login »', 'mp'); ?> " /> <input type="hidden" name="redirect_to" value="<?php mp_orderstatus_link(true, true); ?> " /> </form> </td> </tr> </tbody> </table> <div class="clear padding10"></div> <div class="mp_cart_checkout"> <form action="<?php mp_orderstatus_link(true, true); ?> " method="get"> <label><?php _e('Or, Enter your 12-digit Order ID number:', 'mp'); ?> <br /> <input type="text" name="order_id" id="order_id" class="input" value="" size="20" /></label> <input type="submit" id="order-id-submit" class="btn<?php echo $btnclass; ?> " value="<?php _e('Look Up »', 'mp'); ?> " /> </form> </div> <?php } else { ?> <form action="<?php mp_orderstatus_link(true, true); ?> " method="get"> <label><?php _e('Enter your 12-digit Order ID number:', 'mp'); ?> <br /> <input type="text" name="order_id" id="order_id" class="input" value="" size="20" /></label> <input type="submit" id="order-id-submit" class="btn<?php echo $btnclass; ?> " value="<?php _e('Look Up »', 'mp'); ?> " /> </form> <?php } } } }
function widget($args, $instance) { global $mp, $post; if ($instance['only_store_pages'] && !mp_is_shop_page()) { return; } extract($args); echo $before_widget; $title = $instance['title']; if (!empty($title)) { echo $before_title . apply_filters('widget_title', $title) . $after_title; } if (!empty($instance['custom_text'])) { echo '<div id="custom_text">' . $instance['custom_text'] . '</div>'; } /* setup our custom query */ //setup taxonomy if applicable if ($instance['taxonomy_type'] == 'category') { $taxonomy_query = '&product_category=' . $instance['taxonomy']; } else { if ($instance['taxonomy_type'] == 'tag') { $taxonomy_query = '&product_tag=' . $instance['taxonomy']; } else { $taxonomy_query = ''; } } //figure out perpage if (isset($instance['num_products']) && intval($instance['num_products']) > 0) { $paginate_query = '&posts_per_page=' . intval($instance['num_products']) . '&paged=1'; } else { $paginate_query = '&posts_per_page=10&paged=1'; } //get order by if ($instance['order_by']) { if ($instance['order_by'] == 'price') { $order_by_query = '&meta_key=mp_price_sort&orderby=meta_value_num'; } else { if ($instance['order_by'] == 'sales') { $order_by_query = '&meta_key=mp_sales_count&orderby=meta_value_num'; } else { $order_by_query = '&orderby=' . $instance['order_by']; } } } else { $order_by_query = '&orderby=title'; } //get order direction if ($instance['order']) { $order_query = '&order=' . $instance['order']; } else { $order_query = '&orderby=DESC'; } //The Query $custom_query = new WP_Query('post_type=product' . $taxonomy_query . $paginate_query . $order_by_query . $order_query); //do we have products? if ($custom_query->have_posts()) { echo '<ul id="mp_product_list" class="hfeed">'; while ($custom_query->have_posts()) { $custom_query->the_post(); echo '<li itemscope itemtype="http://schema.org/Product" ' . mp_product_class(false, array('mp_product', 'hentry'), $post->ID) . '>'; echo '<h3 class="mp_product_name entry-title" itemprop="name"><a href="' . get_permalink($post->ID) . '">' . esc_attr($post->post_title) . '</a></h3>'; if ($instance['show_thumbnail']) { mp_product_image(true, 'widget', $post->ID, $instance['size']); } echo '<div class="entry-content" style="margin:0;padding:0;width:auto;">'; if ($instance['show_excerpt']) { echo '<div class="mp_product_content">' . $mp->product_excerpt($post->post_excerpt, $post->post_content, $post->ID) . '</div>'; } if ($instance['show_price'] || $instance['show_button']) { echo '<div class="mp_product_meta">'; if ($instance['show_price']) { echo mp_product_price(false, $post->ID, ''); } if ($instance['show_button']) { echo mp_buy_button(false, 'list', $post->ID); } echo '</div>'; } echo '</div>'; echo '<div style="display:none"> <time class="updated">' . get_the_time('Y-m-d\\TG:i') . '</time> by <span class="author vcard"><span class="fn">' . get_the_author_meta('display_name') . '</span></span> </div>'; echo '</li>'; } wp_reset_postdata(); echo '</ul>'; } else { ?> <div class="widget-error"> <?php _e('No Products', 'mp'); ?> </div> <?php } echo $after_widget; }
function mp_list_global_products($args = '') { global $wpdb, $mp; $defaults = array('echo' => true, 'paginate' => true, 'page' => 0, 'per_page' => 20, 'order_by' => 'date', 'order' => 'DESC', 'category' => '', 'tag' => '', 'show_thumbnail' => true, 'thumbnail_size' => 150, 'context' => 'list', 'show_price' => true, 'text' => 'excerpt', 'as_list' => false); $r = wp_parse_args($args, $defaults); extract($r); //setup taxonomy if applicable if ($category) { $category = $wpdb->escape(sanitize_title($category)); $query = "SELECT blog_id, p.post_id, post_permalink, post_title, post_content FROM {$wpdb->base_prefix}mp_products p INNER JOIN {$wpdb->base_prefix}mp_term_relationships r ON p.id = r.post_id INNER JOIN {$wpdb->base_prefix}mp_terms t ON r.term_id = t.term_id WHERE p.blog_public = 1 AND t.type = 'product_category' AND t.slug = '{$category}'"; } else { if ($tag) { $tag = $wpdb->escape(sanitize_title($tag)); $query = "SELECT blog_id, p.post_id, post_permalink, post_title, post_content FROM {$wpdb->base_prefix}mp_products p INNER JOIN {$wpdb->base_prefix}mp_term_relationships r ON p.id = r.post_id INNER JOIN {$wpdb->base_prefix}mp_terms t ON r.term_id = t.term_id WHERE p.blog_public = 1 AND t.type = 'product_tag' AND t.slug = '{$tag}'"; } else { $query = "SELECT blog_id, p.post_id, post_permalink, post_title, post_content FROM {$wpdb->base_prefix}mp_products p WHERE p.blog_public = 1"; } } //get order by switch ($order_by) { case 'title': $query .= " ORDER BY p.post_title"; break; case 'price': $query .= " ORDER BY p.price"; break; case 'sales': $query .= " ORDER BY p.sales_count"; break; case 'rand': $query .= " ORDER BY RAND()"; break; case 'date': default: $query .= " ORDER BY p.post_date"; break; } //get order direction if ($order == 'ASC') { $query .= " ASC"; } else { $query .= " DESC"; } //adjust for mysql (0 is lowest) $page = $page - 1; if ($page < 0) { $page = 0; } $start = $page * $per_page; //get page details if ($paginate) { $query .= " LIMIT " . intval($start) . ", " . intval($per_page); } //The Query $results = $wpdb->get_results($query); if ($as_list) { $content = '<ul id="mp_product_list">'; } else { $content = '<div id="mp_product_list">'; } if ($results) { $results = apply_filters('mp_list_global_products_results', $results); foreach ($results as $product) { if ($as_list) { $content .= '<li class="product type-product mp_product">'; } else { $content .= '<div class="product type-product mp_product">'; } global $current_blog; switch_to_blog($product->blog_id); //grab permalink $permalink = get_permalink($product->post_id); //grab thumbnail if ($show_thumbnail) { $thumbnail = mp_product_image(false, $context, $product->post_id, $thumbnail_size); } //price if ($show_price) { if ($context == 'widget') { $price = mp_product_price(false, $product->post_id, ''); } else { $price = mp_product_price(false, $product->post_id); } } restore_current_blog(); $content .= '<h3 class="mp_product_name"><a href="' . $permalink . '">' . esc_attr($product->post_title) . '</a></h3>'; $content .= '<div class="mp_product_content">'; $content .= $thumbnail; //show content if ($text == 'excerpt') { $excerpt = str_replace(']]>', ']]>', $product->post_content); $excerpt = strip_tags($excerpt); $excerpt_length = apply_filters('excerpt_length', 55); $words = preg_split("/[\n\r\t ]+/", $excerpt, $excerpt_length + 1, PREG_SPLIT_NO_EMPTY); if (count($words) > $excerpt_length) { array_pop($words); $excerpt = implode(' ', $words); } else { $excerpt = implode(' ', $words); } $content .= '<p>' . $excerpt . '<p>'; } else { if ($text == 'content') { $content .= $product->post_content; } } $content .= '</div>'; $content .= '<div class="mp_product_meta">'; //price $content .= $price; //button $content .= '<a class="mp_link_buynow" href="' . $permalink . '">' . __('Buy Now »', 'mp') . '</a>'; $content .= '</div>'; if ($as_list) { $content .= '</li>'; } else { $content .= '</div>'; } } } else { if ($as_list) { $content .= '<li>' . __('No Products', 'mp') . '</li>'; } else { $content .= __('No Products', 'mp'); } } if ($as_list) { $content .= '</ul>'; } else { $content .= '</div>'; } if ($echo) { echo $content; } else { return $content; } }
function mp_product($echo = true, $product_id, $title = true, $content = 'full', $image = 'single', $meta = true) { global $mp; $post = get_post($product_id); $return = '<div itemscope itemtype="http://schema.org/Product" ' . mp_product_class(false, 'mp_product', $post->ID) . '>'; if ($title) { $return .= '<h3 itemprop="name" class="mp_product_name"><a href="' . get_permalink($post->ID) . '">' . $post->post_title . '</a></h3>'; } if ($content) { $return .= '<div itemprop="description" class="mp_product_content">'; if ($image) { $return .= mp_product_image(false, $image, $post->ID); } if ($content == 'excerpt') { $return .= $mp->product_excerpt($post->post_excerpt, $post->post_content, $post->ID); } else { $return .= apply_filters('the_content', $post->post_content); } $return .= '</div>'; } if ($meta) { $return .= '<div itemprop="offers" itemscope itemtype="http://schema.org/Offer" class="mp_product_meta">'; //price $return .= mp_product_price(false, $post->ID); //button $return .= mp_buy_button(false, 'single', $post->ID); $return .= '</div>'; } $return .= '</div>'; if ($echo) { echo $return; } else { return $return; } }