• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

PHP WC_Cache_Helper类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了PHP中WC_Cache_Helper的典型用法代码示例。如果您正苦于以下问题:PHP WC_Cache_Helper类的具体用法?PHP WC_Cache_Helper怎么用?PHP WC_Cache_Helper使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



在下文中一共展示了WC_Cache_Helper类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的PHP代码示例。

示例1: delete_simple_flat_rate

 /**
  * Delete the simple flat rate.
  *
  * @since 2.3
  */
 public static function delete_simple_flat_rate()
 {
     delete_option('woocommerce_flat_rate_settings');
     delete_option('woocommerce_flat_rate');
     WC_Cache_Helper::get_transient_version('shipping', true);
     WC()->shipping->unregister_shipping_methods();
 }
开发者ID:Korkey128k,项目名称:woocommerce,代码行数:12,代码来源:class-wc-helper-shipping.php


示例2: clear_transients

 /**
  * Clear the product/shop transients cache.
  *
  * ## EXAMPLES
  *
  *     wp wc tool clear_transients
  *
  * @since 2.5.0
  */
 public function clear_transients($args, $assoc_args)
 {
     wc_delete_product_transients();
     wc_delete_shop_order_transients();
     WC_Cache_Helper::get_transient_version('shipping', true);
     WP_CLI::success('Product transients and shop order transients were cleared.');
 }
开发者ID:bitoncoin,项目名称:woocommerce,代码行数:16,代码来源:class-wc-cli-tool.php


示例3: cancel_booking

 /**
  * Cancel a booking.
  */
 public static function cancel_booking()
 {
     if (isset($_GET['cancel_booking']) && isset($_GET['booking_id'])) {
         $booking_id = absint($_GET['booking_id']);
         $booking = get_wc_booking($booking_id);
         $booking_can_cancel = $booking->has_status(apply_filters('woocommerce_valid_booking_statuses_for_cancel', array('unpaid', 'pending-confirmation', 'confirmed', 'paid')));
         $redirect = $_GET['redirect'];
         if ($booking->has_status('cancelled')) {
             // Already cancelled - take no action
         } elseif ($booking_can_cancel && $booking->id == $booking_id && isset($_GET['_wpnonce']) && wp_verify_nonce($_GET['_wpnonce'], 'woocommerce-bookings-cancel_booking')) {
             // Cancel the booking
             $booking->update_status('cancelled');
             WC_Cache_Helper::get_transient_version('bookings', true);
             // Message
             wc_add_notice(apply_filters('woocommerce_booking_cancelled_notice', __('Your booking was cancelled.', 'woocommerce-bookings')), apply_filters('woocommerce_booking_cancelled_notice_type', 'notice'));
             do_action('woocommerce_bookings_cancelled_booking', $booking->id);
         } elseif (!$booking_can_cancel) {
             wc_add_notice(__('Your booking can no longer be cancelled. Please contact us if you need assistance.', 'woocommerce-bookings'), 'error');
         } else {
             wc_add_notice(__('Invalid booking.', 'woocommerce-bookings'), 'error');
         }
         if ($redirect) {
             wp_safe_redirect($redirect);
             exit;
         }
     }
 }
开发者ID:tonyvu1985,项目名称:appletutorings,代码行数:30,代码来源:class-wc-booking-form-handler.php


示例4: remove_mock_zones

 /**
  * Remove all zones
  */
 public static function remove_mock_zones()
 {
     global $wpdb;
     $wpdb->query("TRUNCATE TABLE {$wpdb->prefix}woocommerce_shipping_zone_methods;");
     $wpdb->query("TRUNCATE TABLE {$wpdb->prefix}woocommerce_shipping_zone_locations;");
     $wpdb->query("TRUNCATE TABLE {$wpdb->prefix}woocommerce_shipping_zones;");
     WC_Cache_Helper::incr_cache_prefix('shipping_zones');
 }
开发者ID:coderkevin,项目名称:woocommerce,代码行数:11,代码来源:class-wc-helper-shipping-zones.php


示例5: delete_product_query_transients

 /**
  * Delete product view transients when needed e.g. when post status changes, or visibility/stock status is modified.
  */
 public static function delete_product_query_transients()
 {
     // Increments the transient version to invalidate cache
     WC_Cache_Helper::get_transient_version('product_query', true);
     // If not using an external caching system, we can clear the transients out manually and avoid filling our DB
     if (!wp_using_ext_object_cache()) {
         global $wpdb;
         $wpdb->query("\n\t\t\t\tDELETE FROM `{$wpdb->options}`\n\t\t\t\tWHERE `option_name` LIKE ('\\_transient\\_wc\\_uf\\_pid\\_%')\n\t\t\t\tOR `option_name` LIKE ('\\_transient\\_timeout\\_wc\\_uf\\_pid\\_%')\n\t\t\t\tOR `option_name` LIKE ('\\_transient\\_wc\\_products\\_will\\_display\\_%')\n\t\t\t\tOR `option_name` LIKE ('\\_transient\\_timeout\\_wc\\_products\\_will\\_display\\_%')\n\t\t\t");
     }
 }
