Exemplo n.º 1
0
/**
 * Feature a product from admin
 */
function woocommerce_feature_product()
{
    if (!is_admin()) {
        die;
    }
    if (!current_user_can('edit_posts')) {
        wp_die(__('You do not have sufficient permissions to access this page.', 'woothemes'));
    }
    if (!check_admin_referer()) {
        wp_die(__('You have taken too long. Please go back and retry.', 'woothemes'));
    }
    $post_id = isset($_GET['product_id']) && (int) $_GET['product_id'] ? (int) $_GET['product_id'] : '';
    if (!$post_id) {
        die;
    }
    $post = get_post($post_id);
    if (!$post) {
        die;
    }
    if ($post->post_type !== 'product') {
        die;
    }
    $product = new woocommerce_product($post->ID);
    if ($product->is_featured()) {
        update_post_meta($post->ID, 'featured', 'no');
    } else {
        update_post_meta($post->ID, 'featured', 'yes');
    }
    $sendback = remove_query_arg(array('trashed', 'untrashed', 'deleted', 'ids'), wp_get_referer());
    wp_safe_redirect($sendback);
}
 /**
  * Backorder notification email
  **/
 function backorder($args)
 {
     $defaults = array('product' => '', 'quantity' => '');
     $args = wp_parse_args($args, $defaults);
     extract($args);
     if (!$product || !$quantity) {
         return;
     }
     $_product = new woocommerce_product($product);
     $subject = '[' . get_bloginfo('name') . '] ' . __('Product Backorder', 'woothemes');
     $message = $this->wrap_message(__('Product Backorder', 'woothemes'), $quantity . __(' units of #', 'woothemes') . $_product->id . ' ' . $_product->get_title() . ' (' . $_product->sku . ') ' . __('have been backordered.', 'woothemes'));
     // Send the mail
     $this->send(get_option('woocommerce_stock_email_recipient'), $subject, $message);
 }
 function render_product_feed()
 {
     global $wpdb, $wp_query, $post;
     define('DONOTCACHEPAGE', TRUE);
     set_time_limit(0);
     $siteurl = home_url('/');
     $self = home_url("/index.php?action=woocommerce_storeya");
     header("Content-Type: application/xml; charset=UTF-8");
     echo "<?xml version='1.0' encoding='UTF-8' ?>\n\r";
     echo "<rss version='2.0' xmlns:atom='http://www.w3.org/2005/Atom' xmlns:g='http://base.google.com/ns/1.0'>\n";
     echo "  <channel>\n";
     echo "    <title><![CDATA[" . get_option('blogname') . " Products]]></title>\n";
     echo "    <link>" . $siteurl . "</link>\n";
     echo "    <description>StoreYa RSS feed 2.4</description>\n";
     echo "    <atom:link href='{$self}' rel='self' type='application/rss+xml' />\n";
     if (isset($this->settings['product_fields']['disable_feed'])) {
         echo "    <message>Feed was disabled.</message>\n";
         echo "  </channel>\n\r";
         echo "</rss>";
         exit;
     }
     $currency = get_option('woocommerce_currency');
     $weight_units = get_option('woocommerce_weight_unit');
     $base_country = get_option('woocommerce_base_country');
     if (!empty($base_country) && substr($base_country, 0, 2) == 'US') {
         $US_feed = true;
     } else {
         $US_feed = false;
     }
     $chunk_size = apply_filters('woocommerce_storeya_chunk_size', 20);
     $args['post_type'] = 'product';
     $args['numberposts'] = $chunk_size;
     $args['offset'] = 0;
     $products = get_posts($args);
     while (count($products)) {
         foreach ($products as $post) {
             setup_postdata($post);
             if (function_exists('get_product')) {
                 $woocommerce_product = get_product($post->ID);
             } else {
                 $woocommerce_product = new woocommerce_product($post->ID);
             }
             if ($woocommerce_product->visibility == 'hidden') {
                 continue;
             }
             if (!$woocommerce_product->is_in_stock()) {
                 continue;
             }
             if ($US_feed) {
                 $price = $woocommerce_product->get_price_excluding_tax();
             } else {
                 $price = $woocommerce_product->get_price();
             }
             if (count($woocommerce_product->children)) {
                 $children = $woocommerce_product->children;
                 if (is_array($children)) {
                     foreach ($children as $child_product) {
                         if ($US_feed) {
                             $child_price = $child_product->product->get_price_excluding_tax();
                         } else {
                             $child_price = $child_product->product->get_price();
                         }
                         if ($price == 0 && $child_price > 0) {
                             $price = $child_price;
                         } else {
                             if ($child_price > 0 && $child_price < $price) {
                                 $price = $child_price;
                             }
                         }
                     }
                 }
             }
             if (empty($price)) {
                 continue;
             }
             $price = number_format($price, 2, '.', '');
             $purchase_link = get_permalink($post->ID);
             echo "    <item>\n\r";
             echo "      <title><![CDATA[" . get_the_title() . "]]></title>\n\r";
             echo "      <link>{$purchase_link}</link>\n\r";
             echo "      <description><![CDATA[" . substr(apply_filters('the_content', get_the_content()), 0, 10000) . "]]></description>\n\r";
             echo " <description_short><![CDATA[" . get_post_field(post_excerpt, $post->ID) . "]]></description_short>\n\r";
             echo "      <guid>woocommerce_storeya_" . $post->ID . "</guid>\n\r";
             $image_link = $this->get_the_post_thumbnail_src($post->ID, 'shop_large');
             if (!empty($image_link)) {
                 echo "      <g:image_link>{$image_link}</g:image_link>\n\r";
             }
             echo "      <g:price>{$price} {$currency}</g:price>\n\r";
             $google_elements = apply_filters('woocommerce_storeya_elements', array(), $post->ID);
             $done_condition = FALSE;
             $done_weight = FALSE;
             if (count($google_elements)) {
                 foreach ($google_elements as $element_name => $element_values) {
                     foreach ($element_values as $element_value) {
                         if ('g:availability' == $element_name) {
                             if (!$woocommerce_product->is_in_stock()) {
                                 $element_value = 'out of stock';
                             }
                         }
                         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 (!$done_condition) {
                 echo "      <g:condition>new</g:condition>\n\r";
             }
             if (!$done_weight) {
                 $weight = apply_filters('woocommerce_storeya_shipping_weight', $woocommerce_product->get_weight(), $post->ID);
                 if ($weight_units == 'lbs') {
                     $weight_units = 'lb';
                 }
                 if ($weight && is_numeric($weight) && $weight > 0) {
                     echo "      <g:shipping_weight>{$weight} {$weight_units}</g:shipping_weight>";
                 }
             }
             echo "    </item>\n\r";
         }
         $args['offset'] += $chunk_size;
         $products = get_posts($args);
     }
     echo "  </channel>\n\r";
     echo "</rss>";
     exit;
 }
 /**
  * Increase stock level of the product
  *
  * @param   int		$by		Amount to increase by
  */
 function increase_stock($by = 1)
 {
     if ($this->variation_has_stock) {
         if ($this->managing_stock()) {
             $this->stock = $this->stock + $by;
             $this->total_stock = $this->get_total_stock() + $by;
             update_post_meta($this->variation_id, 'stock', $this->stock);
             // Parents out of stock attribute
             if ($this->is_in_stock()) {
                 update_post_meta($this->id, 'stock_status', 'instock');
             }
             return $this->stock;
         }
     } else {
         return parent::increase_stock($by);
     }
 }