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 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_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_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_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; } }