开发者ID:abcode619,项目名称:wpstuff,代码行数:13,代码来源:class-wc-post-data.php


示例6: product_loop

    /**
     * Loop over found products.
     * @param  array $query_args
     * @param  array $atts
     * @param  string $loop_name
     * @return string
     */
    private static function product_loop($query_args, $atts, $loop_name)
    {
        global $woocommerce_loop;
        $columns = absint($atts['columns']);
        $woocommerce_loop['columns'] = $columns;
        $woocommerce_loop['name'] = $loop_name;
        $transient_name = 'wc_loop' . substr(md5(json_encode($query_args) . $loop_name), 28) . WC_Cache_Helper::get_transient_version('product_query');
        $products = get_transient($transient_name);
        if (false === $products || !is_a($products, 'WP_Query')) {
            $products = new WP_Query(apply_filters('woocommerce_shortcode_products_query', $query_args, $atts, $loop_name));
            set_transient($transient_name, $products, DAY_IN_SECONDS * 30);
        }
        ob_start();
        if ($products->have_posts()) {
            ?>

			<?php 
            do_action("woocommerce_shortcode_before_{$loop_name}_loop", $atts);
            ?>

			<?php 
            woocommerce_product_loop_start();
            ?>

				<?php 
            while ($products->have_posts()) {
                $products->the_post();
                ?>

					<?php 
                wc_get_template_part('content', 'product');
                ?>

				<?php 
            }
            // end of the loop.
            ?>

			<?php 
            woocommerce_product_loop_end();
            ?>

			<?php 
            do_action("woocommerce_shortcode_after_{$loop_name}_loop", $atts);
            ?>

			<?php 
        } else {
            do_action("woocommerce_shortcode_{$loop_name}_loop_no_results", $atts);
        }
        woocommerce_reset_loop();
        wp_reset_postdata();
        return '<div class="woocommerce columns-' . $columns . '">' . ob_get_clean() . '</div>';
    }
开发者ID:shivapoudel,项目名称:woocommerce,代码行数:61,代码来源:class-wc-shortcodes.php


示例7: save

 /**
  * Save settings.
  */
 public function save()
 {
     global $current_section, $wpdb;
     if (!$current_section) {
         $settings = $this->get_settings();
         WC_Admin_Settings::save_fields($settings);
     } elseif (!empty($_POST['tax_rate_country'])) {
         $this->save_tax_rates();
     }
     WC_Cache_Helper::incr_cache_prefix('taxes');
 }
开发者ID:bitoncoin,项目名称:woocommerce,代码行数:14,代码来源:class-wc-settings-tax.php


示例8: get_bookings_for_objects

 /**
  * Gets bookings for product ids and resource ids
  * @param  array  $ids
  * @param  array  $status
  * @return array of WC_Booking objects
  */
 public static function get_bookings_for_objects($ids = array(), $status = array('confirmed', 'paid'))
 {
     $transient_name = 'book_fo_' . md5(http_build_query(array($ids, $status, WC_Cache_Helper::get_transient_version('bookings'))));
     if (false === ($booking_ids = get_transient($transient_name))) {
         $booking_ids = self::get_bookings_for_objects_query($ids, $status);
         set_transient($transient_name, $booking_ids, DAY_IN_SECONDS * 30);
     }
     $bookings = array();
     foreach ($booking_ids as $booking_id) {
         $bookings[] = get_wc_booking($booking_id);
     }
     return $bookings;
 }
开发者ID:tonyvu1985,项目名称:appletutorings,代码行数:19,代码来源:class-wc-bookings-controller.php


示例9: get_children

 /**
  * Return the products children posts.
  *
  * @access public
  * @return array
  */
 public function get_children()
 {
     if (!is_array($this->children) || empty($this->children)) {
         $transient_name = 'wc_product_children_ids_' . $this->id . WC_Cache_Helper::get_transient_version('product');
         $this->children = get_transient($transient_name);
         if (empty($this->children)) {
             $args = apply_filters('woocommerce_grouped_children_args', array('post_parent' => $this->id, 'post_type' => 'product', 'orderby' => 'menu_order', 'order' => 'ASC', 'fields' => 'ids', 'post_status' => 'publish', 'numberposts' => -1));
             $this->children = get_posts($args);
             set_transient($transient_name, $this->children, YEAR_IN_SECONDS);
         }
     }
     return (array) $this->children;
 }
