<?php if (wpsc_product_is_customisable()) { ?> <input type="hidden" value="true" name="is_customisable"/> <?php } ?> <!-- END OF QUANTITY OPTION --> <?php if (get_option('hide_addtocart_button') == 0 && get_option('addtocart_or_buynow') != '1') { ?> <?php if (wpsc_product_has_stock()) { ?> <?php if (wpsc_product_external_link(wpsc_the_product_id()) != '') { ?> <?php $action = wpsc_product_external_link(wpsc_the_product_id()); ?> <input class="wpsc_buy_button" type='button' value='<?php echo __('Buy Now', 'wpsc'); ?> ' onclick='gotoexternallink("<?php echo $action; ?> ")'> <?php
/** * wpsc product has stock function * @return boolean - true if the product has stock or does not use stock, false if it does not */ function wpsc_product_has_stock($id = null) { // maybe do wpsc_clear_stock_claims first? if (is_numeric($id) && $id > 0) { $id = absint($id); } else { $id = get_the_ID(); } $stock = get_post_meta($id, '_wpsc_stock', true); if ($stock === '') { return true; } $variations = get_children(array("post_type" => "wpsc-product", "post_parent" => $id)); $filter_name = empty($variations) ? 'wpsc_product_stock' : 'wpsc_product_variation_stock'; $stock = apply_filters($filter_name, (int) $stock, $id); if (!empty($variations)) { foreach ($variations as $variation) { if (wpsc_product_has_stock($variation->ID)) { return true; } } } elseif ($stock > 0) { $claimed_query = new WPSC_Claimed_Stock(array('product_id' => $id)); $claimed_stock = $claimed_query->get_claimed_stock_count(); if ($stock - $claimed_stock > 0) { return true; } } return false; }
function wpsc_generate_product_feed() { global $wpdb, $wp_query, $post; set_time_limit(0); // Don't build up a huge posts cache for the whole store - http://code.google.com/p/wp-e-commerce/issues/detail?id=885 // WP 3.3+ only if (function_exists('wp_suspend_cache_addition')) { wp_suspend_cache_addition(true); } $chunk_size = apply_filters('wpsc_productfeed_chunk_size', 50); // Don't cache feed under WP Super-Cache define('DONOTCACHEPAGE', TRUE); $selected_category = ''; $selected_product = ''; $args = array('post_type' => 'wpsc-product', 'numberposts' => $chunk_size, 'offset' => 0, 'cache_results' => false); $args = apply_filters('wpsc_productfeed_query_args', $args); $self = site_url("/index.php?rss=true&action=product_list{$selected_category}{$selected_product}"); header("Content-Type: application/xml; charset=UTF-8"); header('Content-Disposition: inline; filename="E-Commerce_Product_List.rss"'); echo "<?xml version='1.0' encoding='UTF-8' ?>\n\r"; echo "<rss version='2.0' xmlns:atom='http://www.w3.org/2005/Atom'"; $google_checkout_note = false; if ($_GET['xmlformat'] == 'google') { echo ' xmlns:g="http://base.google.com/ns/1.0"'; // Is Google Checkout available as a payment gateway $selected_gateways = get_option('custom_gateway_options'); if (in_array('google', $selected_gateways)) { $google_checkout_note = true; } } else { echo ' xmlns:product="http://www.buy.com/rss/module/productV2/"'; } echo ">\n\r"; echo " <channel>\n\r"; echo " <title><![CDATA[" . get_option('blogname') . " Products]]></title>\n\r"; echo " <link>" . get_option('siteurl') . "/wp-admin/admin.php?page=" . WPSC_DIR_NAME . "/display-log.php</link>\n\r"; echo " <description>This is the WP e-Commerce Product List RSS feed</description>\n\r"; echo " <generator>WP e-Commerce Plugin</generator>\n\r"; echo " <atom:link href='{$self}' rel='self' type='application/rss+xml' />\n\r"; $products = get_posts($args); while (count($products)) { foreach ($products as $post) { setup_postdata($post); $purchase_link = wpsc_product_url($post->ID); echo " <item>\n\r"; if ($google_checkout_note) { echo " <g:payment_notes>Google Checkout</g:payment_notes>\n\r"; } echo " <title><![CDATA[" . get_the_title() . "]]></title>\n\r"; echo " <link>{$purchase_link}</link>\n\r"; echo " <description><![CDATA[" . apply_filters('the_content', get_the_content()) . "]]></description>\n\r"; echo " <pubDate>" . $post->post_modified_gmt . "</pubDate>\n\r"; echo " <guid>{$purchase_link}</guid>\n\r"; $image_link = wpsc_the_product_thumbnail(); if ($image_link !== FALSE) { if ($_GET['xmlformat'] == 'google') { echo " <g:image_link>{$image_link}</g:image_link>\n\r"; } else { echo " <enclosure url='{$image_link}' />\n\r"; } } $price = wpsc_calculate_price($post->ID); $currargs = array('display_currency_symbol' => false, 'display_decimal_point' => true, 'display_currency_code' => false, 'display_as_html' => false); $price = wpsc_currency_display($price, $currargs); $children = get_children(array('post_parent' => $post->ID, 'post_type' => 'wpsc-product')); foreach ($children as $child) { $child_price = wpsc_calculate_price($child->ID); if ($price == 0 && $child_price > 0) { $price = $child_price; } else { if ($child_price > 0 && $child_price < $price) { $price = $child_price; } } } if ($_GET['xmlformat'] == 'google') { echo " <g:price>" . $price . "</g:price>\n\r"; $google_elements = array(); $product_meta = get_post_custom($post->ID); if (is_array($product_meta)) { foreach ($product_meta as $meta_key => $meta_value) { if (stripos($meta_key, 'g:') === 0) { $google_elements[$meta_key] = $meta_value; } } } $google_elements = apply_filters('wpsc_google_elements', array('product_id' => $post->ID, 'elements' => $google_elements)); $google_elements = $google_elements['elements']; $done_condition = FALSE; $done_availability = FALSE; $done_weight = FALSE; if (count($google_elements)) { foreach ($google_elements as $element_name => $element_values) { foreach ($element_values as $element_value) { echo " <" . $element_name . ">"; echo "<![CDATA[" . $element_value . "]]>"; echo "</" . $element_name . ">\n\r"; } if ($element_name == 'g:shipping_weight') { $done_weight = TRUE; } if ($element_name == 'g:condition') { $done_condition = TRUE; } if ($element_name == 'g:availability') { $done_availability = true; } } } if (!$done_condition) { echo " <g:condition>new</g:condition>\n\r"; } if (!$done_availability) { if (wpsc_product_has_stock()) { $product_availability = "in stock"; } else { $product_availability = "out of stock"; } echo " <g:availability>{$product_availability}</g:availability>"; } if (!$done_weight) { $wpsc_product_meta = get_product_meta($post->ID, 'product_metadata', true); $weight = apply_filters('wpsc_google_shipping_weight', $wpsc_product_meta['weight'], $post->ID); if ($weight && is_numeric($weight) && $weight > 0) { echo "<g:shipping_weight>{$weight} pounds</g:shipping_weight>"; } } } else { echo " <product:price>" . $price . "</product:price>\n\r"; } echo " </item>\n\r"; } $args['offset'] += $chunk_size; $products = get_posts($args); } echo " </channel>\n\r"; echo "</rss>"; exit; }
/** * Renders the WPEC tickets table/form * * @version 4.2 * * @var bool $must_login */ ob_start(); $is_there_any_product = false; $is_there_any_product_to_sell = false; foreach ($tickets as $ticket) { if ($ticket->date_in_range(current_time('timestamp'))) { $is_there_any_product = true; echo '<tr>'; echo "<td width='115' class='wpec quantity' data-product-id='" . esc_attr($ticket->ID) . "'>"; if (wpsc_product_has_stock($ticket->ID)) { $is_there_any_product_to_sell = true; if (get_option('addtocart_or_buynow') == '1') { echo wpsc_buy_now_button($ticket->ID); } else { ?> <fieldset> <legend><?php esc_html_e('Quantity', 'event-tickets-plus'); ?> </legend> <div class="wpsc_quantity_update"> <input type="number" id="wpec_tickets_quantity_<?php echo esc_attr($ticket->ID); ?> " name="wpec_tickets_quantity[]" size="2" value="0" min="0" <?php
public function send_product() { if (wpsc_is_single_product()) { $product = array(); while (wpsc_have_products()) { wpsc_the_product(); $product_id = (int) wpsc_the_product_id(); $product['url'] = (string) wpsc_the_product_permalink(); $product['product_id'] = $product_id; $product['name'] = (string) wpsc_the_product_title(); $product['image_url'] = (string) wpsc_the_product_image('', '', $product_id); if (wpsc_product_has_variations($product_id)) { $price = $this->get_lowest_product_variation_price($product_id); } else { $price = wpsc_calculate_price($product_id, false, true); } $product['price'] = $this->format_price($price); if (wpsc_product_has_stock($product_id)) { $product['stock'] = 1; } else { $product['stock'] = 0; } $product['categories'] = array(); $category_terms = wp_get_product_categories($product_id); foreach ($category_terms as $category_term) { $category_path = $category_term; if (!empty($category_path)) { $product['category_name'] = $category_term->name; $product['category_id'] = $category_term->term_id; } } if (wpsc_product_has_variations($product_id)) { $list_price = $this->get_lowest_product_variation_price($product_id); } else { $list_price = wpsc_calculate_price($product_id, false, false); } $product['list_price'] = $this->format_price($list_price); } if (!empty($product)) { $this->render('sendProduct', array('product' => $product)); } } }
<?php if(wpsc_has_multi_adding()): ?> <label class='wpsc_quantity_update' for='wpsc_quantity_update[<?php echo wpsc_the_product_id(); ?>]'><?php echo __('Quantity', 'wpsc'); ?>:</label> + <input type="text" id='wpsc_quantity_update[<?php echo wpsc_the_product_id(); ?>]' name="wpsc_quantity_update" 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"/> <?php endif ;?> <input type="hidden" value="add_to_cart" name="wpsc_ajax_action"/> <input type="hidden" value="<?php echo wpsc_the_product_id(); ?>" name="product_id"/> <?php if((get_option('hide_addtocart_button') == 0) && (get_option('addtocart_or_buynow') !='1')) : ?> <?php if(wpsc_product_has_stock()) : ?> <div class='wpsc_buy_button_container'> <?php if(wpsc_product_external_link(wpsc_the_product_id()) != '') : ?> <?php $action = wpsc_product_external_link(wpsc_the_product_id()); ?> <input class="wpsc_buy_button" type='button' value='<?php echo __('Buy Now', 'wpsc'); ?>' onclick='gotoexternallink("<?php echo $action; ?>")'> <?php else: ?> <input type='image' src='<?php echo WPSC_URL; ?>/themes/iShop/images/buy_button.gif' id='product_<?php echo wpsc_the_product_id(); ?>_submit_button' class='wpsc_buy_button' name='Buy' value="<?php echo __('Add To Cart', 'wpsc'); ?>" /> <?php endif; ?> <div class='wpsc_loading_animation'> <img title="Loading" alt="Loading" src="<?php echo WPSC_URL; ?>/images/indicator.gif" class="loadingimage"/> <?php echo __('Updating cart...', 'wpsc'); ?> </div>
/** * Determine whether a product is out of stock or not. * * @since 0.1 * * @param null|int $id Optional. The product ID. Defaults to the current product in the loop. * @return bool */ function wpsc_is_product_out_of_stock($id = null) { return !wpsc_product_has_stock($id); }
/** * wpsc product has stock function * @return boolean - true if the product has stock or does not use stock, false if it does not */ function wpsc_product_has_stock($id = null) { global $wpdb; // maybe do wpsc_clear_stock_claims first? if (is_numeric($id) && $id > 0) { $id = absint($id); } else { $id = get_the_ID(); } $stock = get_post_meta($id, '_wpsc_stock', true); if ($stock === '') { return true; } $variations = get_children(array("post_type" => "wpsc-product", "post_parent" => $id)); $filter_name = empty($variations) ? 'wpsc_product_variation_stock' : 'wpsc_product_stock'; $stock = apply_filters($filter_name, (int) $stock, $id); if (!empty($variations)) { foreach ($variations as $variation) { if (wpsc_product_has_stock($variation->ID)) { return true; } } } elseif ($stock > 0) { $claimed_stock = $wpdb->get_var("SELECT SUM(`stock_claimed`) FROM `" . WPSC_TABLE_CLAIMED_STOCK . "` WHERE `product_id` IN({$id})"); if ($stock - $claimed_stock > 0) { return true; } } return false; }
/** * wpsc check variation stock availability function * @return string - the product price */ function wpsc_check_variation_stock_availability($product_id, $variations) { global $wpdb; $selected_post = (array) get_posts(array('post_parent' => $product_id, 'post_type' => "wpsc-product", 'post_status' => 'all', 'suppress_filters' => true)); foreach ($selected_post as $variation) { $matches = 0; $terms = wp_get_object_terms($variation->ID, 'wpsc-variation'); foreach ($terms as $term) { if (in_array($term->term_id, $variations)) { $matches++; } if ($matches == count($variations)) { $the_selected_product = $variation->ID; } } } if (wpsc_product_has_stock($the_selected_product)) { $stock = get_product_meta($the_selected_product, "stock", true); $stock = apply_filters('wpsc_product_variation_stock', $stock, $id); if (0 < $stock) { return $stock; } } else { $stock = get_product_meta($the_selected_product, "stock", true); $stock = apply_filters('wpsc_product_variation_stock', $stock, $id); if (is_numeric($stock)) { $claimed_stock = $wpdb->get_var("SELECT SUM(`stock_claimed`) FROM `" . WPSC_TABLE_CLAIMED_STOCK . "` WHERE `product_id` IN('{$the_selected_product}')"); $stock = $stock - $claimed_stock; return $stock; } } return ''; }
/** * wpsc buy now button code products function * Sorry about the ugly code, this is just to get the functionality back, buy now will soon be overhauled, and this function will then be completely different * @return string - html displaying one or more products */ function wpsc_buy_now_button($product_id, $replaced_shortcode = false) { $product_id = absint($product_id); $product = get_post($product_id); $supported_gateways = array('wpsc_merchant_paypal_standard', 'paypal_multiple'); $selected_gateways = get_option('custom_gateway_options'); if ($replaced_shortcode) { ob_start(); } if (in_array('wpsc_merchant_paypal_standard', (array) $selected_gateways)) { if ($product_id > 0) { $post_meta = get_post_meta($product_id, '_wpsc_product_metadata', true); $shipping = isset($post_meta['shipping']) ? $post_meta['shipping']['local'] : ''; $price = get_post_meta($product_id, '_wpsc_price', true); $special_price = get_post_meta($product_id, '_wpsc_special_price', true); if ($special_price) { $price = $special_price; } if (wpsc_uses_shipping()) { $handling = get_option('base_local_shipping'); } else { $handling = $shipping; } $has_variants = wpsc_product_has_variations($product_id) || !wpsc_product_has_stock($product_id); $src = apply_filters('wpsc_buy_now_button_src', _x('https://www.paypal.com/en_US/i/btn/btn_buynow_LG.gif', 'PayPal Buy Now Button', 'wpsc')); $classes = apply_filters('wpsc_buy_now_button_class', "wpsc-buy-now-form wpsc-buy-now-form-{$product_id}"); $classes_array = array_map('sanitize_html_class', explode(' ', $classes)); $classes = implode(' ', $classes_array); $button_html = sprintf('<input%1$s class="wpsc-buy-now-button wpsc-buy-now-button-%2$s" type="image" name="submit" border="0" src="%3$s" alt="%4$s" />', disabled($has_variants, true, false), esc_attr($product_id), esc_url($src), esc_attr__('PayPal - The safer, easier way to pay online', 'wpsc')); $button_html = apply_filters('wpsc_buy_now_button_html', $button_html, $product_id); ?> <form class="<?php echo $classes; ?> " id="buy-now-product_<?php echo $product_id; ?> " target="paypal" action="<?php echo esc_url(home_url()); ?> " method="post"> <input type="hidden" name="wpsc_buy_now_callback" value="1" /> <input type="hidden" name="product_id" value="<?php echo esc_attr($product_id); ?> " /> <?php if ($has_variants) { // grab the variation form fields here $wpsc_variations = new wpsc_variations($product_id); while (wpsc_have_variation_groups()) { wpsc_the_variation_group(); printf('<input type="hidden" class="variation-value" name="variation[%1$d]" id="%2$s" value="0"/>', wpsc_vargrp_id(), wpsc_vargrp_form_id()); } } /* END wpsc_product_has_variations */ ?> <?php if (get_option('multi_add')) { ?> <label for="quantity"><?php esc_html_e('Quantity', 'wpsc'); ?> </label> <input type="text" size="4" id="quantity" class="wpsc-buy-now-quantity" name="quantity" value="" /><br /> <?php } else { ?> <input type="hidden" name="quantity" class="wpsc-buy-now-quantity" value="1" /> <?php } ?> <?php echo $button_html; ?> <img alt='' border='0' width='1' height='1' src='<?php echo esc_url(_x('https://www.paypal.com/en_US/i/scr/pixel.gif', 'PayPal Pixel', 'wpsc')); ?> ' /> </form> <?php } } if ($replaced_shortcode) { return ob_get_clean(); } }