Esempio n. 1
0
/**
 * Related Products
 */
function get_related_products($product_id, $cats_search = true, $width, $height, $number = 20)
{
    global $wpdb;
    // Related products are found from category and tag
    $tags_array = array(0);
    $cats_array = array(0);
    $tags = '';
    $cats = '';
    // Get tags
    $terms = wp_get_post_terms($product_id, 'product_tag');
    foreach ($terms as $term) {
        $tags_array[] = $term->term_id;
    }
    $tags = implode(',', $tags_array);
    $terms = wp_get_post_terms($product_id, 'wpsc_product_category');
    foreach ($terms as $term) {
        $cats_array[] = $term->term_id;
    }
    $cats = implode(',', $cats_array);
    if ($cats_search) {
        $cats_search = "\n\t\t\t\t(\n\t\t\t\t\ttt.taxonomy ='wpsc_product_category'\n\t\t\t\t\tAND tt.term_taxonomy_id = tr.term_taxonomy_id\n\t\t\t\t\tAND tr.object_id  = p.ID\n\t\t\t\t\tAND tt.term_id IN ({$cats})\n\t\t\t\t)\n\t\t\t\tOR \n        ";
    } else {
        $cats_search = '';
    }
    $q = "\n\t\tSELECT p.ID\n\t\tFROM {$wpdb->term_taxonomy} AS tt, {$wpdb->term_relationships} AS tr, {$wpdb->posts} AS p\n\t\tWHERE \n\t\t\tp.ID != {$product_id}\n\t\t\tAND p.post_status = 'publish'\n\t\t\tAND p.post_type = 'wpsc-product'\n\t\t\tAND\n\t\t\t(\n                {$cats_search}\n\t\t\t\t(\n\t\t\t\t\ttt.taxonomy ='product_tag'\n\t\t\t\t\tAND tt.term_taxonomy_id = tr.term_taxonomy_id\n\t\t\t\t\tAND tr.object_id  = p.ID\n\t\t\t\t\tAND tt.term_id IN ({$tags})\n\t\t\t\t)\n\t\t\t)\n\t\tGROUP BY tr.object_id\n\t\tORDER BY RAND()\n\t\tLIMIT {$number};";
    $related = $wpdb->get_col($q);
    if (sizeof($related) > 0) {
        $args = array('post__in' => $related, 'post__not_in' => array($product_id), 'post_type' => 'wpsc-product', 'ignore_sticky_posts' => 1, 'posts_per_page' => $number, 'orderby' => 'rand');
        $related_query = new WP_Query($args);
        if ($related_query->have_posts()) {
            $_i = 0;
            while ($related_query->have_posts()) {
                $related_query->the_post();
                $_i++;
                $id = get_the_ID();
                $variants_exist = $wpdb->get_row("SELECT * FROM {$wpdb->posts} WHERE `post_parent`={$id} AND `post_type`='wpsc-product'", 'ARRAY_A');
                $related_array[$_i]['id'] = get_the_ID();
                $related_array[$_i]['title'] = esc_attr(get_the_title());
                $related_array[$_i]['image'] = etheme_get_image(0, $width, $height, false, $id);
                $related_array[$_i]['permalink'] = get_permalink();
                if ($variants_exist) {
                    if (wpsc_product_on_special($id)) {
                        $related_array[$_i]['normal_price'] = wpsc_product_normal_price($id);
                        $related_array[$_i]['price'] = wpsc_the_product_price($id);
                    } else {
                        $related_array[$_i]['normal_price'] = 0;
                        $related_array[$_i]['price'] = wpsc_the_product_price($id);
                    }
                } else {
                    $related_array[$_i]['normal_price'] = the_product_price($id);
                    $related_array[$_i]['price'] = the_product_price($id, true);
                }
                unset($variants_exist);
            }
        }
        wp_reset_postdata();
    }
    return $related_array;
}
:</label>
								<input type='text' id='donation_price_<?php 
        echo wpsc_the_product_id();
        ?>
' name='donation_price' value='<?php 
        echo $wpsc_query->product['price'];
        ?>
