function mp_product_meta_sc($atts) { extract(shortcode_atts(array('context' => 'single', 'label' => true, 'product_id' => NULL), $atts)); $content = '<div class="mp_product_meta">'; $content .= mp_product_price(false, $product_id, $label); $content .= mp_buy_button(false, $context, $product_id); $content .= '</div>'; return $content; }
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; } }
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 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']; } } //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=mp_price'; } else { if ($instance['order_by'] == 'sales') { $order_by_query = '&meta_key=mp_sales_count&orderby=mp_sales_count'; } 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">'; foreach ($custom_query->posts as $post) { echo '<li ' . mp_product_class(false, 'mp_product', $post->ID) . '>'; echo '<h3 class="mp_product_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']); } 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>'; } $content .= '</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); }
/** * Returns properly formatted product price for Event on the front end. */ function show_product_price($price, $event_id) { if (!$this->_is_mp_present()) { return $price; } $event = new Eab_EventModel(get_post($event_id)); $parent_event_id = $event->is_recurring_child(); if (!$parent_event_id) { $linked_product_id = get_post_meta($event_id, 'eab_product_id', true); if (!$linked_product_id) { return $price; } return mp_product_price(false, $linked_product_id, false); } else { // Recurring event child. Figure out parent-linked product ID and appropriate SKU $linked_product_id = get_post_meta($parent_event_id, 'eab_product_id', true); if (!$linked_product_id) { return $price; } $skus = maybe_unserialize(get_post_meta($linked_product_id, 'mp_sku', true)); if (empty($skus)) { return $price; } $price_id = in_array($event_id, $skus) ? array_search($event_id, $skus) : false; if (false === $price_id) { return $price; } $prices = maybe_unserialize(get_post_meta($linked_product_id, 'mp_price', true)); if (empty($prices)) { return $price; } $raw_price = isset($prices[$price_id]) ? $prices[$price_id] : false; if (!$raw_price) { return $price; } // Sales test $is_sale = get_post_meta($linked_product_id, 'mp_is_sale', true); if ($is_sale) { $sales = maybe_unserialize(get_post_meta($linked_product_id, 'mp_sale_price', true)); if (!empty($sales) && !empty($sales[$price_id])) { $raw_price = $sales[$price_id]; } } // End sales test global $mp; return apply_filters('mp_product_price_tag', '<span class="mp_product_price">' . $mp->format_currency('', $raw_price) . '</span>', $linked_product_id, ''); } return $price; // This won't happen, but whatever }
/** * Returns properly formatted product price for Event on the front end. */ function show_product_price($price, $event_id) { if (!$this->_is_mp_present()) { return $price; } $event = new Eab_EventModel(get_post($event_id)); $parent_event_id = $event->is_recurring_child(); if (!$parent_event_id) { $linked_product_id = get_post_meta($event_id, 'eab_product_id', true); if (!$linked_product_id) { return $price; } return mp_product_price(false, $linked_product_id, false); } else { // Recurring event child. Figure out parent-linked product ID and appropriate SKU $linked_product_id = get_post_meta($parent_event_id, 'eab_product_id', true); if (!$linked_product_id) { return $price; } $query = new WP_Query(array('post_type' => apply_filters('mp_product_variation_post_type', 'mp_product_variation'), 'posts_per_page' => 1, 'post_parent' => $linked_product_id, 'meta_query' => array(array('key' => 'sku', 'value' => $event_id)), 'fields' => 'ids')); $variation_id = !empty($query->posts[0]) ? $query->posts[0] : false; if (empty($variation_id)) { return $price; } $raw_price = MP_Product::get_variation_meta($variation_id, 'regular_price'); if (!$raw_price) { return $price; } /* $product = new MP_Product($linked_product_id); if ($product->on_sale()) { } // Sales test $is_sale = MP_Product::get_variation_meta($variation_id, 'price'); if ($is_sale) { $sales = maybe_unserialize(get_post_meta($linked_product_id, 'mp_sale_price', true)); if (!empty($sales) && !empty($sales[$price_id])) $raw_price = $sales[$price_id]; } // End sales test */ return apply_filters('mp_product/display_price', '<span class="mp_product_price">' . mp_format_currency('', $raw_price) . '</span>', $raw_price, $linked_product_id); } return $price; // This won't happen, but whatever }
function framemarket_product_meta() { global $post, $id; $post_id = NULL === $post->ID ? $id : $post->ID; //don't filter outside of the loop if (!in_the_loop()) { return $content; } $content = '<div class="product-meta-details">'; $content .= mp_category_list($post_id, '<span class="grid_mp_product_categories">' . __('Categorized in ', 'mp'), ', ', '</span>'); $content .= ' '; $content .= mp_tag_list($post_id, '<span class="grid_mp_product_tags">' . __('Tagged in ', 'mp'), ', ', '</span>'); $content .= '</div><hr/><div class="product-meta-details">'; $content .= mp_product_price(false); $content .= mp_pinit_button(); $content .= mp_buy_button(false, 'single'); $content .= '</div><hr />'; return $content; }
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; } }