开发者ID:amusiiko,项目名称:armo,代码行数:19,代码来源:class-wc-product-grouped.php


示例10: get_total_stock

 /**
  * Get total stock.
  *
  * This is the stock of parent and children combined.
  *
  * @access public
  * @return int
  */
 public function get_total_stock()
 {
     if (empty($this->total_stock)) {
         $transient_name = 'wc_product_total_stock_' . $this->id . WC_Cache_Helper::get_transient_version('product');
         if (false === ($this->total_stock = get_transient($transient_name))) {
             $this->total_stock = $this->stock;
             if (sizeof($this->get_children()) > 0) {
                 foreach ($this->get_children() as $child_id) {
                     $stock = get_post_meta($child_id, '_stock', true);
                     if ($stock != '') {
                         $this->total_stock += wc_stock_amount($stock);
                     }
                 }
             }
             set_transient($transient_name, $this->total_stock, DAY_IN_SECONDS * 30);
         }
     }
     return wc_stock_amount($this->total_stock);
 }
开发者ID:Junaid-Farid,项目名称:gocnex,代码行数:27,代码来源:class-wc-product-grouped.php


示例11: get_related

 /**
  * Returns array that conintains ids of related tours.
  *
  * @param  int   $limit
  * @return array
  */
 public function get_related($limit = 5)
 {
     $transient_name = 'wc_related_' . $limit . '_' . $this->id . WC_Cache_Helper::get_transient_version('product');
     if (false === ($related_posts = get_transient($transient_name))) {
         global $wpdb;
         // Related products are found from category and tag
         $tags_array = $this->get_related_terms('product_tag');
         $tour_cats_array = $this->get_related_terms('tour_category');
         // Don't bother if none are set
         if (sizeof($tour_cats_array) == 1 && sizeof($tags_array) == 1) {
             $related_posts = array();
         } else {
             // Sanitize
             $exclude_ids = array_map('absint', array_merge(array(0, $this->id), $this->get_upsells()));
             // Generate query
             $query = $this->build_related_tours_query($tour_cats_array, $tags_array, $exclude_ids, $limit);
             // Get the posts
             $related_posts = $wpdb->get_col(implode(' ', $query));
         }
         set_transient($transient_name, $related_posts, DAY_IN_SECONDS * 30);
     }
     shuffle($related_posts);
     return $related_posts;
 }
开发者ID:j-kenneth,项目名称:Expeero,代码行数:30,代码来源:WC_Product_Tour.php


示例12: wc_scheduled_sales

/**
 * Function which handles the start and end of scheduled sales via cron.
 *
 * @access public
 */
function wc_scheduled_sales()
{
    global $wpdb;
    // Sales which are due to start
    $product_ids = $wpdb->get_col($wpdb->prepare("\n\t\tSELECT postmeta.post_id FROM {$wpdb->postmeta} as postmeta\n\t\tLEFT JOIN {$wpdb->postmeta} as postmeta_2 ON postmeta.post_id = postmeta_2.post_id\n\t\tLEFT JOIN {$wpdb->postmeta} as postmeta_3 ON postmeta.post_id = postmeta_3.post_id\n\t\tWHERE postmeta.meta_key = '_sale_price_dates_from'\n\t\tAND postmeta_2.meta_key = '_price'\n\t\tAND postmeta_3.meta_key = '_sale_price'\n\t\tAND postmeta.meta_value > 0\n\t\tAND postmeta.meta_value < %s\n\t\tAND postmeta_2.meta_value != postmeta_3.meta_value\n\t", current_time('timestamp')));
    if ($product_ids) {
        foreach ($product_ids as $product_id) {
            $sale_price = get_post_meta($product_id, '_sale_price', true);
            if ($sale_price) {
                update_post_meta($product_id, '_price', $sale_price);
            } else {
                // No sale price!
                update_post_meta($product_id, '_sale_price_dates_from', '');
                update_post_meta($product_id, '_sale_price_dates_to', '');
            }
            $parent = wp_get_post_parent_id($product_id);
            // Sync parent
            if ($parent) {
                // We can force variable product prices to sync up by removing their min price meta
                delete_post_meta($parent, '_min_price_variation_id');
                // Grouped products need syncing via a function
                $this_product = wc_get_product($product_id);
                if ($this_product->is_type('simple')) {
                    $this_product->grouped_product_sync();
                }
            }
        }
        delete_transient('wc_products_onsale');
    }
    // Sales which are due to end
    $product_ids = $wpdb->get_col($wpdb->prepare("\n\t\tSELECT postmeta.post_id FROM {$wpdb->postmeta} as postmeta\n\t\tLEFT JOIN {$wpdb->postmeta} as postmeta_2 ON postmeta.post_id = postmeta_2.post_id\n\t\tLEFT JOIN {$wpdb->postmeta} as postmeta_3 ON postmeta.post_id = postmeta_3.post_id\n\t\tWHERE postmeta.meta_key = '_sale_price_dates_to'\n\t\tAND postmeta_2.meta_key = '_price'\n\t\tAND postmeta_3.meta_key = '_regular_price'\n\t\tAND postmeta.meta_value > 0\n\t\tAND postmeta.meta_value < %s\n\t\tAND postmeta_2.meta_value != postmeta_3.meta_value\n\t", current_time('timestamp')));
    if ($product_ids) {
        foreach ($product_ids as $product_id) {
            $regular_price = get_post_meta($product_id, '_regular_price', true);
            update_post_meta($product_id, '_price', $regular_price);
            update_post_meta($product_id, '_sale_price', '');
            update_post_meta($product_id, '_sale_price_dates_from', '');
            update_post_meta($product_id, '_sale_price_dates_to', '');
            $parent = wp_get_post_parent_id($product_id);
            // Sync parent
            if ($parent) {
                // Grouped products need syncing via a function
                $this_product = wc_get_product($product_id);
                if ($this_product->is_type('simple')) {
                    $this_product->grouped_product_sync();
                }
            }
        }
        WC_Cache_Helper::get_transient_version('product', true);
        delete_transient('wc_products_onsale');
    }
}
开发者ID:jameztrue,项目名称:woocommerce,代码行数:57,代码来源:wc-product-functions.php


