get_title() public method

Get the product's title. For products this is the product name.
public get_title ( ) : string
return string
 protected function get_name(WC_Product $product)
 {
     if ($product->get_sku()) {
         $identifier = $product->get_sku();
     } else {
         $identifier = '#' . (isset($product->variation_id) ? $product->variation_id : $product->id);
     }
     return sprintf('%s - %s', $identifier, $product->get_title());
 }
Ejemplo n.º 2
0
 public function ajax_get_products_per_period()
 {
     $product_num = isset($_POST['product_num']) ? $_POST['product_num'] : 10;
     $start_date = isset($_POST['start_date']) ? $_POST['start_date'] : null;
     $end_date = isset($_POST['end_date']) ? $_POST['end_date'] : null;
     $results = [];
     $stats = $this->get_products_per_period(100, $start_date, $end_date);
     //wcds_var_dump($stats);
     /*Format:
     		array(4) {
     		  [0]=>
     		  array(4) {
     			["total_earning"]=>
     			string(1) "4"
     			["total_purchases"]=>
     			string(1) "4"
     			["prod_id"]=>
     			string(2) "12"
     			["prod_variation_id"]=>
     			string(1) "0"
     		  }
     		  */
     $counter = 0;
     $wpml_helper = new WCDS_Wpml();
     foreach ($stats as $prod_id => $product) {
         //WPML: Merge product stats by id
         $stats[$prod_id]['total_earning'] = round($product['total_earning'], 2);
         $stats[$prod_id]['permalink'] = get_permalink($prod_id);
         if ($wpml_helper->wpml_is_active()) {
             $original_id = $wpml_helper->get_original_id($prod_id);
             $product_temp = new WC_Product($original_id);
             $stats[$prod_id]['prod_title'] = $product_temp->get_title();
             $stats[$prod_id]['permalink'] = get_permalink($original_id);
             //wcds_var_dump($prod_id." -> ".$original_id);
             if (!isset($results[$original_id])) {
                 //wcds_var_dump("new");
                 $results[$original_id] = $stats[$prod_id];
             } else {
                 //wcds_var_dump("update");
                 $results[$original_id]["total_earning"] += $product["total_purchases"];
                 $results[$original_id]["total_earning"] += $product["total_earning"];
                 $results[$original_id]["total_earning"] = round($results[$original_id]['total_earning'], 2);
             }
         } else {
             $results[$prod_id] = $stats[$prod_id];
         }
         if (++$counter == $product_num) {
             break;
         }
     }
     usort($results, function ($a, $b) {
         return $b['total_earning'] - $a['total_earning'];
     });
     echo json_encode($results);
     wp_die();
 }
 /**
  * Convert a WC Product into a Square Item for Update
  *
  * Updates (PUT) don't accept the same parameters (namely variations) as Creation
  * See: https://docs.connect.squareup.com/api/connect/v1/index.html#put-itemid
  *
  * @param WC_Product $wc_product
  * @param bool       $include_category
  * @return array
  */
 public static function format_wc_product_update_for_square_api(WC_Product $wc_product, $include_category = false)
 {
     $formatted = array('name' => $wc_product->get_title(), 'description' => $wc_product->post->post_content, 'visibility' => 'PUBLIC');
     if ($include_category) {
         if ($square_cat_id = self::get_square_category_id_for_wc_product($wc_product)) {
             $formatted['category_id'] = $square_cat_id;
         }
     }
     return array_filter($formatted);
 }
Ejemplo n.º 4
0
    /**
     * widget function.
     *
     * @see WP_Widget
     * @access public
     * @param array $args
     * @param array $instance
     * @return void
     */
    function widget($args, $instance)
    {
        global $comments, $comment, $woocommerce;
        $cache = wp_cache_get('widget_recent_reviews', 'widget');
        if (!is_array($cache)) {
            $cache = array();
        }
        if (isset($cache[$args['widget_id']])) {
            echo $cache[$args['widget_id']];
            return;
        }
        ob_start();
        extract($args);
        $title = apply_filters('widget_title', empty($instance['title']) ? __('Recent Reviews', 'woocommerce') : $instance['title'], $instance, $this->id_base);
        if (!($number = absint($instance['number']))) {
            $number = 5;
        }
        $comments = get_comments(array('number' => $number, 'status' => 'approve', 'post_status' => 'publish', 'post_type' => 'product'));
        if ($comments) {
            echo $before_widget;
            if ($title) {
                echo $before_title . $title . $after_title;
            }
            echo '<ul class="product_list_widget">';
            foreach ((array) $comments as $comment) {
                $_product = new WC_Product($comment->comment_post_ID);
                $star_size = apply_filters('woocommerce_star_rating_size_recent_reviews', 16);
                $rating = get_comment_meta($comment->comment_ID, 'rating', true);
                $rating_html = '<div class="star-rating" title="' . $rating . '">
					<span style="width:' . $rating * $star_size . 'px">' . $rating . ' ' . __('out of 5', 'woocommerce') . '</span>
				</div>';
                echo '<li><a href="' . esc_url(get_comment_link($comment->comment_ID)) . '">';
                echo $_product->get_image();
                echo $_product->get_title() . '</a>';
                echo $rating_html;
                printf(_x('by %1$s', 'by comment author', 'woocommerce'), get_comment_author()) . '</li>';
            }
            echo '</ul>';
            echo $after_widget;
        }
        $content = ob_get_clean();
        if (isset($args['widget_id'])) {
            $cache[$args['widget_id']] = $content;
        }
        echo $content;
        wp_cache_set('widget_recent_reviews', $cache, 'widget');
    }
 /**
  * Get product data.
  *
  * @param WC_Product $product
  * @return array
  */
 protected function get_product_data($product)
 {
     $data = array('id' => (int) $product->is_type('variation') ? $product->get_variation_id() : $product->id, 'name' => $product->get_title(), 'slug' => $product->get_post_data()->post_name, 'permalink' => $product->get_permalink(), 'date_created' => wc_rest_prepare_date_response($product->get_post_data()->post_date_gmt), 'date_modified' => wc_rest_prepare_date_response($product->get_post_data()->post_modified_gmt), 'type' => $product->product_type, 'status' => $product->get_post_data()->post_status, 'featured' => $product->is_featured(), 'catalog_visibility' => $product->visibility, 'description' => wpautop(do_shortcode($product->get_post_data()->post_content)), 'short_description' => apply_filters('woocommerce_short_description', $product->get_post_data()->post_excerpt), 'sku' => $product->get_sku(), 'price' => $product->get_price(), 'regular_price' => $product->get_regular_price(), 'sale_price' => $product->get_sale_price() ? $product->get_sale_price() : '', 'date_on_sale_from' => $product->sale_price_dates_from ? date('Y-m-d', $product->sale_price_dates_from) : '', 'date_on_sale_to' => $product->sale_price_dates_to ? date('Y-m-d', $product->sale_price_dates_to) : '', 'price_html' => $product->get_price_html(), 'on_sale' => $product->is_on_sale(), 'purchasable' => $product->is_purchasable(), 'total_sales' => (int) get_post_meta($product->id, 'total_sales', true), 'virtual' => $product->is_virtual(), 'downloadable' => $product->is_downloadable(), 'downloads' => $this->get_downloads($product), 'download_limit' => '' !== $product->download_limit ? (int) $product->download_limit : -1, 'download_expiry' => '' !== $product->download_expiry ? (int) $product->download_expiry : -1, 'download_type' => $product->download_type ? $product->download_type : 'standard', 'external_url' => $product->is_type('external') ? $product->get_product_url() : '', 'button_text' => $product->is_type('external') ? $product->get_button_text() : '', 'tax_status' => $product->get_tax_status(), 'tax_class' => $product->get_tax_class(), 'manage_stock' => $product->managing_stock(), 'stock_quantity' => $product->get_stock_quantity(), 'in_stock' => $product->is_in_stock(), 'backorders' => $product->backorders, 'backorders_allowed' => $product->backorders_allowed(), 'backordered' => $product->is_on_backorder(), 'sold_individually' => $product->is_sold_individually(), 'weight' => $product->get_weight(), 'dimensions' => array('length' => $product->get_length(), 'width' => $product->get_width(), 'height' => $product->get_height()), 'shipping_required' => $product->needs_shipping(), 'shipping_taxable' => $product->is_shipping_taxable(), 'shipping_class' => $product->get_shipping_class(), 'shipping_class_id' => (int) $product->get_shipping_class_id(), 'reviews_allowed' => 'open' === $product->get_post_data()->comment_status, 'average_rating' => wc_format_decimal($product->get_average_rating(), 2), 'rating_count' => (int) $product->get_rating_count(), 'related_ids' => array_map('absint', array_values($product->get_related())), 'upsell_ids' => array_map('absint', $product->get_upsells()), 'cross_sell_ids' => array_map('absint', $product->get_cross_sells()), 'parent_id' => $product->is_type('variation') ? $product->parent->id : $product->get_post_data()->post_parent, 'purchase_note' => wpautop(do_shortcode(wp_kses_post($product->purchase_note))), 'categories' => $this->get_taxonomy_terms($product), 'tags' => $this->get_taxonomy_terms($product, 'tag'), 'images' => $this->get_images($product), 'attributes' => $this->get_attributes($product), 'default_attributes' => $this->get_default_attributes($product), 'variations' => array(), 'grouped_products' => array(), 'menu_order' => $this->get_product_menu_order($product));
     return $data;
 }
