public function widget($args, $instance) { extract($args); global $wpdb, $post; $title = apply_filters('widget_title', $instance['title']); $post_num = isset($instance['post-quantity']) ? $instance['post-quantity'] : 5; $post_type = isset($instance['post-type']) ? $instance['post-type'] : 'post'; $sort_by = isset($instance['sort-by']) ? $instance['sort-by'] : 'date'; $sort_order = isset($instance['sort-order']) ? $instance['sort-order'] : false; if ($sort_order) { $order = 'ASC'; } else { $order = 'DESC'; } $show_date = isset($instance['date']) ? $instance['date'] : false; $show_comments = isset($instance['comments']) ? $instance['comments'] : false; $categories = isset($instance['category']) ? $instance['category'] : ''; $show_excerpt = isset($instance['excerpt']) ? $instance['excerpt'] : false; $excerpt_length = isset($instance['excerpt-length']) ? $instance['excerpt-length'] : 10; $excerpt_more = isset($instance['excerpt-more']) ? $instance['excerpt-more'] : '...read more'; // Excerpt filters $new_excerpt_more = create_function('$more', 'return " ";'); add_filter('excerpt_more', $new_excerpt_more); $new_excerpt_length = create_function('$length', 'return "' . $excerpt_length . '";'); if ($excerpt_length > 0) { add_filter('excerpt_length', $new_excerpt_length); } $show_thumb = isset($instance['thumb']) ? $instance['thumb'] : false; $show_price = isset($instance['price']) ? $instance['price'] : false; $cur_postID = $post->ID; // The Query $query_args = array('ignore_sticky_posts' => 1, 'posts_per_page' => $post_num, 'orderby' => $sort_by, 'order' => $order, 'post_type' => $post_type, 'post_status' => 'publish', 'cat' => $categories); $the_query = new WP_Query($query_args); echo $before_widget; if ($title) { echo $before_title . $title . $after_title; } echo '<ul class="recent-post-list">'; while ($the_query->have_posts()) { $the_query->the_post(); // Frontend Output ?> <li class="recent-post-item"> <?php if ($show_thumb && has_post_thumbnail()) { ?> <div class="thumb-wrapper"> <a class="recent-posts-img-link" rel="bookmark" href="<?php the_permalink(); ?> " title="Click to learn more about <?php the_title(); ?> "> <?php the_post_thumbnail('shortcode-thumb-short'); ?> </a> </div> <?php } // Post Thumbnail ?> <h4> <a href="<?php the_permalink(); ?> " class="nav-button" rel="bookmark" title="Click to learn more about <?php the_title(); ?> "><?php the_title(); ?> </a> </h4> <?php if ($show_date || $show_comments) { ?> <div class="recent-posts-entry-meta"> <?php if ($show_date) { ?> <div class="post-date"><?php the_time('F jS, Y'); ?> <span class="post-author"> by <?php the_author_posts_link(); ?> </span></div> <?php } // Post Date & Author ?> <?php if ($show_comments) { ?> <div class="comments-qty"><?php comments_popup_link('No comments yet', '1 comment', '% comments', 'comments-link', 'Comments are off for this post'); ?> </div> <?php } // Post Comments ?> </div> <?php } ?> <?php if ($show_excerpt) { ?> <div class="recent-posts-entry-content"><?php the_excerpt(); ?> <a href="<?php the_permalink(); ?> " class="more-link" rel="bookmark" title="Read more about <?php the_title(); ?> "><?php echo $excerpt_more; ?> </a> </div> <?php } // Post Content ?> <?php if ($show_price && $post_type != 'product') { continue; } else { if ($post_type === 'product') { echo '<div class="product-price">'; woocommerce_template_single_price(); echo '</div>'; // Product Price if WOO } elseif ($post_type === 'wpsc-product') { echo '<div class="product-price">'; wpsc_the_product_price_display(); echo '</div>'; // Product Price if WPEC } else { continue; } } ?> </li> <?php } echo '</ul>'; echo $after_widget; wp_reset_postdata(); }
?> "> <p><?php the_title(); ?> </p> </a> <?php if (wpsc_product_is_donation()) { ?> <h4>Donation</h4> <?php } else { ?> <h4><?php wpsc_the_product_price_display(); ?> </h4> <!-- multi currency code --> <?php if (wpsc_product_has_multicurrency()) { ?> <h4><?php echo wpsc_display_product_multicurrency(); ?> </h4> <?php } ?> <?php }
/** ***************************** *** FOR WPEC VERSION 3.9+ *** ***************************** COPIED FROM WPSC-INCLUDES/PRODUCT-TEMPLATE.PHP WPEC VERSION 3.8.10 * WPSC The Product Price Display * * @param $args (array) Array of args. * @return (string) HTML formatted prices * * @uses apply_filters() Calls 'wpsc_the_product_price_display_old_price_class' passing class and product ID * @uses apply_filters() Calls 'wpsc_the_product_price_display_old_price_amount_class' passing class and product ID * @uses apply_filters() Calls 'wpsc_the_product_price_display_price_class' passing class and product ID * @uses apply_filters() Calls 'wpsc_the_product_price_display_price_amount_class' passing class and product ID * @uses apply_filters() Calls 'wpsc_the_product_price_display_you_save_class' passing class and product ID * @uses apply_filters() Calls 'wpsc_the_product_price_display_you_save_amount_class' passing class and product ID * @uses wpsc_product_normal_price() Get the normal price * @uses wpsc_the_product_price() Get the current price * @uses wpsc_you_save() Get pricing saving * @uses wpsc_product_on_special() Is product on sale? * @uses wpsc_product_has_variations() Checks if product has variations * @uses wpsc_product_variation_price_from() Gets the lowest variation price * @uses wpsc_currency_display() Display price as currency */ function vtprd_the_product_price_display($args = array()) { global $vtprd_info, $vtprd_setup_options; if (empty($args['id'])) { $id = get_the_ID(); } else { $id = (int) $args['id']; } //-+--+-+-+-+-+-+-+-+-+-+-++--+-+-+-+-+-+-+-+-+-+-++--+-+-+-+-+-+-+-+-+-+-+ // if $id is a variation and has a parent, sent the PARENT!!! //gets all of the info we need and puts it into 'product_session_info' vtprd_get_product_session_info($id); //-+--+-+-+-+-+-+-+-+-+-+-++--+-+-+-+-+-+-+-+-+-+-++--+-+-+-+-+-+-+-+-+-+-+ // if $id is a variation, refigure product_yousave_total_amt!! //refigure yousave amts for WPEC if (VTPRD_PARENT_PLUGIN_NAME == 'WP E-Commerce') { vtprd_WPEC_recompute_theme_amts(); } //if we have no yousave amt, do the default routine and exit if ($vtprd_info['product_session_info']['product_yousave_total_amt'] == 0) { wpsc_the_product_price_display($args); return; } $defaults = array('id' => $id, 'old_price_text' => __('Old Price: %s', 'wpsc'), 'price_text' => __('Price: %s', 'wpsc'), 'you_save_text' => __('You save: %s', 'wpsc'), 'old_price_class' => 'pricedisplay wpsc-product-old-price ' . $id, 'old_price_before' => '<p %s>', 'old_price_after' => '</p>', 'old_price_amount_id' => 'old_product_price_' . $id, 'old_price_amount_class' => 'oldprice', 'old_price_amount_before' => '<span class="%1$s" id="%2$s">', 'old_price_amount_after' => '</span>', 'price_amount_id' => 'product_price_' . $id, 'price_class' => 'pricedisplay wpsc-product-price ' . $id, 'price_before' => '<p %s>', 'price_after' => '</p>', 'price_amount_class' => 'currentprice pricedisplay ' . $id, 'price_amount_before' => '<span class="%1$s" id="%2$s">', 'price_amount_after' => '</span>', 'you_save_class' => 'pricedisplay wpsc-product-you-save product_' . $id, 'you_save_before' => '<p %s>', 'you_save_after' => '</p>', 'you_save_amount_id' => 'yousave_' . $id, 'you_save_amount_class' => 'yousave', 'you_save_amount_before' => '<span class="%1$s" id="%2$s">', 'you_save_amount_after' => '</span>', 'output_price' => true, 'output_old_price' => true, 'output_you_save' => true); $r = wp_parse_args($args, $defaults); extract($r); $amt = $vtprd_info['product_session_info']['product_list_price']; $amt = vtprd_format_money_element($amt); $old_price = $amt; $amt = $vtprd_info['product_session_info']['product_yousave_total_amt']; $amt = vtprd_format_money_element($amt); $you_save = $amt . '! (' . $vtprd_info['product_session_info']['product_yousave_total_pct'] . '%)'; $you_save_percentage = $vtprd_info['product_session_info']['product_yousave_total_pct']; // if the product has no variations, these amounts are straight forward... // $old_price = wpsc_product_normal_price( $id ); $current_price = wpsc_the_product_price(false, false, $id); // $you_save = wpsc_you_save( 'type=amount' ) . '! (' . wpsc_you_save() . '%)'; // $you_save_percentage = wpsc_you_save(); // $show_old_price = $show_you_save = wpsc_product_on_special( $id ); /* // but if the product has variations and at least one of the variations is on special, we have // a few edge cases... if ( wpsc_product_has_variations( $id ) && wpsc_product_on_special( $id ) ) { // generally it doesn't make sense to display "you save" amount unless the user has selected // a specific variation $show_you_save = false; $old_price_number = wpsc_product_variation_price_from( $id, array( 'only_normal_price' => true ) ); $current_price_number = wpsc_product_variation_price_from( $id ); // if coincidentally, one of the variations are not on special, but its price is equal to // or lower than the lowest variation sale price, old price should be hidden, and current // price should reflect the "normal" price, not the sales price, to avoid confusion if ( $old_price_number == $current_price_number ) { $show_old_price = false; $current_price = wpsc_product_normal_price( $id ); } } */ // replace placeholders in arguments with correct values $old_price_class = apply_filters('wpsc_the_product_price_display_old_price_class', $old_price_class, $id); $old_price_amount_class = apply_filters('wpsc_the_product_price_display_old_price_amount_class', $old_price_amount_class, $id); $attributes = 'class="' . esc_attr($old_price_class) . '"'; // if ( ! $show_old_price ) // $attributes .= ' style="display:none;"'; $old_price_before = sprintf($old_price_before, $attributes); $old_price_amount_before = sprintf($old_price_amount_before, esc_attr($old_price_amount_class), esc_attr($old_price_amount_id)); $price_class = 'class="' . esc_attr(apply_filters('wpsc_the_product_price_display_price_class', esc_attr($price_class), $id)) . '"'; $price_amount_class = apply_filters('wpsc_the_product_price_display_price_amount_class', esc_attr($price_amount_class), $id); $price_before = sprintf($price_before, $price_class); $price_amount_before = sprintf($price_amount_before, esc_attr($price_amount_class), esc_attr($price_amount_id)); $you_save_class = apply_filters('wpsc_the_product_price_display_you_save_class', $you_save_class, $id); $you_save_amount_class = apply_filters('wpsc_the_product_price_display_you_save_amount_class', $you_save_amount_class, $id); $attributes = 'class="' . esc_attr($you_save_class) . '"'; // if ( ! $show_you_save ) // $attributes .= ' style="display:none;"'; $you_save_before = sprintf($you_save_before, $attributes); $you_save_amount_before = sprintf($you_save_amount_before, esc_attr($you_save_amount_class), esc_attr($you_save_amount_id)); // $you_save = wpsc_currency_display ( $you_save ); $old_price = $old_price_amount_before . $old_price . $old_price_amount_after; $current_price = $price_amount_before . $current_price . $price_amount_after; $you_save = $you_save_amount_before . $you_save . $you_save_amount_after; $old_price_text = sprintf($old_price_text, $old_price); $price_text = sprintf($price_text, $current_price); $you_save_text = sprintf($you_save_text, $you_save); // if ( $vtprd_setup_options['show_old_price'] == 'yes' ) { if ($output_old_price && $old_price_text > ' ') { echo $old_price_before . $old_price_text . $old_price_after . "\n"; } if ($output_price) { echo $price_before . $price_text . $price_after . "\n"; } // if ( $vtprd_setup_options['show_you_save'] == 'yes' ) { if ($output_you_save) { if ($you_save_text > ' ') { echo $you_save_before . $you_save_text . $you_save_after . "\n"; } else { if ($vtprd_info['product_session_info']['show_yousave_one_some_msg'] > ' ') { echo $vtprd_info['product_session_info']['show_yousave_one_some_msg'] . "\n"; } } } return; }
<?php } ?> </td> <?php } ?> <td> <?php do_action('wpsc_product_before_description', wpsc_the_product_id(), $wp_query->post); ?> </td> <td class='wpsc_price_td'> <?php wpsc_the_product_price_display(array('output_you_save' => false)); ?> </td> <td> <?php if (wpsc_product_external_link(wpsc_the_product_id()) != '') { ?> <?php $action = wpsc_product_external_link(wpsc_the_product_id()); ?> <?php } else { ?> <?php $action = wpsc_this_page_url();
/** * Product Specials Widget content function * * Displays the latest products. * * Changes made in 3.8 that may affect users: * * 1. The product title link text does now not have a bold tag, it should be styled via css. * 2. <br /> tags have been ommitted. Padding and margins should be applied via css. * 3. Each product is enclosed in a <div> with a 'wpec-special-product' class. * 4. The product list is enclosed in a <div> with a 'wpec-special-products' class. * 5. Function now expect a single paramter with an array of options (used to be a string which prepended the output). */ function wpsc_specials($args = null, $instance) { global $wpdb; $args = wp_parse_args((array) $args, array('number' => 5)); if (!($number = (int) $instance['number'])) { $number = 5; } $show_thumbnails = isset($instance['show_thumbnails']) ? (bool) $instance['show_thumbnails'] : false; $show_description = isset($instance['show_description']) ? (bool) $instance['show_description'] : false; $show_discount = isset($instance['show_discount']) ? (bool) $instance['show_discount'] : false; $show_old_price = isset($instance['show_old_price']) ? (bool) $instance['show_old_price'] : false; $args = array('post_type' => 'wpsc-product', 'ignore_sticky_posts' => 1, 'post_status' => 'publish', 'post_parent' => 0, 'posts_per_page' => $number, 'no_found_rows' => true); add_filter('posts_join', '_wpsc_filter_special_widget_join'); add_filter('posts_where', '_wpsc_filter_special_widget_where'); $special_products = new WP_Query($args); remove_filter('posts_join', '_wpsc_filter_special_widget_join'); remove_filter('posts_where', '_wpsc_filter_special_widget_where'); if (!$special_products->post_count) { echo apply_filters('wpsc_specials_widget_no_items_message', __('We currently have no items on special.', 'wp-e-commerce')); return; } $product_ids = array(); while ($special_products->have_posts()) { $special_products->the_post(); ?> <h4><strong><a class="wpsc_product_title" href="<?php echo esc_url(wpsc_product_url(wpsc_the_product_id(), false)); ?> "><?php echo esc_html(wpsc_the_product_title()); ?> </a></h4></strong> <?php if ($show_description) { ?> <div class="wpsc-special-description"> <?php echo wpsc_the_product_description(); ?> </div> <?php } // close show description if (!in_array(wpsc_the_product_id(), $product_ids)) { $product_ids[] = wpsc_the_product_id(); $has_children = wpsc_product_has_children(get_the_ID()); $width = get_option('product_image_width'); $height = get_option('product_image_height'); if ($show_thumbnails) { if (wpsc_the_product_thumbnail()) { ?> <a rel="<?php echo str_replace(array(" ", '"', "'", '"', '''), array("_", "", "", "", ''), wpsc_the_product_title()); ?> " href="<?php echo esc_url(wpsc_the_product_permalink()); ?> "><img class="product_image" id="product_image_<?php echo esc_attr(wpsc_the_product_id()); ?> " alt="<?php echo esc_attr(wpsc_the_product_title()); ?> " title="<?php echo esc_attr(wpsc_the_product_title()); ?> " src="<?php echo esc_url(wpsc_the_product_thumbnail($width, $height)); ?> "/></a> <?php } else { ?> <a href="<?php esc_url(wpsc_the_product_permalink()); ?> "><img class="no-image" id="product_image_<?php echo esc_attr(wpsc_the_product_id()); ?> " alt="<?php echo esc_attr(wpsc_the_product_title()); ?> " title="<?php echo esc_attr(wpsc_the_product_title()); ?> " src="<?php echo esc_url(WPSC_CORE_THEME_PATH . '/wpsc-images/noimage.png'); ?> " width="<?php echo esc_attr($width); ?> " height="<?php echo esc_attr($height); ?> " /></a> <?php } ?> <br /> <?php } // close show thumbnails ?> <div id="special_product_price_<?php echo esc_attr(wpsc_the_product_id()); ?> "> <?php wpsc_the_product_price_display(array('output_old_price' => $show_old_price, 'output_you_save' => $show_discount)); ?> </div><br /> <?php } } wp_reset_postdata(); }