示例13: get_customer_location

 /**
  * Locate user via AJAX
  */
 public static function get_customer_location()
 {
     $location_hash = WC_Cache_Helper::geolocation_ajax_get_location_hash();
     wp_send_json_success(array('hash' => $location_hash));
 }
开发者ID:JodiWarren,项目名称:woocommerce,代码行数:8,代码来源:class-wc-ajax.php


示例14: get_variation_prices

 /**
  * Get an array of all sale and regular prices from all variations. This is used for example when displaying the price range at variable product level or seeing if the variable product is on sale.
  *
  * Can be filtered by plugins which modify costs, but otherwise will include the raw meta costs unlike get_price() which runs costs through the woocommerce_get_price filter.
  * This is to ensure modified prices are not cached, unless intended.
  *
  * @param  bool $display Are prices for display? If so, taxes will be calculated.
  * @return array() Array of RAW prices, regular prices, and sale prices with keys set to variation ID.
  */
 public function get_variation_prices($display = false)
 {
     global $wp_filter;
     /**
      * Transient name for storing prices for this product (note: Max transient length is 45)
      * @since 2.5.0 a single transient is used per product for all prices, rather than many transients per product.
      */
     $transient_name = 'wc_var_prices_' . $this->id;
     /**
      * Create unique cache key based on the tax location (affects displayed/cached prices), product version and active price filters.
      * DEVELOPERS should filter this hash if offering conditonal pricing to keep it unique.
      * @var string
      */
     if ($display) {
         $price_hash = array(get_option('woocommerce_tax_display_shop', 'excl'), WC_Tax::get_rates());
     } else {
         $price_hash = array(false);
     }
     $filter_names = array('woocommerce_variation_prices_price', 'woocommerce_variation_prices_regular_price', 'woocommerce_variation_prices_sale_price');
     foreach ($filter_names as $filter_name) {
         if (!empty($wp_filter[$filter_name])) {
             $price_hash[$filter_name] = array();
             foreach ($wp_filter[$filter_name] as $priority => $callbacks) {
                 $price_hash[$filter_name][] = array_values(wp_list_pluck($callbacks, 'function'));
             }
         }
     }
     $price_hash = md5(json_encode(apply_filters('woocommerce_get_variation_prices_hash', $price_hash, $this, $display)));
     // If the value has already been generated, we don't need to grab the values again.
     if (empty($this->prices_array[$price_hash])) {
         // Get value of transient
         $prices_array = array_filter((array) json_decode(strval(get_transient($transient_name)), true));
         // If the product version has changed, reset cache
         if (empty($prices_array['version']) || $prices_array['version'] !== WC_Cache_Helper::get_transient_version('product')) {
             $this->prices_array = array('version' => WC_Cache_Helper::get_transient_version('product'));
         }
         // If the prices are not stored for this hash, generate them
         if (empty($prices_array[$price_hash])) {
             $prices = array();
             $regular_prices = array();
             $sale_prices = array();
             $variation_ids = $this->get_children(true);
             foreach ($variation_ids as $variation_id) {
                 if ($variation = $this->get_child($variation_id)) {
                     $price = apply_filters('woocommerce_variation_prices_price', $variation->price, $variation, $this);
                     $regular_price = apply_filters('woocommerce_variation_prices_regular_price', $variation->regular_price, $variation, $this);
                     $sale_price = apply_filters('woocommerce_variation_prices_sale_price', $variation->sale_price, $variation, $this);
                     // Skip empty prices
                     if ('' === $price) {
                         continue;
                     }
                     // If sale price does not equal price, the product is not yet on sale
                     if ($sale_price === $regular_price || $sale_price !== $price) {
                         $sale_price = $regular_price;
                     }
                     // If we are getting prices for display, we need to account for taxes
                     if ($display) {
                         if ('incl' === get_option('woocommerce_tax_display_shop')) {
                             $price = '' === $price ? '' : $variation->get_price_including_tax(1, $price);
                             $regular_price = '' === $regular_price ? '' : $variation->get_price_including_tax(1, $regular_price);
                             $sale_price = '' === $sale_price ? '' : $variation->get_price_including_tax(1, $sale_price);
                         } else {
                             $price = '' === $price ? '' : $variation->get_price_excluding_tax(1, $price);
                             $regular_price = '' === $regular_price ? '' : $variation->get_price_excluding_tax(1, $regular_price);
                             $sale_price = '' === $sale_price ? '' : $variation->get_price_excluding_tax(1, $sale_price);
                         }
                     }
                     $prices[$variation_id] = wc_format_decimal($price, wc_get_price_decimals());
                     $regular_prices[$variation_id] = wc_format_decimal($regular_price, wc_get_price_decimals());
                     $sale_prices[$variation_id] = wc_format_decimal($sale_price . '.00', wc_get_price_decimals());
                 }
             }
             asort($prices);
             asort($regular_prices);
             asort($sale_prices);
             $prices_array[$price_hash] = array('price' => $prices, 'regular_price' => $regular_prices, 'sale_price' => $sale_prices);
             set_transient($transient_name, json_encode($prices_array), DAY_IN_SECONDS * 30);
         }
         /**
          * Give plugins one last chance to filter the variation prices array which has been generated.
          */
         $this->prices_array[$price_hash] = apply_filters('woocommerce_variation_prices', $prices_array[$price_hash], $this, $display);
     }
     /**
      * Return the values.
      */
     return $this->prices_array[$price_hash];
 }