Ejemplo n.º 6
0
 private function get_product_from_post($post_id)
 {
     $woocommerce_ver_below_2_1 = false;
     if (version_compare(WOOCOMMERCE_VERSION, '2.1', '<')) {
         $woocommerce_ver_below_2_1 = true;
     }
     if ($woocommerce_ver_below_2_1) {
         $product = new WC_Product_Simple($post_id);
     } else {
         $product = new WC_Product($post_id);
     }
     //$post_categories = wp_get_post_categories( $post_id );
     //$categories = get_the_category();
     try {
         $thumbnail = $product->get_image();
         if ($thumbnail) {
             if (preg_match('/data-lazy-src="([^\\"]+)"/s', $thumbnail, $match)) {
                 $thumbnail = $match[1];
             } else {
                 if (preg_match('/data-lazy-original="([^\\"]+)"/s', $thumbnail, $match)) {
                     $thumbnail = $match[1];
                 } else {
                     if (preg_match('/lazy-src="([^\\"]+)"/s', $thumbnail, $match)) {
                         // Animate Lazy Load Wordpress Plugin
                         $thumbnail = $match[1];
                     } else {
                         if (preg_match('/data-echo="([^\\"]+)"/s', $thumbnail, $match)) {
                             $thumbnail = $match[1];
                         } else {
                             preg_match('/<img(.*)src(.*)=(.*)"(.*)"/U', $thumbnail, $result);
                             $thumbnail = array_pop($result);
                         }
                     }
                 }
             }
         }
     } catch (Exception $e) {
         $err_msg = "exception raised in thumbnails";
         self::send_error_report($err_msg);
         $thumbnail = '';
     }
     // handling scheduled sale price update
     if (!$woocommerce_ver_below_2_1) {
         $sale_price_dates_from = get_post_meta($post_id, '_sale_price_dates_from', true);
         $sale_price_dates_to = get_post_meta($post_id, '_sale_price_dates_to', true);
         if ($sale_price_dates_from || $sale_price_dates_to) {
             self::schedule_sale_price_update($post_id, null);
         }
         if ($sale_price_dates_from) {
             self::schedule_sale_price_update($post_id, $sale_price_dates_from);
         }
         if ($sale_price_dates_to) {
             self::schedule_sale_price_update($post_id, $sale_price_dates_to);
         }
     }
     $product_tags = array();
     foreach (wp_get_post_terms($post_id, 'product_tag') as $tag) {
         $product_tags[] = $tag->name;
     }
     $product_brands = array();
     if (taxonomy_exists('product_brand')) {
         foreach (wp_get_post_terms($post_id, 'product_brand') as $brand) {
             $product_brands[] = $brand->name;
         }
     }
     $taxonomies = array();
     try {
         $all_taxonomies = get_option('wcis_taxonomies');
         if (is_array($all_taxonomies)) {
             foreach ($all_taxonomies as $taxonomy) {
                 if (taxonomy_exists($taxonomy) && !array_key_exists($taxonomy, $taxonomies)) {
                     foreach (wp_get_post_terms($post_id, $taxonomy) as $taxonomy_value) {
                         if (!array_key_exists($taxonomy, $taxonomies)) {
                             $taxonomies[$taxonomy] = array();
                         }
                         $taxonomies[$taxonomy][] = $taxonomy_value->name;
                     }
                 }
             }
         }
     } catch (Exception $e) {
     }
     $acf_fields = array();
     try {
         if (class_exists('acf') && function_exists('get_field')) {
             $all_acf_fields = get_option('wcis_acf_fields');
             if (is_array($all_acf_fields)) {
                 foreach ($all_acf_fields as $acf_field_name) {
                     $acf_field_value = get_field($acf_field_name, $post_id);
                     if ($acf_field_value) {
                         $acf_fields[$acf_field_name] = $acf_field_value;
                     }
                 }
             }
         }
     } catch (Exception $e) {
     }
     $send_product = array('product_id' => $product->id, 'currency' => get_woocommerce_currency(), 'price' => $product->get_price(), 'url' => get_permalink($product->id), 'thumbnail_url' => $thumbnail, 'action' => 'insert', 'description' => $product->get_post_data()->post_content, 'short_description' => $product->get_post_data()->post_excerpt, 'name' => $product->get_title(), 'sku' => $product->get_sku(), 'categories' => $product->get_categories(), 'tag' => $product_tags, 'store_id' => get_current_blog_id(), 'identifier' => (string) $product->id, 'product_brand' => $product_brands, 'taxonomies' => $taxonomies, 'acf_fields' => $acf_fields, 'sellable' => $product->is_purchasable(), 'visibility' => $product->is_visible(), 'stock_quantity' => $product->get_stock_quantity(), 'is_managing_stock' => $product->managing_stock(), 'is_backorders_allowed' => $product->backorders_allowed(), 'is_purchasable' => $product->is_purchasable(), 'is_in_stock' => $product->is_in_stock(), 'product_status' => get_post_status($post_id));
     try {
         $variable = new WC_Product_Variable($post_id);
         $variations = $variable->get_available_variations();
         $variations_sku = '';
         if (!empty($variations)) {
             foreach ($variations as $variation) {
                 if ($product->get_sku() != $variation['sku']) {
                     $variations_sku .= $variation['sku'] . ' ';
                 }
             }
         }
         $send_product['variations_sku'] = $variations_sku;
         $all_attributes = $product->get_attributes();
         $attributes = array();
         if (!empty($all_attributes)) {
             foreach ($all_attributes as $attr_mame => $value) {
                 if ($all_attributes[$attr_mame]['is_taxonomy']) {
                     if (!$woocommerce_ver_below_2_1) {
                         $attributes[$attr_mame] = wc_get_product_terms($post_id, $attr_mame, array('fields' => 'names'));
                     } else {
                         $attributes[$attr_mame] = woocommerce_get_product_terms($post_id, $attr_mame, 'names');
                     }
                 } else {
                     $attributes[$attr_mame] = $product->get_attribute($attr_mame);
                 }
             }
         }
         $send_product['attributes'] = $attributes;
         $send_product['total_variable_stock'] = $variable->get_total_stock();
         try {
             if (version_compare(WOOCOMMERCE_VERSION, '2.2', '>=')) {
                 if (function_exists('wc_get_product')) {
                     $original_product = wc_get_product($product->id);
                     if (is_object($original_product)) {
                         $send_product['visibility'] = $original_product->is_visible();
                         $send_product['product_type'] = $original_product->product_type;
                     }
                 }
             } else {
                 if (function_exists('get_product')) {
                     $original_product = get_product($product->id);
                     if (is_object($original_product)) {
                         $send_product['visibility'] = $original_product->is_visible();
                         $send_product['product_type'] = $original_product->product_type;
                     }
                 }
             }
         } catch (Exception $e) {
         }
     } catch (Exception $e) {
         $err_msg = "exception raised in attributes";
         self::send_error_report($err_msg);
     }
     if (!$woocommerce_ver_below_2_1) {
         try {
             $send_product['price_compare_at_price'] = $product->get_regular_price();
             $send_product['price_min'] = $variable->get_variation_price('min');
             $send_product['price_max'] = $variable->get_variation_price('max');
             $send_product['price_min_compare_at_price'] = $variable->get_variation_regular_price('min');
             $send_product['price_max_compare_at_price'] = $variable->get_variation_regular_price('max');
         } catch (Exception $e) {
             $send_product['price_compare_at_price'] = null;
             $send_product['price_min'] = null;
             $send_product['price_max'] = null;
             $send_product['price_min_compare_at_price'] = null;
             $send_product['price_max_compare_at_price'] = null;
         }
     } else {
         $send_product['price_compare_at_price'] = null;
         $send_product['price_min'] = null;
         $send_product['price_max'] = null;
         $send_product['price_min_compare_at_price'] = null;
         $send_product['price_max_compare_at_price'] = null;
     }
     $send_product['description'] = self::content_filter_shortcode_with_content($send_product['description']);
     $send_product['short_description'] = self::content_filter_shortcode_with_content($send_product['short_description']);
     $send_product['description'] = self::content_filter_shortcode($send_product['description']);
     $send_product['short_description'] = self::content_filter_shortcode($send_product['short_description']);
     try {
         if (defined('ICL_SITEPRESS_VERSION') && is_plugin_active('woocommerce-multilingual/wpml-woocommerce.php') && function_exists('wpml_get_language_information')) {
             if (version_compare(ICL_SITEPRESS_VERSION, '3.2', '>=')) {
                 $language_info = apply_filters('wpml_post_language_details', NULL, $post_id);
             } else {
                 $language_info = wpml_get_language_information($post_id);
             }
             if ($language_info && is_array($language_info) && array_key_exists('locale', $language_info)) {
                 // WP_Error could be returned from wpml_get_language_information(...)
                 $send_product['lang'] = $language_info['locale'];
             }
         }
     } catch (Exception $e) {
     }
     return $send_product;
 }
/**
 * Composited product title template.
 *
 * @param  WC_Product           $product
 * @param  string               $component_id
 * @param  WC_Product_Composite $composite
 * @return void
 */
function wc_cp_composited_product_title($product, $component_id, $composite)
{
    $component_data = $composite->get_component_data($component_id);
    $hide_product_title = isset($component_data['hide_product_title']) ? $component_data['hide_product_title'] : 'no';
    $show_selection_ui = true;
    if ($composite->is_component_static($component_id)) {
        $show_selection_ui = false;
    }
    // Current selection title.
    if ($hide_product_title !== 'yes') {
        if ($show_selection_ui) {
            wc_get_template('composited-product/selection.php', array('component_id' => $component_id, 'composite' => $composite), '', WC_CP()->plugin_path() . '/templates/');
        }
        wc_get_template('composited-product/title.php', array('title' => $product->get_title(), 'product_id' => $product->id, 'component_id' => $component_id, 'composite' => $composite, 'quantity' => ''), '', WC_CP()->plugin_path() . '/templates/');
    }
    // Clear current selection.
    if ($show_selection_ui) {
        ?>
<p class="component_section_title clear_component_options_wrapper">
			<a class="clear_component_options" href="#clear_component"><?php 
        echo __('Clear selection', 'woocommerce-composite-products');
        ?>
</a>
		</p><?php 
    }
}
        public function wc_add_to_cart_message($message, $product_id)
        {
            $integration = $this->load_integration();
            if (empty($integration->get_option('facebookpixel'))) {
                return;
            }
            $product = new WC_Product($product_id);
            ob_start('tracker');
            ?>

            <img height="1" width="1" style="display:none"
            src="https://www.facebook.com/tr?<?php 
            echo http_build_query(array('id' => $integration->get_option('facebookpixel'), 'ev' => 'AddToCart', 'noscript' => 1, 'content_ids' => $product->get_sku(), 'content_name' => $product->get_title(), 'currency' => get_woocommerce_currency(), 'value' => $product->get_price(), 'content_type' => 'product'));
            ?>
"/>

            <?php 
            $_tracker = ob_get_clean();
            $message .= ' ' . $_tracker;
            return $message;
        }
 /**
  * Bundles with subscriptions can't be composited.
  *
  * @param  boolean     $passed
  * @param  WC_Product  $bundle
  * @return boolean
  */
 public static function disallow_bundled_item_subs($passed, $bundle)
 {
     if ($bundle->contains_sub()) {
         wc_add_notice(sprintf(__('The configuration you have selected cannot be added to the cart. &quot;%s&quot; cannot be purchased.', 'woocommerce-product-bundles'), $bundle->get_title()), 'error');
         return false;
     }
     return $passed;
 }
Ejemplo n.º 10
0
 /**
  * Gets an individual ticket
  *
  * @param $event_id
  * @param $ticket_id
  *
  * @return null|Tribe__Tickets__Ticket_Object
  */
 public function get_ticket($event_id, $ticket_id)
 {
     if (class_exists('WC_Product_Simple')) {
         $product = new WC_Product_Simple($ticket_id);
     } else {
         $product = new WC_Product($ticket_id);
     }
     if (!$product) {
         return null;
     }
     $return = new Tribe__Tickets__Ticket_Object();
     $product_data = $product->get_post_data();
     $qty = get_post_meta($ticket_id, 'total_sales', true);
     $return->description = $product_data->post_excerpt;
     $return->frontend_link = get_permalink($ticket_id);
     $return->ID = $ticket_id;
     $return->name = $product->get_title();
     $return->price = $product->get_price();
     $return->regular_price = $product->get_regular_price();
     $return->on_sale = (bool) $product->is_on_sale();
     $return->provider_class = get_class($this);
     $return->admin_link = admin_url(sprintf(get_post_type_object($product_data->post_type)->_edit_link . '&action=edit', $ticket_id));
     $return->start_date = get_post_meta($ticket_id, '_ticket_start_date', true);
     $return->end_date = get_post_meta($ticket_id, '_ticket_end_date', true);
     $return->purchase_limit = get_post_meta($ticket_id, '_ticket_purchase_limit', true);
     $complete_totals = $this->count_order_items_by_status($ticket_id, 'complete');
     $pending_totals = $this->count_order_items_by_status($ticket_id, 'incomplete');
     $qty = $qty ? $qty : 0;
     $pending = $pending_totals['total'] ? $pending_totals['total'] : 0;
     // if any orders transitioned from complete back to one of the incomplete states, their quantities
     // were already recorded in total_sales and we have to deduct them from there so they aren't
     // double counted
     $qty -= $pending_totals['recorded_sales'];
     // let's calculate the stock based on the product stock minus the quantity purchased minus the
     // pending purchases
     $stock = $product->get_stock_quantity() - $qty - $pending;
     // if any orders have reduced the stock of an order (check and cash on delivery payments do this, for example)
     // we need to re-inflate the stock by that amount
     $stock += $pending_totals['reduced_stock'];
     $stock += $complete_totals['reduced_stock'];
     $return->manage_stock($product->managing_stock());
     $return->stock($stock);
     $return->qty_sold($qty);
     $return->qty_pending($pending);
     $return->qty_cancelled($this->get_cancelled($ticket_id));
     if (empty($return->purchase_limit) && 0 !== (int) $return->purchase_limit) {
         /**
          * Filter the default purchase limit for the ticket
          *
          * @var int
          *
          * @return int
          */
         $return->purchase_limit = apply_filters('tribe_tickets_default_purchase_limit', 0);
     }
     return apply_filters('wootickets_get_ticket', $return, $event_id, $ticket_id);
 }