' size='6' />
								<br />
							
							
							<?php 
    } else {
        ?>
								<?php 
        if (wpsc_product_on_special()) {
            ?>
									<span class='oldprice'><?php 
            echo __('Price', 'wpsc');
            ?>
: <?php 
            echo wpsc_product_normal_price();
            ?>
</span><br />
								<?php 
        }
        ?>
								  <span id="product_price_<?php 
        echo wpsc_the_product_id();
        ?>
" class="pricedisplay"><?php 
Esempio n. 3
0
function wpsc_the_product_price_display($args = array())
{
    if (empty($args['id'])) {
        $id = get_the_ID();
    } else {
        $id = (int) $args['id'];
    }
    $defaults = array('id' => $id, 'old_price_text' => __('Old Price: %s', 'wp-e-commerce'), 'price_text' => __('Price: %s', 'wp-e-commerce'), 'you_save_text' => __('You save: %s', 'wp-e-commerce'), '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);
    /**
     * wpsc_the_product_price_display_args filter args for product price display
     *
     * Paramters used to format price display can be set globally using this filter
     *
     * @since 4.0
     *
     * @type array $args array of parameters used to format product price
     * @type int $product_id WPeC Product ID for the current product
     */
    $r = apply_filters('wpsc_the_product_price_display_args', $r, $id);
    extract($r);
    // 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(array('type' => 'amount', 'product_id' => $id));
    $show_old_price = $show_you_save = wpsc_product_on_special($id);
    // Don't output old price HTML if not on sale.
    if (!wpsc_product_on_special($id)) {
        $output_old_price = $output_you_save = false;
    }
    // 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 ($output_old_price) {
        echo $old_price_before . $old_price_text . $old_price_after . "\n";
    }
    if ($output_price) {
        echo $price_before . $price_text . $price_after . "\n";
    }
    if ($output_you_save) {
        echo $you_save_before . $you_save_text . $you_save_after . "\n";
    }
}
						
						<input type="text" id='wpsc_quantity_update' name="wpsc_quantity_update[<?php echo wpsc_the_product_id(); ?>]" size="2" value="1"/>
						<input type="hidden" name="key" value="<?php echo wpsc_the_cart_item_key(); ?>"/>
						<input type="hidden" name="wpsc_update_quantity" value="true"/>
						</fieldset>
					<?php endif ;?>
					
						<div class="wpsc_product_price">
							<?php if(wpsc_product_is_donation()) : ?>
								<label for='donation_price_<?php echo wpsc_the_product_id(); ?>'><?php echo __('Donation', 'wpsc'); ?>:</label>
								<input type='text' id='donation_price_<?php echo wpsc_the_product_id(); ?>' name='donation_price' value='<?php echo $wpsc_query->product['price']; ?>' size='6' />
								<br />
							
							
							<?php else : ?>
								<?php if(wpsc_product_on_special()) : ?>
									<span class='oldprice'><?php echo __('Price', 'wpsc'); ?>: <?php echo wpsc_product_normal_price(); ?></span><br />
								<?php endif; ?>
								<span id="product_price_<?php echo wpsc_the_product_id(); ?>" class="pricedisplay"><?php echo wpsc_the_product_price(); ?></span><?php echo __('Price', 'wpsc'); ?>:  <br/>
								<!-- multi currency code -->
								<?php if(wpsc_product_has_multicurrency()) : ?>
								<?php echo wpsc_display_product_multicurrency(); ?>
								<?php endif; ?>
								<!-- end multi currency code -->
								<?php if(get_option('display_pnp') == 1) : ?>
									<span class="pricedisplay"><?php echo wpsc_product_postage_and_packaging(); ?></span><?php echo __('P&amp;P', 'wpsc'); ?>:  <br />
								<?php endif; ?>							
							<?php endif; ?>
						</div>
					<?php if(function_exists('wpsc_akst_share_link') && (get_option('wpsc_share_this') == 1)) {
						echo wpsc_akst_share_link('return');
function vtprd_show_product_you_save($product_id = null)
{
    global $post, $vtprd_setup_options, $vtprd_info;
    //can only be executed when WPEC version less than 3.8.9
    if (!(version_compare(strval('3.8.9'), strval(WPSC_VERSION), '>') == 1)) {
        //'==1' = 2nd value is lower
        return;
    }
    $pct = vtprd_get_single_product_you_save_pct($product_id);
    $amt = $vtprd_info['product_session_info']['product_yousave_total_amt'];
    $amt = vtprd_format_money_element($amt);
    //CUSTOM function created by CUSTOMER
    if (function_exists('custom_show_single_product_you_save')) {
        custom_show_single_product_you_save($product_id, $pct, $amt);
        return;
    }
    if ($pct) {
        ?>
				<p class="pricedisplay product_<?php 
        echo wpsc_the_product_id();
        ?>
"><?php 
        _e('You save', 'wpsc');
        ?>
: <span class="yousave" id="yousave_<?php 
        echo wpsc_the_product_id();
        ?>
"><?php 
        echo $amt;
        ?>
! (<?php 
        echo $pct;
        ?>
%)</span></p>
			<?php 
    } else {
        //original code from wpsc-single_product.php
        ?>
      
        <?php 
        if (wpsc_product_on_special()) {
            ?>
					<p class="pricedisplay product_<?php 
            echo wpsc_the_product_id();
            ?>
"><?php 
            _e('You save', 'wpsc');
            ?>
: <span class="yousave" id="yousave_<?php 
            echo wpsc_the_product_id();
            ?>
"><?php 
            echo wpsc_currency_display(wpsc_you_save('type=amount'), array('html' => false));
            ?>
! (<?php 
            echo wpsc_you_save();
            ?>
%)</span></p>
				<?php 
        }
        ?>
      
      <?php 
    }
    return;
}
function getSliderProducts($products)
{
    $products = explode(",", $products);
    global $wpsc_query, $wpdb;
    foreach ($products as $product) {
        $image_width = get_option('single_view_image_width');
        $image_height = get_option('single_view_image_height');
        $options = get_option('site_basic_options');
        $wpsc_query = new WPSC_Query(array('product_id' => $product));
        while (wpsc_have_products()) {
            wpsc_the_product();
            ?>
			<li class="feature-product">
			<?php 
            if (wpsc_the_product_thumbnail()) {
                ?>
			<div class="product-image">
				<a rel="<?php 
                echo str_replace(array(" ", '"', "'", '&quot;', '&#039;'), array("_", "", "", "", ''), wpsc_the_product_title());
                ?>
" class="thickbox preview_link" href="<?php 
                echo wpsc_the_product_image();
                ?>
">
					<img class="product_image" id="product_image_<?php 
                echo wpsc_the_product_id();
                ?>
" alt="<?php 
                echo wpsc_the_product_title();
                ?>
" title="<?php 
                echo wpsc_the_product_title();
                ?>
" src="<?php 
                if ($options['themelayout'] == 'boxed') {
                    bloginfo('template_url');
                    ?>
/timthumb.php?src=<?php 
                    echo wpsc_the_product_image($image_width, $image_height);
                    ?>
&w=457<?php 
                } else {
                    echo wpsc_the_product_image($image_width, $image_height);
                }
                ?>
" />
				</a>
			</div>
			<?php 
            } else {
                ?>
				<div class="product-image product-thumb item_no_image">
					<a href="<?php 
                echo wpsc_the_product_permalink();
                ?>
">
					<span><?php 
                _e('No Image Available', 'flexishop');
                ?>
</span>
					</a>
				</div>
			<?php 
            }
            ?>
			<div class="product-content">
			<h2 class="prodtitles">
				<?php 
            if (get_option('hide_name_link') == 1) {
                ?>
					<span><?php 
                echo wpsc_the_product_title();
                ?>
</span>
				<?php 
            } else {
                ?>
 
					<a class="wpsc_product_title" href="<?php 
                echo wpsc_the_product_permalink();
                ?>
"><?php 
                echo wpsc_the_product_title();
                ?>
</a>
				<?php 
            }
            ?>
 				
			</h2>
			<!-- <div class="wpsc_product_price">
			<?php 
            if (wpsc_product_is_donation()) {
                ?>
				<label for='donation_price_<?php 
                echo wpsc_the_product_id();
                ?>
'><?php 
                echo __('Donation', 'flexishop');
                ?>
:</label>
				<input type='text' id='donation_price_<?php 
                echo wpsc_the_product_id();
                ?>
' name='donation_price' value='<?php 
                echo $wpsc_query->product['price'];
                ?>
' size='6' />
				<br />
			
			
			<?php 
            } else {
                ?>
				<?php 
                if (wpsc_product_on_special()) {
                    ?>
					<span class='oldprice'><?php 
                    echo __('Price', 'flexishop');
                    ?>
: <?php 
                    echo wpsc_product_normal_price(get_option('wpsc_hide_decimals'));
                    ?>
</span><br />
				<?php 
                }
                ?>
				<span id="product_price_<?php 
                echo wpsc_the_product_id();
                ?>
" class="pricedisplay <?php 
                if (wpsc_product_on_special()) {
                    echo "sale-price";
                }
                ?>
"><?php 
                if (wpsc_product_on_special()) {
                    echo __("Sale Price: ", 'flexishop');
                }
                echo wpsc_the_product_price(get_option('wpsc_hide_decimals'));
                ?>
</span>					
			<?php 
            }
            ?>
			</div> -->
			<?php 
            if (wpsc_the_product_additional_description()) {
                ?>
			<div class="description">
			<?php 
                $value = '';
                $the_addl_desc = wpsc_the_product_additional_description();
                if (is_serialized($the_addl_desc)) {
                    $addl_descriptions = @unserialize($the_addl_desc);
                } else {
                    $addl_descriptions = array('addl_desc', $the_addl_desc);
                }
                if (isset($addl_descriptions['addl_desc'])) {
                    $value = $addl_descriptions['addl_desc'];
                }
                if (function_exists('wpsc_addl_desc_show')) {
                    echo wpsc_addl_desc_show($addl_descriptions);
                } else {
                    echo stripslashes(wpautop($the_addl_desc, $br = 1));
                }
                ?>
			</div>
			<?php 
            }
            ?>
			<a href="<?php 
            echo wpsc_the_product_permalink();
            ?>
" class="buy-now"><?php 
            _e('Buy Now', 'flexishop');
            ?>
</a>
			</div>
		</li>
		<?php 
        }
    }
}