开发者ID:jesusmarket,项目名称:jesusmarket,代码行数:97,代码来源:class-wc-product-variable.php


示例15: get_item_meta_array

 /**
  * Get all item meta data in array format in the order it was saved. Does not group meta by key like get_item_meta().
  *
  * @param mixed $order_item_id
  * @return array of objects
  */
 public function get_item_meta_array($order_item_id)
 {
     global $wpdb;
     // Get cache key - uses get_cache_prefix to invalidate when needed
     $cache_key = WC_Cache_Helper::get_cache_prefix('orders') . 'item_meta_array_' . $order_item_id;
     $item_meta_array = wp_cache_get($cache_key, 'orders');
     if (false === $item_meta_array) {
         $item_meta_array = array();
         $metadata = $wpdb->get_results($wpdb->prepare("SELECT meta_key, meta_value, meta_id FROM {$wpdb->prefix}woocommerce_order_itemmeta WHERE order_item_id = %d ORDER BY meta_id", absint($order_item_id)));
         foreach ($metadata as $metadata_row) {
             $item_meta_array[$metadata_row->meta_id] = (object) array('key' => $metadata_row->meta_key, 'value' => $metadata_row->meta_value);
         }
         wp_cache_set($cache_key, $item_meta_array, 'orders');
     }
     return $item_meta_array;
 }
开发者ID:estrategasdigitales,项目名称:venone,代码行数:22,代码来源:abstract-wc-order.php