Ejemplo n.º 11
0
 /**
  * Gets a user's downloadable products if they are logged in
  *
  * @return   array	downloads	Array of downloadable products
  */
 function get_downloadable_products()
 {
     global $wpdb;
     $downloads = array();
     if (is_user_logged_in()) {
         $user_info = get_userdata(get_current_user_id());
         $results = $wpdb->get_results($wpdb->prepare("SELECT * FROM " . $wpdb->prefix . "woocommerce_downloadable_product_permissions WHERE user_id = '%s';", get_current_user_id()));
         if ($results) {
             foreach ($results as $result) {
                 if ($result->order_id > 0) {
                     $order = new WC_Order($result->order_id);
                     if ($order->status != 'completed' && $order->status != 'processing') {
                         continue;
                     }
                     $product_post = get_post($result->product_id);
                     if ($product_post->post_type == 'product_variation') {
                         $_product = new WC_Product_Variation($result->product_id);
                     } else {
                         $_product = new WC_Product($result->product_id);
                     }
                     if ($_product->exists) {
                         $download_name = $_product->get_title();
                     } else {
                         $download_name = '#' . $result->product_id;
                     }
                     $downloads[] = array('download_url' => add_query_arg('download_file', $result->product_id, add_query_arg('order', $result->order_key, add_query_arg('email', $user_info->user_email, home_url()))), 'product_id' => $result->product_id, 'download_name' => $download_name, 'order_id' => $order->id, 'order_key' => $order->order_key, 'downloads_remaining' => $result->downloads_remaining);
                 }
             }
         }
     }
     return apply_filters('woocommerce_customer_get_downloadable_products', $downloads);
 }
Ejemplo n.º 12
0
 /**
  * @param string $content
  * @param License $license
  *
  * @return string
  */
 private function replace_expiration_vars($content, $license)
 {
     // get user
     $user = get_user_by('id', $license->get_user_id());
     // get first name
     $fname = 'there';
     if (!empty($user) && !empty($user->first_name)) {
         $fname = $user->first_name;
     }
     // get WooCommerce product object
     $wc_product = new \WC_Product($license->get_product_id());
     // get parent product if the product has one
     if (0 != $wc_product->get_parent()) {
         $wc_product = new \WC_Product($wc_product->get_parent());
     }
     $content = str_ireplace(':fname:', $fname, $content);
     $content = str_ireplace(':product:', $wc_product->get_title(), $content);
     $content = str_ireplace(':license-key:', $license->get_key(), $content);
     $content = str_ireplace(':license-expiration-date:', $license->get_date_expires() ? $license->get_date_expires()->format('M d Y') : '', $content);
     $content = str_ireplace(':renewal-link:', $license->get_renewal_url(), $content);
     return $content;
 }
Ejemplo n.º 13
0
    /**
     * WCMp Product Report sorting
     */
    function product_report_sort()
    {
        global $WCMp;
        $sort_choosen = isset($_POST['sort_choosen']) ? $_POST['sort_choosen'] : '';
        $report_array = isset($_POST['report_array']) ? $_POST['report_array'] : array();
        $report_bk = isset($_POST['report_bk']) ? $_POST['report_bk'] : array();
        $max_total_sales = isset($_POST['max_total_sales']) ? $_POST['max_total_sales'] : 0;
        $total_sales_sort = isset($_POST['total_sales_sort']) ? $_POST['total_sales_sort'] : array();
        $admin_earning_sort = isset($_POST['admin_earning_sort']) ? $_POST['admin_earning_sort'] : array();
        $i = 0;
        $max_value = 10;
        $report_sort_arr = array();
        if ($sort_choosen == 'total_sales_desc') {
            arsort($total_sales_sort);
            foreach ($total_sales_sort as $product_id => $value) {
                if ($i++ < $max_value) {
                    $report_sort_arr[$product_id]['total_sales'] = $report_bk[$product_id]['total_sales'];
                    $report_sort_arr[$product_id]['admin_earning'] = $report_bk[$product_id]['admin_earning'];
                }
            }
        } else {
            if ($sort_choosen == 'total_sales_asc') {
                asort($total_sales_sort);
                foreach ($total_sales_sort as $product_id => $value) {
                    if ($i++ < $max_value) {
                        $report_sort_arr[$product_id]['total_sales'] = $report_bk[$product_id]['total_sales'];
                        $report_sort_arr[$product_id]['admin_earning'] = $report_bk[$product_id]['admin_earning'];
                    }
                }
            } else {
                if ($sort_choosen == 'admin_earning_desc') {
                    arsort($admin_earning_sort);
                    foreach ($admin_earning_sort as $product_id => $value) {
                        if ($i++ < $max_value) {
                            $report_sort_arr[$product_id]['total_sales'] = $report_bk[$product_id]['total_sales'];
                            $report_sort_arr[$product_id]['admin_earning'] = $report_bk[$product_id]['admin_earning'];
                        }
                    }
                } else {
                    if ($sort_choosen == 'admin_earning_asc') {
                        asort($admin_earning_sort);
                        foreach ($admin_earning_sort as $product_id => $value) {
                            if ($i++ < $max_value) {
                                $report_sort_arr[$product_id]['total_sales'] = $report_bk[$product_id]['total_sales'];
                                $report_sort_arr[$product_id]['admin_earning'] = $report_bk[$product_id]['admin_earning'];
                            }
                        }
                    }
                }
            }
        }
        $report_chart = $report_html = '';
        if (sizeof($report_sort_arr) > 0) {
            foreach ($report_sort_arr as $product_id => $sales_report) {
                $width = $sales_report['total_sales'] > 0 ? round($sales_report['total_sales']) / round($max_total_sales) * 100 : 0;
                $width2 = $sales_report['admin_earning'] > 0 ? round($sales_report['admin_earning']) / round($max_total_sales) * 100 : 0;
                $product = new WC_Product($product_id);
                $product_url = admin_url('post.php?post=' . $product_id . '&action=edit');
                $report_chart .= '<tr><th><a href="' . $product_url . '">' . $product->get_title() . '</a></th>
					<td width="1%"><span>' . woocommerce_price($sales_report['total_sales']) . '</span><span class="alt">' . woocommerce_price($sales_report['admin_earning']) . '</span></td>
					<td class="bars">
						<span style="width:' . esc_attr($width) . '%">&nbsp;</span>
						<span class="alt" style="width:' . esc_attr($width2) . '%">&nbsp;</span>
					</td></tr>';
            }
            $report_html = '
				<h4>' . __("Sales and Earnings", $WCMp->text_domain) . '</h4>
				<div class="bar_indecator">
					<div class="bar1">&nbsp;</div>
					<span class="">' . __("Gross Sales", $WCMp->text_domain) . '</span>
					<div class="bar2">&nbsp;</div>
					<span class="">' . __("My Earnings", $WCMp->text_domain) . '</span>
				</div>
				<table class="bar_chart">
					<thead>
						<tr>
							<th>' . __("Month", $WCMp->text_domain) . '</th>
							<th colspan="2">' . __("Sales Report", $WCMp->text_domain) . '</th>
						</tr>
					</thead>
					<tbody>
						' . $report_chart . '
					</tbody>
				</table>
			';
        } else {
            $report_html = '<tr><td colspan="3">' . __('No product was sold in the given period.', $WCMp->text_domain) . '</td></tr>';
        }
        echo $report_html;
        die;
    }