示例16: get_related

 /**
  * Get and return related products.
  *
  * @param int $limit (default: 5)
  * @return array Array of post IDs
  */
 public function get_related($limit = 5)
 {
     global $wpdb;
     $limit = absint($limit);
     // Related products are found from category and tag
     $tags_array = array(0);
     $cats_array = array(0);
     // Get tags
     $terms = apply_filters('woocommerce_get_related_product_tag_terms', wp_get_post_terms($this->id, 'product_tag'), $this->id);
     foreach ($terms as $term) {
         $tags_array[] = $term->term_id;
     }
     // Get categories
     $terms = apply_filters('woocommerce_get_related_product_cat_terms', wp_get_post_terms($this->id, 'product_cat'), $this->id);
     foreach ($terms as $term) {
         $cats_array[] = $term->term_id;
     }
     // Don't bother if none are set
     if (sizeof($cats_array) == 1 && sizeof($tags_array) == 1) {
         return array();
     }
     // Sanitize
     $cats_array = array_map('absint', $cats_array);
     $tags_array = array_map('absint', $tags_array);
     $exclude_ids = array_map('absint', array_merge(array(0, $this->id), $this->get_upsells()));
     // Generate query
     $query = array();
     $query['fields'] = "SELECT DISTINCT ID FROM {$wpdb->posts} p";
     $query['join'] = " INNER JOIN {$wpdb->postmeta} pm ON ( pm.post_id = p.ID AND pm.meta_key='_visibility' )";
     $query['join'] .= " INNER JOIN {$wpdb->term_relationships} tr ON (p.ID = tr.object_id)";
     $query['join'] .= " INNER JOIN {$wpdb->term_taxonomy} tt ON (tr.term_taxonomy_id = tt.term_taxonomy_id)";
     $query['join'] .= " INNER JOIN {$wpdb->terms} t ON (t.term_id = tt.term_id)";
     if (get_option('woocommerce_hide_out_of_stock_items') === 'yes') {
         $query['join'] .= " INNER JOIN {$wpdb->postmeta} pm2 ON ( pm2.post_id = p.ID AND pm2.meta_key='_stock_status' )";
     }
     $query['where'] = " WHERE 1=1";
     $query['where'] .= " AND p.post_status = 'publish'";
     $query['where'] .= " AND p.post_type = 'product'";
     $query['where'] .= " AND p.ID NOT IN ( " . implode(',', $exclude_ids) . " )";
     $query['where'] .= " AND pm.meta_value IN ( 'visible', 'catalog' )";
     if (get_option('woocommerce_hide_out_of_stock_items') === 'yes') {
         $query['where'] .= " AND pm2.meta_value = 'instock'";
     }
     if (apply_filters('woocommerce_product_related_posts_relate_by_category', true, $this->id)) {
         $query['where'] .= " AND ( tt.taxonomy = 'product_cat' AND t.term_id IN ( " . implode(',', $cats_array) . " ) )";
         $andor = 'OR';
     } else {
         $andor = 'AND';
     }
     // when query is OR - need to check against excluded ids again
     if (apply_filters('woocommerce_product_related_posts_relate_by_tag', true, $this->id)) {
         $query['where'] .= " {$andor} ( ( tt.taxonomy = 'product_tag' AND t.term_id IN ( " . implode(',', $tags_array) . " ) )";
         $query['where'] .= " AND p.ID NOT IN ( " . implode(',', $exclude_ids) . " ) )";
     }
     $query = apply_filters('woocommerce_product_related_posts_query', $query, $this->id);
     // How many rows total?
     $max_related_posts_transient_name = 'wc_max_related_' . $this->id . WC_Cache_Helper::get_transient_version('product');
     if (false === ($max_related_posts = get_transient($max_related_posts_transient_name))) {
         $max_related_posts_query = $query;
         $max_related_posts_query['fields'] = "SELECT COUNT(DISTINCT ID) FROM {$wpdb->posts} p";
         $max_related_posts = absint($wpdb->get_var(implode(' ', apply_filters('woocommerce_product_max_related_posts_query', $max_related_posts_query, $this->id))));
         set_transient($max_related_posts_transient_name, $max_related_posts, DAY_IN_SECONDS * 30);
     }
     // Generate limit
     $offset = $max_related_posts < $limit ? 0 : absint(rand(0, $max_related_posts - $limit));
     $query['limits'] = " LIMIT {$offset}, {$limit} ";
     // Get the posts
     $related_posts = $wpdb->get_col(implode(' ', $query));
     return $related_posts;
 }
开发者ID:nathanielks,项目名称:woocommerce,代码行数:76,代码来源:abstract-wc-product.php


示例17: calculate_shipping_for_package

 /**
  * calculate_shipping_for_package function.
  *
  * Calculates each shipping methods cost. Rates are cached based on the package to speed up calculations.
  *
  * @access public
  * @param array $package cart items
  * @return array
  * @todo Return array() instead of false for consistent return type?
  */
 public function calculate_shipping_for_package($package = array())
 {
     if (!$this->enabled) {
         return false;
     }
     if (!$package) {
         return false;
     }
     // Check if we need to recalculate shipping for this package
     $package_hash = 'wc_ship_' . md5(json_encode($package) . WC_Cache_Helper::get_transient_version('shipping'));
     $status_options = get_option('woocommerce_status_options', array());
     if (false === ($stored_rates = get_transient($package_hash)) || !empty($status_options['shipping_debug_mode'])) {
         // Calculate shipping method rates
         $package['rates'] = array();
         foreach ($this->load_shipping_methods($package) as $shipping_method) {
             if ($shipping_method->is_available($package) && (empty($package['ship_via']) || in_array($shipping_method->id, $package['ship_via']))) {
                 // Reset Rates
                 $shipping_method->rates = array();
                 // Calculate Shipping for package
                 $shipping_method->calculate_shipping($package);
                 // Place rates in package array
                 if (!empty($shipping_method->rates) && is_array($shipping_method->rates)) {
                     foreach ($shipping_method->rates as $rate) {
                         $package['rates'][$rate->id] = $rate;
                     }
                 }
             }
         }
         // Filter the calculated rates
         $package['rates'] = apply_filters('woocommerce_package_rates', $package['rates'], $package);
         // Store
         set_transient($package_hash, $package['rates'], 60 * 60);
         // Cached for an hour
     } else {
         $package['rates'] = $stored_rates;
     }
     return $package;
 }
开发者ID:CannedHead,项目名称:feelingsurf,代码行数:48,代码来源:class-wc-shipping.php


示例18: get_coupon_id_from_code

 /**
  * Get a coupon ID from it's code.
  * @since 2.5.0 woocommerce_coupon_code_query was removed in favour of woocommerce_get_coupon_id_from_code filter on the return. wp_cache was also implemented.
  * @param  string $code
  * @return int
  */
 private function get_coupon_id_from_code($code)
 {
     global $wpdb;
     $coupon_id = wp_cache_get(WC_Cache_Helper::get_cache_prefix('coupons') . 'coupon_id_from_code_' . $code, 'coupons');
     if (false === $coupon_id) {
         $sql = $wpdb->prepare("SELECT ID FROM {$wpdb->posts} WHERE post_title = %s AND post_type = 'shop_coupon' AND post_status = 'publish'", $this->code);
         $coupon_id = apply_filters('woocommerce_get_coupon_id_from_code', $wpdb->get_var($sql), $this->code);
         wp_cache_set(WC_Cache_Helper::get_cache_prefix('coupons') . 'coupon_id_from_code_' . $code, $coupon_id, 'coupons');
     }
     return absint($coupon_id);
 }
开发者ID:naveeninja,项目名称:woocommerce,代码行数:17,代码来源:class-wc-coupon.php


示例19: woocommerce_products_will_display

 /**
  * Check if we will be showing products or not (and not subcats only)
  *
  * @access public
  * @subpackage	Loop
  * @return bool
  */
 function woocommerce_products_will_display()
 {
     if (is_shop()) {
         return get_option('woocommerce_shop_page_display') != 'subcategories';
     }
     if (!is_product_taxonomy()) {
         return false;
     }
     if (is_search() || is_filtered() || is_paged()) {
         return true;
     }
     $term = get_queried_object();
     if (is_product_category()) {
         switch (get_woocommerce_term_meta($term->term_id, 'display_type', true)) {
             case 'subcategories':
                 // Nothing - we want to continue to see if there are products/subcats
                 break;
             case 'products':
             case 'both':
                 return true;
                 break;
             default:
                 // Default - no setting
                 if (get_option('woocommerce_category_archive_display') != 'subcategories') {
                     return true;
                 }
                 break;
         }
     }
     // Begin subcategory logic
     global $wpdb;
     $parent_id = empty($term->term_id) ? 0 : $term->term_id;
     $taxonomy = empty($term->taxonomy) ? '' : $term->taxonomy;
     $products_will_display = true;
     if (!$parent_id && !$taxonomy) {
         return true;
     }
     $transient_name = 'wc_products_will_display_' . $parent_id . WC_Cache_Helper::get_transient_version('product_query');
     if (false === ($products_will_display = get_transient($transient_name))) {
         $has_children = $wpdb->get_col($wpdb->prepare("SELECT term_id FROM {$wpdb->term_taxonomy} WHERE parent = %d AND taxonomy = %s", $parent_id, $taxonomy));
         if ($has_children) {
             // Check terms have products inside - parents first. If products are found inside, subcats will be shown instead of products so we can return false.
             if (sizeof(get_objects_in_term($has_children, $taxonomy)) > 0) {
                 $products_will_display = false;
             } else {
                 // If we get here, the parents were empty so we're forced to check children
                 foreach ($has_children as $term) {
                     $children = get_term_children($term, $taxonomy);
                     if (sizeof(get_objects_in_term($children, $taxonomy)) > 0) {
                         $products_will_display = false;
                         break;
                     }
                 }
             }
         } else {
             $products_will_display = true;
         }
     }
     set_transient($transient_name, $products_will_display, YEAR_IN_SECONDS);
     return $products_will_display;
 }