Ejemplo n.º 14
0
    public function woocommerce_cart_items_meta_box($post)
    {
        global $woocommerce;
        $order_items = (array) maybe_unserialize(get_post_meta($post->ID, 'av8_cartitems', true));
        ?>
	<div class="woocommerce_cart_reports_items_wrapper">
	<?php 
        if (sizeof($order_items) > 0) {
            ?>
		<table cellpadding="0" width="100%" cellspacing="0" class="woocommerce_cart_reports_items">
			<thead >
				<tr>
					<th class="thumb"  width="20%" style="text-align:left;"><?php 
            _e('Item', 'woocommerce');
            ?>
</th>

					<th class="sku"   width="20%" style="text-align:left"><?php 
            _e('SKU', 'woocommerce');
            ?>
</th>

					<th class="name"  width="20%" style="text-align:left"><?php 
            _e('Name', 'woocommerce');
            ?>
</th>

					<th class="price"  width="20%" style="text-align:left"><?php 
            _e('Price', 'woocommerce');
            ?>
</th>

					<?php 
            //do_action('woocommerce_admin_order_item_headers');
            ?>
					
					<th class="quantity"  width="20%" style="text-align:left"><?php 
            _e('Qty', 'woocommerce');
            ?>
</th>
										
				</tr>
			</thead>
			<tbody id="cart_items_list">	
			
			
				<?php 
        }
        $loop = 0;
        if (sizeof($order_items) > 0) {
            foreach ($order_items as $item) {
                if (isset($item['variation_id']) && $item['variation_id'] > 0) {
                    if (function_exists('get_product')) {
                        $_product = get_product($item['variation_id']);
                    } else {
                        $_product = new WC_Product($item['variation_id']);
                    }
                } else {
                    if (function_exists('get_product')) {
                        $_product = get_product($item['product_id']);
                    } else {
                        $_product = new WC_Product($item['product_id']);
                    }
                }
                // Totals - Backwards Compatibility
                if ($loop % 2 == 0) {
                    $table_color = " td1 ";
                } else {
                    $table_color = " td2 ";
                }
                ?>
					
					<?php 
                if (isset($_product) && $_product != false) {
                    ?>
					
					<tr class="item <?php 
                    echo $table_color;
                    ?>
" rel="<?php 
                    echo $loop;
                    ?>
">
						<td class="thumb" width="20%">
							<a href="<?php 
                    echo esc_url(admin_url('post.php?post=' . $_product->id . '&action=edit'));
                    ?>
" class="tips" data-tip="<?php 
                    echo '<strong>' . __('Product ID:', 'woocommerce') . '</strong> ' . $_product->id;
                    echo '<br/><strong>' . __('Variation ID:', 'woocommerce') . '</strong> ';
                    if (isset($item->variation_id)) {
                        echo $item->variation_id;
                    } else {
                        echo '-';
                    }
                    echo '<br/><strong>' . __('Product SKU:', 'woocommerce') . '</strong> ';
                    if (isset($_product->sku)) {
                        echo $_product->sku;
                    } else {
                        echo '-';
                    }
                    ?>
"><?php 
                    echo $_product->get_image();
                    ?>
</a>
						</td>
						<td class="sku" width="20%">
							<?php 
                    if ($_product->sku) {
                        echo $_product->sku;
                    } else {
                        echo '-';
                    }
                    ?>
							<input type="hidden" class="item_id" name="item_id[<?php 
                    echo $loop;
                    ?>
]" value="<?php 
                    if (isset($item->id) && $item->id != '') {
                        echo esc_attr($item->id);
                    }
                    ?>
" />
							<input type="hidden" name="item_name[<?php 
                    echo $loop;
                    ?>
]" value="<?php 
                    echo esc_attr($item->id);
                    ?>
" />
						<?php 
                    if (isset($item->variation_id)) {
                        ?>
	<input type="hidden" name="item_variation[<?php 
                        echo $loop;
                        ?>
]" value="<?php 
                        echo esc_attr($item->variation_id);
                        ?>
" /> <?php 
                    }
                    ?>
						</td>
						<td class="name" width="20%">
						
							<div class="row-actions">
								<span class="view"><a href="<?php 
                    echo esc_url(admin_url('post.php?post=' . $_product->id . '&action=edit'));
                    ?>
"><?php 
                    _e('View product', 'woocommerce');
                    ?>
</a>
							</div>
							
							<?php 
                    echo $_product->get_title();
                    ?>
							<?php 
                    if (isset($_product->variation_data)) {
                        echo '<br/>' . woocommerce_get_formatted_variation($_product->variation_data, true);
                    }
                    ?>

						</td>

						<?php 
                    //do_action('woocommerce_admin_order_item_values', $_product, $item);
                    ?>

						<td class="price"  width="20%"><p>
							<?php 
                    echo $_product->get_price_html();
                    ?>
						</p></td>
						
						<td class="quantity"  width="20%"><p>
							<?php 
                    echo $item['quantity'];
                    ?>
						</p></td>

						
					</tr>
					
					<?php 
                }
                ?>
				<?php 
                $loop++;
            }
        } else {
            //Explain to the user why no products could show up in a recently abandoned / opened cart
            ?>

				<span style="color:gray;"'>No Products In The Cart</span> <?php 
            av8_tooltip(__('When a customer adds items to a cart, then abandones the cart for a considerable amount of time, the browser often deletes the cart data. The cart still belongs to the customer, but their brower removed the products. :( But hey! This indicates that they came back. And might be ready to purchase.', 'woocommerce_cart_reports'));
            ?>
				<?php 
        }
        ?>
			</tbody>
		</table>
	</div>
	
    <script type="text/javascript">

    </script>
	<?php 
    }
 /**
  * Set up the DoExpressCheckoutPayment request
  *
  * @link https://developer.paypal.com/docs/classic/express-checkout/integration-guide/ECGettingStarted/#id084RN060BPF
  * @link https://developer.paypal.com/webapps/developer/docs/classic/api/merchant/DoExpressCheckoutPayment_API_Operation_NVP/
  *
  * @since 3.0.0
  * @param \WC_Order $order order object
  * @param string $type
  */
 private function do_payment(WC_Order $order, $type)
 {
     $this->set_method('DoExpressCheckoutPayment');
     // set base params
     $this->add_parameters(array('TOKEN' => $order->paypal_express_token, 'PAYERID' => !empty($order->paypal_express_payer_id) ? $order->paypal_express_payer_id : null, 'BUTTONSOURCE' => 'WooThemes_Cart', 'RETURNFMFDETAILS' => 1));
     $order_subtotal = $i = 0;
     $order_items = array();
     // add line items
     foreach ($order->get_items() as $item) {
         $product = new WC_Product($item['product_id']);
         $order_items[] = array('NAME' => SV_WC_Helper::str_truncate(html_entity_decode($product->get_title(), ENT_QUOTES, 'UTF-8'), 127), 'DESC' => $this->get_item_description($item, $product), 'AMT' => $order->get_item_subtotal($item), 'QTY' => !empty($item['qty']) ? absint($item['qty']) : 1, 'ITEMURL' => $product->get_permalink());
         $order_subtotal += $item['line_total'];
     }
     // add fees
     foreach ($order->get_fees() as $fee) {
         $order_items[] = array('NAME' => SV_WC_Helper::str_truncate($fee['name'], 127), 'AMT' => $fee['line_total'], 'QTY' => 1);
         $order_subtotal += $fee['line_total'];
     }
     if (SV_WC_Plugin_Compatibility::is_wc_version_gte_2_3()) {
         // WC 2.3+, no after-tax discounts
         if ($order->get_total_discount() > 0) {
             $order_items[] = array('NAME' => __('Total Discount', WC_Paypal_Express::TEXT_DOMAIN), 'QTY' => 1, 'AMT' => -$order->get_total_discount());
         }
     } else {
         // WC 2.2 or lesser
         // add cart discounts as line item
         if ($order->get_cart_discount() > 0) {
             $order_items[] = array('NAME' => __('Cart Discount', WC_Paypal_Express::TEXT_DOMAIN), 'QTY' => 1, 'AMT' => -$order->get_cart_discount());
         }
         // add order discounts as line item
         if ($order->get_order_discount() > 0) {
             $order_items[] = array('NAME' => __('Order Discount', WC_Paypal_Express::TEXT_DOMAIN), 'QTY' => 1, 'AMT' => -$order->get_order_discount());
         }
     }
     $total_discount = SV_WC_Plugin_Compatibility::is_wc_version_gte_2_3() ? 0 : $order->get_order_discount();
     // order subtotal includes pre-tax discounts in 2.3
     if ($this->skip_line_items($order)) {
         $item_names = array();
         foreach ($order_items as $item) {
             $item_names[] = sprintf('%s x %s', $item['NAME'], $item['QTY']);
         }
         // add a single item for the entire order
         $this->add_line_item_parameters(array('NAME' => sprintf(__('%s - Order', WC_PayPal_Express::TEXT_DOMAIN), get_option('blogname')), 'DESC' => SV_WC_Helper::str_truncate(html_entity_decode(implode(', ', $item_names), ENT_QUOTES, 'UTF-8'), 127), 'AMT' => $order_subtotal - $total_discount + $order->get_cart_tax(), 'QTY' => 1), 0);
         // add order-level parameters
         //  - Do not sent the TAXAMT due to rounding errors
         $this->add_payment_parameters(array('AMT' => $order->get_total(), 'CURRENCYCODE' => $order->get_order_currency(), 'ITEMAMT' => $order_subtotal - $total_discount + $order->get_cart_tax(), 'SHIPPINGAMT' => $order->get_total_shipping() + $order->get_shipping_tax(), 'INVNUM' => $order->paypal_express_invoice_prefix . SV_WC_Helper::str_to_ascii(ltrim($order->get_order_number(), _x('#', 'hash before the order number', WC_PayPal_Express::TEXT_DOMAIN))), 'PAYMENTACTION' => $type, 'PAYMENTREQUESTID' => $order->id));
     } else {
         // add individual order items
         foreach ($order_items as $item) {
             $this->add_line_item_parameters($item, $i++);
         }
         // add order-level parameters
         $this->add_payment_parameters(array('AMT' => $order->get_total(), 'CURRENCYCODE' => $order->get_order_currency(), 'ITEMAMT' => $order_subtotal - $total_discount, 'SHIPPINGAMT' => $order->get_total_shipping(), 'TAXAMT' => $order->get_total_tax(), 'INVNUM' => $order->paypal_express_invoice_prefix . SV_WC_Helper::str_to_ascii(ltrim($order->get_order_number(), _x('#', 'hash before the order number', WC_PayPal_Express::TEXT_DOMAIN))), 'PAYMENTACTION' => $type, 'PAYMENTREQUESTID' => $order->id));
     }
 }
 /**
  * Get the order data for a single CSV row
  *
  * Note items are keyed according to the column header keys above so these can be modified using
  * the provider filter without needing to worry about the array order
  *
  * @since 3.0
  * @param int $order_id the WC_Order ID
  * @return array order data in the format key => content
  */
 private function get_orders_csv_row($order_id)
 {
     $order = wc_get_order($order_id);
     $line_items = $shipping_items = $fee_items = $tax_items = $coupon_items = array();
     // get line items
     foreach ($order->get_items() as $item_id => $item) {
         $product = $order->get_product_from_item($item);
         if (!is_object($product)) {
             $product = new WC_Product(0);
         }
         $item_meta = new WC_Order_Item_Meta(SV_WC_Plugin_Compatibility::is_wc_version_gte_2_4() ? $item : $item['item_meta']);
         $meta = $item_meta->display(true, true);
         if ($meta) {
             // remove newlines
             $meta = str_replace(array("\r", "\r\n", "\n"), '', $meta);
             // switch reserved chars (:;|) to =
             $meta = str_replace(array(': ', ':', ';', '|'), '=', $meta);
         }
         $line_item = array('name' => html_entity_decode($product->get_title() ? $product->get_title() : $item['name'], ENT_NOQUOTES, 'UTF-8'), 'sku' => $product->get_sku(), 'quantity' => $item['qty'], 'total' => wc_format_decimal($order->get_line_total($item), 2), 'refunded' => wc_format_decimal($order->get_total_refunded_for_item($item_id), 2), 'meta' => html_entity_decode($meta, ENT_NOQUOTES, 'UTF-8'));
         // add line item tax
         $line_tax_data = isset($item['line_tax_data']) ? $item['line_tax_data'] : array();
         $tax_data = maybe_unserialize($line_tax_data);
         $line_item['tax'] = isset($tax_data['total']) ? wc_format_decimal(wc_round_tax_total(array_sum((array) $tax_data['total'])), 2) : '';
         /**
          * CSV Order Export Line Item.
          *
          * Filter the individual line item entry for the default export
          *
          * @since 3.0.6
          * @param array $line_item {
          *     line item data in key => value format
          *     the keys are for convenience and not used for exporting. Make
          *     sure to prefix the values with the desired line item entry name
          * }
          *
          * @param array $item WC order item data
          * @param WC_Product $product the product
          * @param WC_Order $order the order
          * @param \WC_Customer_Order_CSV_Export_Generator $this, generator instance
          */
         $line_item = apply_filters('wc_customer_order_csv_export_order_line_item', $line_item, $item, $product, $order, $this);
         if ('default_one_row_per_item' !== $this->order_format && is_array($line_item)) {
             foreach ($line_item as $name => $value) {
                 $line_item[$name] = $name . ':' . $value;
             }
             $line_item = implode('|', $line_item);
         }
         if ($line_item) {
             $line_items[] = $line_item;
         }
     }
     foreach ($order->get_shipping_methods() as $_ => $shipping_item) {
         $shipping_items[] = implode('|', array('method:' . $shipping_item['name'], 'total:' . wc_format_decimal($shipping_item['cost'], 2)));
     }
     // get fee items & total
     $fee_total = 0;
     $fee_tax_total = 0;
     foreach ($order->get_fees() as $fee_id => $fee) {
         $fee_items[] = implode('|', array('name:' . $fee['name'], 'total:' . wc_format_decimal($fee['line_total'], 2), 'tax:' . wc_format_decimal($fee['line_tax'], 2)));
         $fee_total += $fee['line_total'];
         $fee_tax_total += $fee['line_tax'];
     }
     // get tax items
     foreach ($order->get_tax_totals() as $tax_code => $tax) {
         $tax_items[] = implode('|', array('code:' . $tax_code, 'total:' . wc_format_decimal($tax->amount, 2)));
     }
     // add coupons
     foreach ($order->get_items('coupon') as $_ => $coupon_item) {
         $coupon = new WC_Coupon($coupon_item['name']);
         $coupon_post = get_post($coupon->id);
         $coupon_items[] = implode('|', array('code:' . $coupon_item['name'], 'description:' . (is_object($coupon_post) ? $coupon_post->post_excerpt : ''), 'amount:' . wc_format_decimal($coupon_item['discount_amount'], 2)));
     }
     $order_data = array('order_id' => $order->id, 'order_number' => $order->get_order_number(), 'order_date' => $order->order_date, 'status' => $order->get_status(), 'shipping_total' => $order->get_total_shipping(), 'shipping_tax_total' => wc_format_decimal($order->get_shipping_tax(), 2), 'fee_total' => wc_format_decimal($fee_total, 2), 'fee_tax_total' => wc_format_decimal($fee_tax_total, 2), 'tax_total' => wc_format_decimal($order->get_total_tax(), 2), 'cart_discount' => SV_WC_Plugin_Compatibility::is_wc_version_gte_2_3() ? wc_format_decimal($order->get_total_discount(), 2) : wc_format_decimal($order->get_cart_discount(), 2), 'order_discount' => SV_WC_Plugin_Compatibility::is_wc_version_gte_2_3() ? wc_format_decimal($order->get_total_discount(), 2) : wc_format_decimal($order->get_order_discount(), 2), 'discount_total' => wc_format_decimal($order->get_total_discount(), 2), 'order_total' => wc_format_decimal($order->get_total(), 2), 'refunded_total' => wc_format_decimal($order->get_total_refunded(), 2), 'order_currency' => $order->get_order_currency(), 'payment_method' => $order->payment_method, 'shipping_method' => $order->get_shipping_method(), 'customer_id' => $order->get_user_id(), 'billing_first_name' => $order->billing_first_name, 'billing_last_name' => $order->billing_last_name, 'billing_company' => $order->billing_company, 'billing_email' => $order->billing_email, 'billing_phone' => $order->billing_phone, 'billing_address_1' => $order->billing_address_1, 'billing_address_2' => $order->billing_address_2, 'billing_postcode' => $order->billing_postcode, 'billing_city' => $order->billing_city, 'billing_state' => $order->billing_state, 'billing_country' => $order->billing_country, 'shipping_first_name' => $order->shipping_first_name, 'shipping_last_name' => $order->shipping_last_name, 'shipping_company' => $order->shipping_company, 'shipping_address_1' => $order->shipping_address_1, 'shipping_address_2' => $order->shipping_address_2, 'shipping_postcode' => $order->shipping_postcode, 'shipping_city' => $order->shipping_city, 'shipping_state' => $order->shipping_state, 'shipping_country' => $order->shipping_country, 'customer_note' => $order->customer_note, 'shipping_items' => implode(';', $shipping_items), 'fee_items' => implode(';', $fee_items), 'tax_items' => implode(';', $tax_items), 'coupon_items' => implode(';', $coupon_items), 'order_notes' => implode('|', $this->get_order_notes($order)), 'download_permissions' => $order->download_permissions_granted ? $order->download_permissions_granted : 0);
     if ('default_one_row_per_item' === $this->order_format) {
         $new_order_data = array();
         foreach ($line_items as $item) {
             $order_data['item_name'] = $item['name'];
             $order_data['item_sku'] = $item['sku'];
             $order_data['item_quantity'] = $item['quantity'];
             $order_data['item_tax'] = $item['tax'];
             $order_data['item_total'] = $item['total'];
             $order_data['item_refunded'] = $item['refunded'];
             $order_data['item_meta'] = $item['meta'];
             /**
              * CSV Order Export Row for One Row per Item.
              *
              * Filter the individual row data for the order export
              *
              * @since 3.3.0
              * @param array $order_data {
              *     order data in key => value format
              *     to modify the row data, ensure the key matches any of the header keys and set your own value
              * }
              * @param array $item
              * @param \WC_Order $order WC Order object
              * @param \WC_Customer_Order_CSV_Export_Generator $this, generator instance
              */
             $new_order_data[] = apply_filters('wc_customer_order_csv_export_order_row_one_row_per_item', $order_data, $item, $order, $this);
         }
         $order_data = $new_order_data;
     } else {
         $order_data['line_items'] = implode(';', $line_items);
     }
     /**
      * CSV Order Export Row.
      *
      * Filter the individual row data for the order export
      *
      * @since 3.0
      * @param array $order_data {
      *     order data in key => value format
      *     to modify the row data, ensure the key matches any of the header keys and set your own value
      * }
      * @param \WC_Order $order WC Order object
      * @param \WC_Customer_Order_CSV_Export_Generator $this, generator instance
      */
     return apply_filters('wc_customer_order_csv_export_order_row', $order_data, $order, $this);
 }
Ejemplo n.º 17
0
function dhvc_woo_get_product_formatted_name(WC_Product $product)
{
    if ($product->get_sku()) {
        $identifier = $product->get_sku();
    } else {
        $identifier = '#' . $product->id;
    }
    return sprintf(__('%s &ndash; %s', DHVC_WOO), $identifier, $product->get_title());
}
Ejemplo n.º 18
0
 protected function _formatted_name(WC_Product $product)
 {
     if ($product->get_sku()) {
         $identifier = $product->get_sku();
     } else {
         $identifier = '#' . $product->id;
     }
     return sprintf(__('%s &ndash; %s', 'sitesao'), $identifier, $product->get_title());
 }
Ejemplo n.º 19
0
 public function av8_manage_cart_columns($column, $post_id = '')
 {
     global $post;
     $cart = new AV8_Cart_Receipt();
     $cart->load_receipt($post->ID);
     $cart->set_guest_details();
     $title = '';
     switch ($column) {
         /* If displaying the 'duration' column. */
         case 'cartname':
             $suffix = "'s Cart";
             if ($cart->is_guest_order() && $cart->has_guest_details()) {
                 $fullname = ucwords($cart->get_guest_details('billing_first_name')) . ' ' . ucwords($cart->get_guest_details('billing_last_name'));
                 if ($fullname != ' ') {
                     $title .= $fullname;
                 } else {
                     $title .= "Guest";
                 }
                 $title .= $suffix . " (Guest)";
             } elseif ($cart->is_guest_order() && $cart->status() == "Converted" && isset($cart->order)) {
                 $title = ucwords($cart->order->billing_first_name) . ' ' . ucwords($cart->order->billing_last_name) . $suffix . " (Guest)";
             } elseif ($cart->is_guest_order()) {
                 $title = "Guest" . $suffix;
             } elseif ($cart->full_name() != false) {
                 $title = ucwords($cart->full_name()) . $suffix;
             }
             $post_url = admin_url('post.php?post=' . $post->ID . '&action=edit');
             echo __("<a href='{$post_url}'>" . $title . "</a>");
             break;
         case 'post__in':
             /* Get the post meta. */
             $show_custom_state = $cart->status();
             $filter_link = admin_url('edit.php?post_type=carts&status=' . $show_custom_state);
             echo __('<div class="index_status"><mark class="' . strtolower($show_custom_state) . '_index">' . $show_custom_state . '</mark></div>');
             break;
             /* If displaying the 'genre' column. */
         /* If displaying the 'genre' column. */
         case 'updated':
             /* Get the genres for the post. */
             the_modified_date('F j, Y');
             echo " at ";
             the_modified_date('g:i a');
             break;
             /* Just break out of the switch statement for everything else. */
         /* Just break out of the switch statement for everything else. */
         case 'products':
             //$products = $this->extract_cart_products();
             global $woocommerce;
             $cartitems = get_post_meta($post->ID, 'av8_cartitems', true);
             $items_arr = str_replace(array('O:17:"WC_Product_Simple"', 'O:10:"WC_Product"'), 'O:8:"stdClass"', $cartitems);
             if (isset($cartitems) && $cartitems != false) {
                 $order_items = (array) maybe_unserialize($items_arr);
             } else {
                 break;
             }
             $loop = 0;
             if (sizeof($order_items) > 0 && $order_items != false) {
                 foreach ($order_items as $item) {
                     if (function_exists('get_product')) {
                         if (isset($item['variation_id']) && $item['variation_id'] > 0) {
                             $_product = get_product($item['variation_id']);
                         } else {
                             $_product = get_product($item['product_id']);
                         }
                     } else {
                         if (isset($item['variation_id']) && $item['variation_id'] > 0) {
                             $_product = new WC_Product_Variation($item['variation_id']);
                         } else {
                             $_product = new WC_Product($item['product_id']);
                         }
                     }
                     if (isset($_product) && $_product != false) {
                         echo "<a href='" . get_admin_url('', 'post.php?post=' . $_product->id . '&action=edit') . "'>" . $_product->get_title() . "</a>";
                         if (isset($_product->variation_data)) {
                             echo ' (' . woocommerce_get_formatted_variation($_product->variation_data, true) . ')';
                         }
                         if ($item['quantity'] > 1) {
                             echo " x" . $item['quantity'];
                         }
                     }
                     if ($loop < sizeof($order_items) - 1) {
                         echo ", ";
                     }
                     $loop++;
                 }
             } else {
                 echo "<span style='color:lightgray;'>" . __("No Products", "woocommerce_cart_reports") . "</span>";
             }
             break;
         case 'actions':
             $cart->print_cart_actions($cart->status(), $cart->is_guest_order());
             break;
         default:
             break;
     }
 }
 /**
  * Uses the details of an order to create a pending subscription on the customers account
  * for a subscription product, as specified with $product_id.
  *
  * @param $order mixed int | WC_Order The order ID or WC_Order object to create the subscription from.
  * @param product_id int The ID of the subscription product on the order.
  * @since 1.1
  */
 public static function create_pending_subscription_for_order($order, $product_id)
 {
     if (!is_object($order)) {
         $order = new WC_Order($order);
     }
     if (!WC_Subscriptions_Order::is_item_subscription($order, $product_id)) {
         return;
     }
     $subscription_key = self::get_subscription_key($order->id, $product_id);
     // In case the subscription exists already
     $subscription = self::get_users_subscription($order->customer_user, $subscription_key);
     // Adding a new subscription so set the start date/time to now
     $start_date = isset($subscription['start_date']) ? $subscription['start_date'] : date('Y-m-d H:i:s');
     // Adding a new subscription so set the expiry date/time from the order date
     $expiration = isset($subscription['expiry_date']) ? $subscription['expiry_date'] : WC_Subscriptions_Product::get_expiration_date($product_id, date('Y-m-d H:i:s'));
     // Adding a new subscription so set the expiry date/time from the order date
     $trial_expiration = isset($subscription['trial_expiry_date']) ? $subscription['trial_expiry_date'] : WC_Subscriptions_Product::get_trial_expiration_date($product_id, date('Y-m-d H:i:s'));
     $failed_payments = isset($subscription['failed_payments']) ? $subscription['failed_payments'] : 0;
     $completed_payments = isset($subscription['completed_payments']) ? $subscription['completed_payments'] : array();
     $subscriptions[$subscription_key] = array('product_id' => $product_id, 'order_key' => $order->order_key, 'order_id' => $order->id, 'start_date' => $start_date, 'expiry_date' => $expiration, 'end_date' => 0, 'status' => 'pending', 'trial_expiry_date' => $trial_expiration, 'failed_payments' => $failed_payments, 'completed_payments' => $completed_payments);
     self::update_users_subscriptions($order->customer_user, $subscriptions);
     $product = new WC_Product($product_id);
     // Set subscription status to active and log activation
     $order->add_order_note(sprintf(__('Pending subscription created for "%s".', WC_Subscriptions::$text_domain), $product->get_title()));
     do_action('pending_subscription_created_for_order', $order, $product_id);
 }
Ejemplo n.º 21
0
 /**
  * Gets an individual ticket
  *
  * @param $event_id
  * @param $ticket_id
  *
  * @return null|Tribe__Events__Tickets__Ticket_Object
  */
 public function get_ticket($event_id, $ticket_id)
 {
     if (class_exists('WC_Product_Simple')) {
         $product = new WC_Product_Simple($ticket_id);
     } else {
         $product = new WC_Product($ticket_id);
     }
     if (!$product) {
         return null;
     }
     $return = new Tribe__Events__Tickets__Ticket_Object();
     $product_data = $product->get_post_data();
     $qty = get_post_meta($ticket_id, 'total_sales', true);
     $return->description = $product_data->post_excerpt;
     $return->frontend_link = get_permalink($ticket_id);
     $return->ID = $ticket_id;
     $return->name = $product->get_title();
     $return->price = $product->get_price();
     $return->regular_price = $product->get_regular_price();
     $return->on_sale = (bool) $product->is_on_sale();
     $return->provider_class = get_class($this);
     $return->admin_link = admin_url(sprintf(get_post_type_object($product_data->post_type)->_edit_link . '&action=edit', $ticket_id));
     $return->stock = $product->get_stock_quantity();
     $return->start_date = get_post_meta($ticket_id, '_ticket_start_date', true);
     $return->end_date = get_post_meta($ticket_id, '_ticket_end_date', true);
     $return->qty_sold = $qty ? $qty : 0;
     $return->qty_pending = $qty ? $this->count_incomplete_order_items($ticket_id) : 0;
     $return->purchase_limit = get_post_meta($ticket_id, '_ticket_purchase_limit', true);
     if (empty($return->purchase_limit) && 0 !== (int) $return->purchase_limit) {
         /**
          * Filter the default purchase limit for the ticket
          *
          * @var int
          *
          * @return int
          */
         $return->purchase_limit = apply_filters('tribe_tickets_default_purchase_limit', 0);
     }
     return apply_filters('wootickets_get_ticket', $return, $event_id, $ticket_id);
 }
 /**
  * Get standard product data that applies to every product type
  *
  * @since 2.1
  * @param WC_Product $product
  * @return WC_Product
  */
 private function get_product_data($product)
 {
     return array('title' => $product->get_title(), 'id' => (int) $product->is_type('variation') ? $product->get_variation_id() : $product->id, 'created_at' => $this->server->format_datetime($product->get_post_data()->post_date_gmt), 'updated_at' => $this->server->format_datetime($product->get_post_data()->post_modified_gmt), 'type' => $product->product_type, 'status' => $product->get_post_data()->post_status, 'downloadable' => $product->is_downloadable(), 'virtual' => $product->is_virtual(), 'permalink' => $product->get_permalink(), 'sku' => $product->get_sku(), 'price' => $product->get_price(), 'regular_price' => $product->get_regular_price(), 'sale_price' => $product->get_sale_price() ? $product->get_sale_price() : null, 'price_html' => $product->get_price_html(), 'taxable' => $product->is_taxable(), 'tax_status' => $product->get_tax_status(), 'tax_class' => $product->get_tax_class(), 'managing_stock' => $product->managing_stock(), 'stock_quantity' => $product->get_stock_quantity(), 'in_stock' => $product->is_in_stock(), 'backorders_allowed' => $product->backorders_allowed(), 'backordered' => $product->is_on_backorder(), 'sold_individually' => $product->is_sold_individually(), 'purchaseable' => $product->is_purchasable(), 'featured' => $product->is_featured(), 'visible' => $product->is_visible(), 'catalog_visibility' => $product->visibility, 'on_sale' => $product->is_on_sale(), 'product_url' => $product->is_type('external') ? $product->get_product_url() : '', 'button_text' => $product->is_type('external') ? $product->get_button_text() : '', 'weight' => $product->get_weight() ? $product->get_weight() : null, 'dimensions' => array('length' => $product->length, 'width' => $product->width, 'height' => $product->height, 'unit' => get_option('woocommerce_dimension_unit')), 'shipping_required' => $product->needs_shipping(), 'shipping_taxable' => $product->is_shipping_taxable(), 'shipping_class' => $product->get_shipping_class(), 'shipping_class_id' => 0 !== $product->get_shipping_class_id() ? $product->get_shipping_class_id() : null, 'description' => wpautop(do_shortcode($product->get_post_data()->post_content)), 'short_description' => apply_filters('woocommerce_short_description', $product->get_post_data()->post_excerpt), 'reviews_allowed' => 'open' === $product->get_post_data()->comment_status, 'average_rating' => wc_format_decimal($product->get_average_rating(), 2), 'rating_count' => (int) $product->get_rating_count(), 'related_ids' => array_map('absint', array_values($product->get_related())), 'upsell_ids' => array_map('absint', $product->get_upsells()), 'cross_sell_ids' => array_map('absint', $product->get_cross_sells()), 'parent_id' => $product->post->post_parent, 'categories' => wp_get_post_terms($product->id, 'product_cat', array('fields' => 'names')), 'tags' => wp_get_post_terms($product->id, 'product_tag', array('fields' => 'names')), 'images' => $this->get_images($product), 'featured_src' => (string) wp_get_attachment_url(get_post_thumbnail_id($product->is_type('variation') ? $product->variation_id : $product->id)), 'attributes' => $this->get_attributes($product), 'downloads' => $this->get_downloads($product), 'download_limit' => (int) $product->download_limit, 'download_expiry' => (int) $product->download_expiry, 'download_type' => $product->download_type, 'purchase_note' => wpautop(do_shortcode(wp_kses_post($product->purchase_note))), 'total_sales' => metadata_exists('post', $product->id, 'total_sales') ? (int) get_post_meta($product->id, 'total_sales', true) : 0, 'variations' => array(), 'parent' => array(), 'grouped_products' => array());
 }
 private function _getProductDetails($product_id)
 {
     $product = new WC_Product($product_id);
     ob_start();
     echo $product->get_image();
     $image = ob_get_clean();
     return array("item_name" => $product->get_title(), "item_description" => $product->post->post_content, "item_url" => $product->post->guid, "item_price" => $product->price, "item_picture_url" => $image);
 }
 /**
  * Get standard product data that applies to every product type
  *
  * @since 2.1
  * @param WC_Product $product
  * @return WC_Product
  */
 private function get_product_data($product, $fields = null)
 {
     if ($fields) {
         $field_list = explode(',', $fields);
     }
     $product_data = array();
     if (!$fields || $fields && in_array('title', $field_list)) {
         $product_data['title'] = $product->get_title();
     }
     if (!$fields || $fields && in_array('id', $field_list)) {
         $product_data['id'] = (int) $product->is_type('variation') ? $product->get_variation_id() : $product->id;
     }
     if (!$fields || $fields && in_array('created_at', $field_list)) {
         $product_data['created_at'] = $this->server->format_datetime($product->get_post_data()->post_date_gmt);
     }
     if (!$fields || $fields && in_array('updated_at', $field_list)) {
         $product_data['updated_at'] = $this->server->format_datetime($product->get_post_data()->post_modified_gmt);
     }
     if (!$fields || $fields && in_array('type', $field_list)) {
         $product_data['type'] = $product->product_type;
     }
     if (!$fields || $fields && in_array('status', $field_list)) {
         $product_data['status'] = $product->get_post_data()->post_status;
     }
     if (!$fields || $fields && in_array('downloadable', $field_list)) {
         $product_data['downloadable'] = $product->is_downloadable();
     }
     if (!$fields || $fields && in_array('virtual', $field_list)) {
         $product_data['virtual'] = $product->is_virtual();
     }
     if (!$fields || $fields && in_array('permalink', $field_list)) {
         $product_data['permalink'] = $product->get_permalink();
     }
     if (!$fields || $fields && in_array('sku', $field_list)) {
         $product_data['sku'] = $product->get_sku();
     }
     if (!$fields || $fields && in_array('price', $field_list)) {
         $product_data['price'] = $product->get_price();
     }
     if (!$fields || $fields && in_array('regular_price', $field_list)) {
         $product_data['regular_price'] = $product->get_regular_price();
     }
     if (!$fields || $fields && in_array('sale_price', $field_list)) {
         $product_data['sale_price'] = $product->get_sale_price() ? $product->get_sale_price() : null;
     }
     if (!$fields || $fields && in_array('price_html', $field_list)) {
         $product_data['price_html'] = $product->get_price_html();
     }
     if (!$fields || $fields && in_array('taxable', $field_list)) {
         $product_data['taxable'] = $product->is_taxable();
     }
     if (!$fields || $fields && in_array('tax_status', $field_list)) {
         $product_data['tax_status'] = $product->get_tax_status();
     }
     if (!$fields || $fields && in_array('tax_class', $field_list)) {
         $product_data['tax_class'] = $product->get_tax_class();
     }
     if (!$fields || $fields && in_array('managing_stock', $field_list)) {
         $product_data['managing_stock'] = $product->managing_stock();
     }
     if (!$fields || $fields && in_array('stock_quantity', $field_list)) {
         $product_data['stock_quantity'] = $product->get_stock_quantity();
     }
     if (!$fields || $fields && in_array('in_stock', $field_list)) {
         $product_data['in_stock'] = $product->is_in_stock();
     }
     if (!$fields || $fields && in_array('backorders_allowed', $field_list)) {
         $product_data['backorders_allowed'] = $product->backorders_allowed();
     }
     if (!$fields || $fields && in_array('backordered', $field_list)) {
         $product_data['backordered'] = $product->is_on_backorder();
     }
     if (!$fields || $fields && in_array('sold_individually', $field_list)) {
         $product_data['sold_individually'] = $product->is_sold_individually();
     }
     if (!$fields || $fields && in_array('purchaseable', $field_list)) {
         $product_data['purchaseable'] = $product->is_purchasable();
     }
     if (!$fields || $fields && in_array('featured', $field_list)) {
         $product_data['featured'] = $product->is_featured();
     }
     if (!$fields || $fields && in_array('visible', $field_list)) {
         $product_data['visible'] = $product->is_visible();
     }
     if (!$fields || $fields && in_array('catalog_visibility', $field_list)) {
         $product_data['catalog_visibility'] = $product->visibility;
     }
     if (!$fields || $fields && in_array('on_sale', $field_list)) {
         $product_data['on_sale'] = $product->is_on_sale();
     }
     if (!$fields || $fields && in_array('product_url', $field_list)) {
         $product_data['product_url'] = $product->is_type('external') ? $product->get_product_url() : '';
     }
     if (!$fields || $fields && in_array('button_text', $field_list)) {
         $product_data['button_text'] = $product->is_type('external') ? $product->get_button_text() : '';
     }
     if (!$fields || $fields && in_array('weight', $field_list)) {
         $product_data['weight'] = $product->get_weight() ? $product->get_weight() : null;
     }
     if (!$fields || $fields && in_array('dimensions', $field_list)) {
         $product_data['dimensions'] = array('length' => $product->length, 'width' => $product->width, 'height' => $product->height, 'unit' => get_option('woocommerce_dimension_unit'));
     }
     if (!$fields || $fields && in_array('shipping_required', $field_list)) {
         $product_data['shipping_required'] = $product->needs_shipping();
     }
     if (!$fields || $fields && in_array('shipping_taxable', $field_list)) {
         $product_data['shipping_taxable'] = $product->is_shipping_taxable();
     }
     if (!$fields || $fields && in_array('shipping_class', $field_list)) {
         $product_data['shipping_class'] = $product->get_shipping_class();
     }
     if (!$fields || $fields && in_array('shipping_class_id', $field_list)) {
         $product_data['shipping_class_id'] = 0 !== $product->get_shipping_class_id() ? $product->get_shipping_class_id() : null;
     }
     if (!$fields || $fields && in_array('description', $field_list)) {
         $product_data['description'] = wpautop(do_shortcode($product->get_post_data()->post_content));
     }
     if (!$fields || $fields && in_array('short_description', $field_list)) {
         $product_data['short_description'] = apply_filters('woocommerce_short_description', $product->get_post_data()->post_excerpt);
     }
     if (!$fields || $fields && in_array('reviews_allowed', $field_list)) {
         $product_data['reviews_allowed'] = 'open' === $product->get_post_data()->comment_status;
     }
     if (!$fields || $fields && in_array('average_rating', $field_list)) {
         $product_data['average_rating'] = wc_format_decimal($product->get_average_rating(), 2);
     }
     if (!$fields || $fields && in_array('rating_count', $field_list)) {
         $product_data['rating_count'] = (int) $product->get_rating_count();
     }
     if (!$fields || $fields && in_array('related_ids', $field_list)) {
         $product_data['related_ids'] = array_map('absint', array_values($product->get_related()));
     }
     if (!$fields || $fields && in_array('upsell_ids', $field_list)) {
         $product_data['upsell_ids'] = array_map('absint', $product->get_upsells());
     }
     if (!$fields || $fields && in_array('cross_sell_ids', $field_list)) {
         $product_data['cross_sell_ids'] = array_map('absint', $product->get_cross_sells());
     }
     if (!$fields || $fields && in_array('parent_id', $field_list)) {
         $product_data['parent_id'] = $product->post->post_parent;
     }
     if (!$fields || $fields && in_array('categories', $field_list)) {
         $product_data['categories'] = wp_get_post_terms($product->id, 'product_cat', array('fields' => 'names'));
     }
     if (!$fields || $fields && in_array('tags', $field_list)) {
         $product_data['tags'] = wp_get_post_terms($product->id, 'product_tag', array('fields' => 'names'));
     }
     if (!$fields || $fields && in_array('images', $field_list)) {
         $product_data['images'] = $this->get_images($product);
     }
     if (!$fields || $fields && in_array('featured_src', $field_list)) {
         $product_data['featured_src'] = (string) wp_get_attachment_url(get_post_thumbnail_id($product->is_type('variation') ? $product->variation_id : $product->id));
     }
     if (!$fields || $fields && in_array('attributes', $field_list)) {
         $product_data['attributes'] = $this->get_attributes($product);
     }
     if (!$fields || $fields && in_array('downloads', $field_list)) {
         $product_data['downloads'] = $this->get_downloads($product);
     }
     if (!$fields || $fields && in_array('download_limit', $field_list)) {
         $product_data['download_limit'] = (int) $product->download_limit;
     }
     if (!$fields || $fields && in_array('download_expiry', $field_list)) {
         $product_data['download_expiry'] = (int) $product->download_expiry;
     }
     if (!$fields || $fields && in_array('download_type', $field_list)) {
         $product_data['download_type'] = $product->download_type;
     }
     if (!$fields || $fields && in_array('purchase_note', $field_list)) {
         $product_data['purchase_note'] = wpautop(do_shortcode(wp_kses_post($product->purchase_note)));
     }
     if (!$fields || $fields && in_array('total_sales', $field_list)) {
         $product_data['total_sales'] = metadata_exists('post', $product->id, 'total_sales') ? (int) get_post_meta($product->id, 'total_sales', true) : 0;
     }
     if (!$fields || $fields && in_array('variations', $field_list)) {
         $product_data['variations'] = array();
     }
     if (!$fields || $fields && in_array('parent', $field_list)) {
         $product_data['parent'] = array();
     }
     if (!$fields || $fields && in_array('grouped_products', $field_list)) {
         $product_data['grouped_products'] = array();
     }
     if (!$fields || $fields && in_array('menu_order', $field_list)) {
         $product_data['menu_order'] = $product->post->menu_order;
     }
     return $product_data;
 }
Ejemplo n.º 25
0
/**
 * Displays the order downloads meta box.
 *
 * @access public
 * @return void
 */
function woocommerce_order_downloads_meta_box()
{
    global $woocommerce, $post, $wpdb;
    ?>
	<div class="order_download_permissions wc-metaboxes-wrapper">

		<div class="wc-metaboxes">

			<?php 
    $i = -1;
    $download_permissions = $wpdb->get_results("\n\t\t\t\t\tSELECT * FROM {$wpdb->prefix}woocommerce_downloadable_product_permissions\n\t\t\t\t\tWHERE order_id = {$post->ID}\n\t\t\t\t");
    if ($download_permissions && sizeof($download_permissions) > 0) {
        foreach ($download_permissions as $download) {
            $i++;
            $product = new WC_Product($download->product_id);
            ?>
		    		<div class="wc-metabox closed">
						<h3 class="fixed">
							<button type="button" rel="<?php 
            echo $download->product_id;
            ?>
" class="revoke_access button"><?php 
            _e('Revoke Access', 'woocommerce');
            ?>
</button>
							<div class="handlediv" title="<?php 
            _e('Click to toggle', 'woocommerce');
            ?>
"></div>
							<strong><?php 
            echo '#' . $product->id . ' &mdash; ' . $product->get_title() . ' &mdash; ' . sprintf(_n('Downloaded %s time', 'Downloaded %s times', $download->download_count, 'woocommerce'), $download->download_count);
            ?>
</strong>
						</h3>
						<table cellpadding="0" cellspacing="0" class="wc-metabox-content">
							<tbody>
								<tr>
									<td>
										<label><?php 
            _e('Downloads Remaining', 'woocommerce');
            ?>
:</label>
										<input type="hidden" name="download_id[<?php 
            echo $i;
            ?>
]" value="<?php 
            echo $download->product_id;
            ?>
" />
										<input type="text" class="short" name="downloads_remaining[<?php 
            echo $i;
            ?>
]" value="<?php 
            echo $download->downloads_remaining;
            ?>
" placeholder="<?php 
            _e('Unlimited', 'woocommerce');
            ?>
" />
									</td>
									<td>
										<label><?php 
            _e('Access Expires', 'woocommerce');
            ?>
:</label>
										<input type="text" class="short date-picker" name="access_expires[<?php 
            echo $i;
            ?>
]" value="<?php 
            echo $download->access_expires > 0 ? date_i18n('Y-m-d', strtotime($download->access_expires)) : '';
            ?>
" maxlength="10" placeholder="<?php 
            _e('Never', 'woocommerce');
            ?>
" />
									</td>
								</tr>
							</tbody>
						</table>
					</div>
					<?php 
        }
    }
    ?>
		</div>

		<div class="toolbar">
			<p class="buttons">
				<select name="grant_access_id" class="grant_access_id chosen_select_nostd" data-placeholder="<?php 
    _e('Choose a downloadable product&hellip;', 'woocommerce');
    ?>
">
					<?php 
    echo '<option value=""></option>';
    $args = array('post_type' => 'product', 'posts_per_page' => -1, 'post_status' => 'publish', 'post_parent' => 0, 'order' => 'ASC', 'orderby' => 'title', 'meta_query' => array(array('key' => '_downloadable', 'value' => 'yes')));
    $products = get_posts($args);
    if ($products) {
        foreach ($products as $product) {
            $sku = get_post_meta($product->ID, '_sku', true);
            if ($sku) {
                $sku = ' SKU: ' . $sku;
            }
            echo '<option value="' . $product->ID . '">' . $product->post_title . $sku . ' (#' . $product->ID . '' . $sku . ')</option>';
            $args_get_children = array('post_type' => array('product_variation', 'product'), 'posts_per_page' => -1, 'order' => 'ASC', 'orderby' => 'title', 'post_parent' => $product->ID);
            if ($children_products =& get_children($args_get_children)) {
                foreach ($children_products as $child) {
                    echo '<option value="' . $child->ID . '">&nbsp;&nbsp;&mdash;&nbsp;' . $child->post_title . '</option>';
                }
            }
        }
    }
    ?>
				</select>

				<button type="button" class="button grant_access"><?php 
    _e('Grant Access', 'woocommerce');
    ?>
</button>
			</p>
			<div class="clear"></div>
		</div>

	</div>
	<?php 
    /**
     * Javascript
     */
    ob_start();
    ?>
	jQuery(function(){

		jQuery('.order_download_permissions').on('click', 'button.grant_access', function(){

			var product = jQuery('select.grant_access_id').val();

			if (!product) return;

			jQuery('.order_download_permissions').block({ message: null, overlayCSS: { background: '#fff url(<?php 
    echo $woocommerce->plugin_url();
    ?>
/assets/images/ajax-loader.gif) no-repeat center', opacity: 0.6 } });

			var data = {
				action: 		'woocommerce_grant_access_to_download',
				product_id: 	product,
				order_id: 		'<?php 
    echo $post->ID;
    ?>
',
				security: 		'<?php 
    echo wp_create_nonce("grant-access");
    ?>
'
			};

			jQuery.post('<?php 
    echo admin_url('admin-ajax.php');
    ?>
', data, function(response) {

				var loop = jQuery('.order_download_permissions .wc-metabox').size();

				new_download = jQuery.parseJSON( response );

				if ( new_download && new_download.success == 1 ) {

					jQuery('.order_download_permissions .wc-metaboxes').append('<div class="wc-metabox closed">\
						<h3 class="fixed">\
							<button type="button" rel="' + new_download.download_id + '" class="revoke_access button"><?php 
    _e('Revoke Access', 'woocommerce');
    ?>
</button>\
							<div class="handlediv" title="<?php 
    _e('Click to toggle', 'woocommerce');
    ?>
"></div>\
							<strong>#' + new_download.download_id + ' &mdash; ' + new_download.title + '</strong>\
						</h3>\
						<table cellpadding="0" cellspacing="0" class="wc-metabox-content">\
							<tbody>\
								<tr>\
									<td>\
										<label><?php 
    _e('Downloads Remaining', 'woocommerce');
    ?>
:</label>\
										<input type="hidden" name="download_id[' + loop + ']" value="' + new_download.download_id + '" />\
										<input type="text" class="short" name="downloads_remaining[' + loop + ']" value="' + new_download.remaining + '" placeholder="<?php 
    _e('Unlimited', 'woocommerce');
    ?>
" />\
									</td>\
									<td>\
										<label><?php 
    _e('Access Expires', 'woocommerce');
    ?>
:</label>\
										<input type="text" class="short date-picker" name="access_expires[' + loop + ']" value="' + new_download.expires + '" maxlength="10" placeholder="<?php 
    _e('Never', 'woocommerce');
    ?>
" />\
									</td>\
								</tr>\
							</tbody>\
						</table>\
					</div>');

				} else {
					alert('<?php 
    _e('Could not grant access - the user may already have permission for this file.', 'woocommerce');
    ?>
');
				}

				jQuery( ".date-picker" ).datepicker({
					dateFormat: "yy-mm-dd",
					numberOfMonths: 1,
					showButtonPanel: true,
					showOn: "button",
					buttonImage: woocommerce_writepanel_params.calendar_image,
					buttonImageOnly: true
				});

				jQuery('.order_download_permissions').unblock();

			});

			return false;

		});

		jQuery('.order_download_permissions').on('click', 'button.revoke_access', function(e){
			e.preventDefault();
			var answer = confirm('<?php 
    _e('Are you sure you want to revoke access to this download?', 'woocommerce');
    ?>
');
			if (answer){

				var el = jQuery(this).parent().parent();

				var product = jQuery(this).attr('rel');

				if (product>0) {

					jQuery(el).block({ message: null, overlayCSS: { background: '#fff url(<?php 
    echo $woocommerce->plugin_url();
    ?>
/assets/images/ajax-loader.gif) no-repeat center', opacity: 0.6 } });

					var data = {
						action: 		'woocommerce_revoke_access_to_download',
						product_id: 	product,
						order_id: 		'<?php 
    echo $post->ID;
    ?>
',
						security: 		'<?php 
    echo wp_create_nonce("revoke-access");
    ?>
'
					};

					jQuery.post('<?php 
    echo admin_url('admin-ajax.php');
    ?>
', data, function(response) {
						// Success
						jQuery(el).fadeOut('300', function(){
							jQuery(el).remove();
						});
					});

				} else {
					jQuery(el).fadeOut('300', function(){
						jQuery(el).remove();
					});
				}

			}
			return false;
		});

	});
	<?php 
    $javascript = ob_get_clean();
    $woocommerce->add_inline_js($javascript);
}
Ejemplo n.º 26
0
 /**
  * @param WP_Post $product
  *
  * @return array
  */
 public static function getArticleCampaign($product)
 {
     $productId = $product->ID;
     $product = new WC_Product($productId);
     $serialized = array('id' => $productId, 'name' => $product->get_title(), 'url' => $product->get_permalink());
     $description = $product->get_post_data()->post_content;
     if (!empty($description)) {
         $serialized['description'] = $description;
     }
     $imageUrl = wp_get_attachment_url(get_post_thumbnail_id($productId));
     if (!empty($imageUrl)) {
         $serialized['image_url'] = $imageUrl;
     }
     return $serialized;
 }
Ejemplo n.º 27
0
 /**
  * Add a product line item to the order. This is the only line item type with
  * it's own method because it saves looking up order amounts (costs are added up for you).
  * @param  \WC_Product $product
  * @param  int $qty
  * @param  array $args
  * @return int order item ID
  * @throws WC_Data_Exception
  */
 public function add_product($product, $qty = 1, $args = array())
 {
     if ($product) {
         $default_args = array('name' => $product->get_title(), 'tax_class' => $product->get_tax_class(), 'product_id' => $product->get_id(), 'variation_id' => isset($product->variation_id) ? $product->variation_id : 0, 'variation' => isset($product->variation_id) ? $product->get_variation_attributes() : array(), 'subtotal' => $product->get_price_excluding_tax($qty), 'total' => $product->get_price_excluding_tax($qty), 'quantity' => $qty);
     } else {
         $default_args = array('quantity' => $qty);
     }
     $args = wp_parse_args($args, $default_args);
     // BW compatibility with old args
     if (isset($args['totals'])) {
         foreach ($args['totals'] as $key => $value) {
             if ('tax' === $key) {
                 $args['total_tax'] = $value;
             } elseif ('tax_data' === $key) {
                 $args['taxes'] = $value;
             } else {
                 $args[$key] = $value;
             }
         }
     }
     $item = new WC_Order_Item_Product($args);
     $item->set_backorder_meta();
     $item->set_order_id($this->get_id());
     $item->save();
     $this->add_item($item);
     wc_do_deprecated_action('woocommerce_order_add_product', array($this->get_id(), $item->get_id(), $product, $qty, $args), '2.7', 'Use woocommerce_new_order_item action instead.');
     return $item->get_id();
 }
Ejemplo n.º 28
0
 /**
  * Gets an individual ticket
  *
  * @param $unused_event_id
  * @param $ticket_id
  *
  * @return null|Tribe__Events__Tickets__Ticket_Object
  */
 public function get_ticket($unused_event_id, $ticket_id)
 {
     if (class_exists('WC_Product_Simple')) {
         $product = new WC_Product_Simple($ticket_id);
     } else {
         $product = new WC_Product($ticket_id);
     }
     if (!$product) {
         return null;
     }
     $return = new Tribe__Events__Tickets__Ticket_Object();
     $product_data = $product->get_post_data();
     $qty = get_post_meta($ticket_id, 'total_sales', true);
     $return->description = $product_data->post_excerpt;
     $return->frontend_link = get_permalink($ticket_id);
     $return->ID = $ticket_id;
     $return->name = $product->get_title();
     $return->price = $product->get_price();
     $return->regular_price = $product->get_regular_price();
     $return->on_sale = (bool) $product->is_on_sale();
     $return->provider_class = get_class($this);
     $return->admin_link = admin_url(sprintf(get_post_type_object($product_data->post_type)->_edit_link . '&action=edit', $ticket_id));
     $return->stock = $product->get_stock_quantity();
     $return->start_date = get_post_meta($ticket_id, '_ticket_start_date', true);
     $return->end_date = get_post_meta($ticket_id, '_ticket_end_date', true);
     $return->qty_sold = $qty ? $qty : 0;
     $return->qty_pending = $qty ? $this->count_incomplete_order_items($ticket_id) : 0;
     return $return;
 }
 /**
  * Add a product line item to the order
  *
  * @since 2.2
  * @param \WC_Product $product
  * @param int $qty Line item quantity
  * @param array $args
  * @return int|bool Item ID or false
  */
 public function add_product($product, $qty = 1, $args = array())
 {
     $default_args = array('variation' => array(), 'totals' => array());
     $args = wp_parse_args($args, $default_args);
     $item_id = wc_add_order_item($this->id, array('order_item_name' => $product->get_title(), 'order_item_type' => 'line_item'));
     if (!$item_id) {
         return false;
     }
     wc_add_order_item_meta($item_id, '_qty', wc_stock_amount($qty));
     wc_add_order_item_meta($item_id, '_tax_class', $product->get_tax_class());
     wc_add_order_item_meta($item_id, '_product_id', $product->id);
     wc_add_order_item_meta($item_id, '_variation_id', isset($product->variation_id) ? $product->variation_id : 0);
     // Set line item totals, either passed in or from the product
     wc_add_order_item_meta($item_id, '_line_subtotal', wc_format_decimal(isset($args['totals']['subtotal']) ? $args['totals']['subtotal'] : $product->get_price_excluding_tax($qty)));
     wc_add_order_item_meta($item_id, '_line_total', wc_format_decimal(isset($args['totals']['total']) ? $args['totals']['total'] : $product->get_price_excluding_tax($qty)));
     wc_add_order_item_meta($item_id, '_line_subtotal_tax', wc_format_decimal(isset($args['totals']['subtotal_tax']) ? $args['totals']['subtotal_tax'] : 0));
     wc_add_order_item_meta($item_id, '_line_tax', wc_format_decimal(isset($args['totals']['tax']) ? $args['totals']['tax'] : 0));
     // Save tax data - Since 2.2
     if (isset($args['totals']['tax_data'])) {
         $tax_data = array();
         $tax_data['total'] = array_map('wc_format_decimal', $args['totals']['tax_data']['total']);
         $tax_data['subtotal'] = array_map('wc_format_decimal', $args['totals']['tax_data']['subtotal']);
         wc_add_order_item_meta($item_id, '_line_tax_data', $tax_data);
     } else {
         wc_add_order_item_meta($item_id, '_line_tax_data', array('total' => array(), 'subtotal' => array()));
     }
     // Add variation meta
     if (!empty($args['variation'])) {
         foreach ($args['variation'] as $key => $value) {
             wc_add_order_item_meta($item_id, str_replace('attribute_', '', $key), $value);
         }
     }
     // Backorders
     if ($product->backorders_require_notification() && $product->is_on_backorder($qty)) {
         wc_add_order_item_meta($item_id, apply_filters('woocommerce_backordered_item_meta_name', __('Backordered', 'woocommerce')), $qty - max(0, $product->get_total_stock()));
     }
     do_action('woocommerce_order_add_product', $this->id, $item_id, $product, $qty, $args);
     return $item_id;
 }
 /**
  * Check stock before attempting to call the add_to_cart function
  * Some double checking happens, but it's better than partially adding items to the cart
  **/
 function validate_stock($product_id, $variation_id, $quantity, $exclude_cart, $silent)
 {
     global $woocommerce;
     if ($variation_id > 0) {
         if ($this->is_wc_v2()) {
             $product_data = get_product($variation_id, array('product_type' => 'variation'));
         } else {
             $product_data = new WC_Product_Variation($variation_id);
         }
     } else {
         if ($this->is_wc_v2()) {
             $product_data = get_product($product_id, array('product_type' => 'simple'));
         } else {
             $product_data = new WC_Product($product_id);
         }
     }
     // Stock check - only check if we're managing stock and backorders are not allowed.
     if (!$product_data->is_in_stock()) {
         if (!$silent) {
             $woocommerce->add_error(sprintf(__('You cannot add this product to the cart since "%s" is out of stock.', 'woo-bundles'), $product_data->get_title()));
         }
         return false;
     } elseif (!$product_data->has_enough_stock($quantity)) {
         if (!$silent) {
             $woocommerce->add_error(sprintf(__('You cannot add that amount to the cart since there is not enough stock of "%s". We have %s in stock.', 'woo-bundles'), $product_data->get_title(), $product_data->get_stock_quantity()));
         }
         return false;
     }
     // Stock check - this time accounting for whats already in-cart.
     if ($exclude_cart) {
         return true;
     }
     $product_qty_in_cart = $woocommerce->cart->get_cart_item_quantities();
     if ($product_data->managing_stock()) {
         // Variations
         if ($variation_id && $product_data->variation_has_stock) {
             if (isset($product_qty_in_cart[$variation_id]) && !$product_data->has_enough_stock($product_qty_in_cart[$variation_id] + $quantity)) {
                 if (!$silent) {
                     $woocommerce->add_error(sprintf(__('<a href="%s" class="button">%s</a>You cannot add that amount to the cart since there is not enough stock of "%s" &mdash; we have %s in stock and you already have %s in your cart.', 'woo-bundles'), get_permalink(woocommerce_get_page_id('cart')), __('View Cart &rarr;', 'woocommerce'), $product_data->get_title(), $product_data->get_stock_quantity(), $product_qty_in_cart[$variation_id]));
                 }
                 return false;
             }
             // Products
         } else {
             if (isset($product_qty_in_cart[$product_id]) && !$product_data->has_enough_stock($product_qty_in_cart[$product_id] + $quantity)) {
                 if (!$silent) {
                     $woocommerce->add_error(sprintf(__('<a href="%s" class="button">%s</a>You cannot add that amount to the cart since there is not enough stock of "%s" &mdash; we have %s in stock and you already have %s in your cart.', 'woo-bundles'), get_permalink(woocommerce_get_page_id('cart')), __('View Cart &rarr;', 'woocommerce'), $product_data->get_title(), $product_data->get_stock_quantity(), $product_qty_in_cart[$product_id]));
                 }
                 return false;
             }
         }
     }
     return true;
 }