开发者ID:uwitec,项目名称:findgreatmaster,代码行数:68,代码来源:wc-template-functions.php


示例20: read_price_data

 /**
  * Get an array of all sale and regular prices from all variations. This is used for example when displaying the price range at variable product level or seeing if the variable product is on sale.
  *
  * Can be filtered by plugins which modify costs, but otherwise will include the raw meta costs unlike get_price() which runs costs through the woocommerce_get_price filter.
  * This is to ensure modified prices are not cached, unless intended.
  *
  * @since  2.7.0
  * @param  WC_Product
  * @param  bool $include_taxes If taxes should be calculated or not.
  */
 private function read_price_data(&$product, $include_taxes = false)
 {
     global $wp_filter;
     /**
      * Transient name for storing prices for this product (note: Max transient length is 45)
      * @since 2.5.0 a single transient is used per product for all prices, rather than many transients per product.
      */
     $transient_name = 'wc_var_prices_' . $product->get_id();
     /**
      * Create unique cache key based on the tax location (affects displayed/cached prices), product version and active price filters.
      * DEVELOPERS should filter this hash if offering conditonal pricing to keep it unique.
      * @var string
      */
     $price_hash = $include_taxes ? array(get_option('woocommerce_tax_display_shop', 'excl'), WC_Tax::get_rates()) : array(false);
     $filter_names = array('woocommerce_variation_prices_price', 'woocommerce_variation_prices_regular_price', 'woocommerce_variation_prices_sale_price');
     foreach ($filter_names as $filter_name) {
         if (!empty($wp_filter[$filter_name])) {
             $price_hash[$filter_name] = array();
             foreach ($wp_filter[$filter_name] as $priority => $callbacks) {
                 $price_hash[$filter_name][] = array_values(wp_list_pluck($callbacks, 'function'));
             }
         }
     }
     $price_hash[] = WC_Cache_Helper::get_transient_version('product');
     $price_hash = md5(json_encode(apply_filters('woocommerce_get_variation_prices_hash', $price_hash, $product, $include_taxes)));
     /**
      * $this->prices_array is an array of values which may have been modified from what is stored in transients - this may not match $transient_cached_prices_array.
      * If the value has already been generated, we don't need to grab the values again so just return them. They are already filtered.
      */
     if (!empty($this->prices_array[$price_hash])) {
         if ($include_taxes) {
             $product->set_variation_prices_including_taxes($this->prices_array[$price_hash]);
         } else {
             $product->set_variation_prices($this->prices_array[$price_hash]);
         }
         /**
          * No locally cached value? Get the data from the transient or generate it.
          */
     } else {
         // Get value of transient
         $transient_cached_prices_array = array_filter((array) json_decode(strval(get_transient($transient_name)), true));
         // If the product version has changed since the transient was last saved, reset the transient cache.
         if (empty($transient_cached_prices_array['version']) || WC_Cache_Helper::get_transient_version('product') !== $transient_cached_prices_array['version']) {
             $transient_cached_prices_array = array('version' => WC_Cache_Helper::get_transient_version('product'));
         }
         // If the prices are not stored for this hash, generate them and add to the transient.
         if (empty($transient_cached_prices_array[$price_hash])) {
             $prices = array();
             $regular_prices = array();
             $sale_prices = array();
             $variation_ids = $product->get_visible_children();
             foreach ($variation_ids as $variation_id) {
                 if ($variation = wc_get_product($variation_id)) {
                     $price = apply_filters('woocommerce_variation_prices_price', $variation->get_price('edit'), $variation, $product);
                     $regular_price = apply_filters('woocommerce_variation_prices_regular_price', $variation->get_regular_price('edit'), $variation, $product);
                     $sale_price = apply_filters('woocommerce_variation_prices_sale_price', $variation->get_sale_price('edit'), $variation, $product);
                     // Skip empty prices
                     if ('' === $price) {
                         continue;
                     }
                     // If sale price does not equal price, the product is not yet on sale
                     if ($sale_price === $regular_price || $sale_price !== $price) {
                         $sale_price = $regular_price;
                     }
                     // If we are getting prices for display, we need to account for taxes
                     if ($include_taxes) {
                         if ('incl' === get_option('woocommerce_tax_display_shop')) {
                             $price = '' === $price ? '' : wc_get_price_including_tax($variation, array('qty' => 1, 'price' => $price));
                             $regular_price = '' === $regular_price ? '' : wc_get_price_including_tax($variation, array('qty' => 1, 'price' => $regular_price));
                             $sale_price = '' === $sale_price ? '' : wc_get_pri 

鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
PHP WC_Challenge类代码示例发布时间:2022-05-23
下一篇:
PHP WC_Admin_Settings类代码示例发布时间:2022-05-23
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap