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

PHP wpsc_get_product_terms函数代码示例

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

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



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

示例1: __construct

 private function __construct($product_id)
 {
     $this->product_id = $product_id;
     $terms = wpsc_get_product_terms($product_id, 'wpsc-variation');
     foreach ($terms as $term) {
         if ($term->parent == 0) {
             $this->variation_sets[$term->term_id] = $term->name;
         } else {
             if (!array_key_exists($term->parent, $this->variation_terms)) {
                 $this->variation_terms[$term->parent] = array();
             }
             $this->variation_terms[$term->parent][$term->term_id] = $term->name;
         }
     }
 }
开发者ID:ashik968,项目名称:digiplot,代码行数:15,代码来源:product-variations.php


示例2: get_items

 private function get_items()
 {
     $cart = $this->log->get_cart_contents();
     $items = array();
     foreach ($cart as $item) {
         $obj = new stdClass();
         $obj->product_id = $item->prodid;
         $variations = wpsc_get_product_terms($item->prodid, 'wpsc-variation');
         $obj->variation_values = array();
         foreach ($variations as $term) {
             $obj->variation_values[(int) $term->parent] = (int) $term->term_id;
         }
         $obj->sku = get_post_meta($item->prodid, '_wpsc_sku', true);
         $obj->quantity = $item->quantity;
         $obj->unit_price = $item->price;
         $obj->product_name = $item->name;
         $obj->id = $item->id;
         $items[] = $obj;
     }
     return $items;
 }
开发者ID:ashik968,项目名称:digiplot,代码行数:21,代码来源:cart-item-table-order.php


示例3: wpsc_variations

 function wpsc_variations($product_id)
 {
     global $wpdb;
     $product_terms = wpsc_get_product_terms($product_id, 'wpsc-variation');
     $product_terms = wpsc_get_terms_variation_sort_filter($product_terms);
     $this->variation_groups = array();
     $this->first_variations = array();
     $this->all_associated_variations = array();
     foreach ($product_terms as $product_term) {
         if ($product_term->parent > 0) {
             $this->all_associated_variations[$product_term->parent][] = $product_term;
         } else {
             $this->variation_groups[] = $product_term;
         }
     }
     // Sort variation orders
     foreach ($this->all_associated_variations as $variation_set => &$terms) {
         $terms = wpsc_get_terms_variation_sort_filter($terms);
         array_unshift($this->all_associated_variations[$variation_set], (object) array('term_id' => 0, 'name' => __('-- Please Select --', 'wpsc')));
     }
     // Filters to hook into variations to sort etc.
     $this->variation_groups = apply_filters('wpsc_variation_groups', $this->variation_groups, $product_id);
     $this->all_associated_variations = apply_filters('wpsc_all_associated_variations', $this->all_associated_variations, $this->variation_groups, $product_id);
     //the parent_id is the variation group id we need to use this to alter the object ( variants )
     // inside each of these arrays
     $parent_ids = array_keys($this->all_associated_variations);
     foreach ((array) $parent_ids as $parent_id) {
         //sort the variants by their term_order which is the array key
         ksort($this->all_associated_variations[$parent_id]);
         //once sorted renumber the array keys back from 0
         $this->all_associated_variations[$parent_id] = array_values($this->all_associated_variations[$parent_id]);
     }
     foreach ((array) $this->variation_groups as $variation_group) {
         $variation_id = $variation_group->term_id;
         $this->first_variations[] = $this->all_associated_variations[$variation_id][0]->term_id;
     }
     $this->variation_group_count = count($this->variation_groups);
 }
开发者ID:dreamteam111,项目名称:dreamteam,代码行数:38,代码来源:variations.class.php


示例4: wpsc_duplicate_taxonomies

/**
 * Copy the taxonomies of a post to another post
 *
 * @uses get_object_taxonomies()  Gets taxonomies for the give object
 * @uses wp_get_object_terms()    Gets terms for the taxonomies
 * @uses wp_set_object_terms()    Sets the terms for a post object
 *
 * @param int       $id         req     ID of the post we are duping
 * @param int       $new_id     req     ID of the new post
 * @param string    $post_type  req     The post type we are setting
 */
function wpsc_duplicate_taxonomies($id, $new_id, $post_type)
{
    $taxonomies = get_object_taxonomies($post_type);
    //array("category", "post_tag");
    foreach ($taxonomies as $taxonomy) {
        $post_terms = wpsc_get_product_terms($id, $taxonomy);
        foreach ($post_terms as $post_term) {
            wp_set_object_terms($new_id, $post_term->slug, $taxonomy, true);
        }
    }
}
开发者ID:dreamteam111,项目名称:dreamteam,代码行数:22,代码来源:admin.php


示例5: wpsc_check_variation_stock_availability

/**
 * wpsc check variation stock availability function
 * @return string - the product price
 */
function wpsc_check_variation_stock_availability($product_id, $variations)
{
    $selected_post = get_posts(array('post_parent' => $product_id, 'post_type' => "wpsc-product", 'post_status' => 'any', 'suppress_filters' => true, 'numberposts' => -1));
    $selected_variation = false;
    foreach ($selected_post as $variation) {
        $matches = 0;
        $terms = wpsc_get_product_terms($variation->ID, 'wpsc-variation');
        foreach ($terms as $term) {
            if (in_array($term->term_id, $variations)) {
                $matches++;
            }
        }
        if ($matches == count($variations)) {
            $selected_variation = $variation->ID;
        }
    }
    if (!$selected_variation) {
        return false;
    }
    if (wpsc_product_has_stock($selected_variation)) {
        $stock = get_product_meta($selected_variation, 'stock', true);
        if ($stock === '') {
            return true;
        }
        return (int) $stock;
    }
    return 0;
}
开发者ID:AngryBird3,项目名称:WP-e-Commerce,代码行数:32,代码来源:template-tags.php


示例6: wpsc_edit_product_variations

/**
 * wpsc_edit_product_variations function.
 * this is the function to make child products using variations
 *
 * @access public
 * @param mixed $product_id
 * @param mixed $post_data
 * @return void
 */
function wpsc_edit_product_variations($product_id, $post_data)
{
    global $user_ID;
    $parent = get_post_field('post_parent', $product_id);
    if (!empty($parent)) {
        return;
    }
    $variations = array();
    $product_children = array();
    if (!isset($post_data['edit_var_val'])) {
        $post_data['edit_var_val'] = '';
    }
    $variations = (array) $post_data['edit_var_val'];
    // Generate the arrays for variation sets, values and combinations
    $wpsc_combinator = new wpsc_variation_combinator($variations);
    // Retrieve the array containing the variation set IDs
    $variation_sets = $wpsc_combinator->return_variation_sets();
    // Retrieve the array containing the combinations of each variation set to be associated with this product.
    $variation_values = $wpsc_combinator->return_variation_values();
    // Retrieve the array containing the combinations of each variation set to be associated with this product.
    $combinations = $wpsc_combinator->return_combinations();
    $product_terms = wpsc_get_product_terms($product_id, 'wpsc-variation');
    $variation_sets_and_values = array_merge($variation_sets, $variation_values);
    $variation_sets_and_values = apply_filters('wpsc_edit_product_variation_sets_and_values', $variation_sets_and_values, $product_id);
    wp_set_object_terms($product_id, $variation_sets_and_values, 'wpsc-variation');
    $parent_id = $_REQUEST['product_id'];
    $child_product_template = array('post_author' => $user_ID, 'post_content' => get_post_field('post_content', $parent_id, 'raw'), 'post_excerpt' => get_post_field('post_excerpt', $parent_id, 'raw'), 'post_title' => get_post_field('post_title', $parent_id, 'raw'), 'post_status' => 'inherit', 'post_type' => "wpsc-product", 'post_parent' => $product_id);
    $child_product_meta = get_post_custom($product_id);
    // here we loop through the combinations, get the term data and generate custom product names
    foreach ($combinations as $combination) {
        $term_names = array();
        $term_ids = array();
        $term_slugs = array();
        $product_values = $child_product_template;
        $combination_terms = get_terms('wpsc-variation', array('hide_empty' => 0, 'include' => implode(",", $combination), 'orderby' => 'parent'));
        foreach ($combination_terms as $term) {
            $term_ids[] = $term->term_id;
            $term_slugs[] = $term->slug;
            $term_names[] = $term->name;
        }
        $product_values['post_title'] .= " (" . implode(", ", $term_names) . ")";
        $product_values['post_name'] = sanitize_title($product_values['post_title']);
        $selected_post = get_posts(array('name' => $product_values['post_name'], 'post_parent' => $product_id, 'post_type' => "wpsc-product", 'post_status' => 'all', 'suppress_filters' => true));
        $selected_post = array_shift($selected_post);
        $child_product_id = wpsc_get_child_object_in_terms($product_id, $term_ids, 'wpsc-variation');
        $already_a_variation = true;
        if ($child_product_id == false) {
            $already_a_variation = false;
            if ($selected_post != null) {
                $child_product_id = $selected_post->ID;
            } else {
                $child_product_id = wp_insert_post($product_values);
            }
        } else {
            // sometimes there have been problems saving the variations, this gets the correct product ID
            if ($selected_post != null && $selected_post->ID != $child_product_id) {
                $child_product_id = $selected_post->ID;
            }
        }
        $product_children[] = $child_product_id;
        if ($child_product_id > 0) {
            wp_set_object_terms($child_product_id, $term_slugs, 'wpsc-variation');
        }
        //JS - 7.9 - Adding loop to include meta data in child product.
        if (!$already_a_variation) {
            $this_child_product_meta = apply_filters('insert_child_product_meta', $child_product_meta, $product_id, $combination_terms);
            foreach ($this_child_product_meta as $meta_key => $meta_value) {
                if ($meta_key == "_wpsc_product_metadata") {
                    update_post_meta($child_product_id, $meta_key, unserialize($meta_value[0]));
                } else {
                    update_post_meta($child_product_id, $meta_key, $meta_value[0]);
                }
            }
            if (is_array($term_ids) && ($price = wpsc_determine_variation_price($child_product_id, $term_ids))) {
                update_product_meta($child_product_id, 'price', $price);
            }
        }
    }
    //For reasons unknown, this code did not previously deal with variation deletions.
    //Basically, we'll just check if any existing term associations are missing from the posted variables, delete if they are.
    //Get posted terms (multi-dimensional array, first level = parent var, second level = child var)
    $posted_term = $variations;
    //Get currently associated terms
    $currently_associated_var = $product_terms;
    foreach ($currently_associated_var as $current) {
        $currently_associated_vars[] = $current->term_id;
    }
    foreach ($posted_term as $term => $val) {
        $posted_terms[] = $term;
        if (is_array($val)) {
            foreach ($val as $term2 => $val2) {
//.........这里部分代码省略.........
开发者ID:osuarcher,项目名称:WP-e-Commerce,代码行数:101,代码来源:product-functions.php


示例7: get_the_product_category

/**
 * Retrieve product categories. Copied from the corresponding wordpress function
 *
 * @since 3.8.0
 *
 * @param int $id Mandatory, the product ID
 * @return array
 */
function get_the_product_category($id)
{
    $id = (int) $id;
    $categories = wpsc_get_product_terms($id, 'wpsc_product_category');
    if (!empty($categories)) {
        usort($categories, '_usort_terms_by_name');
    } else {
        $categories = array();
    }
    foreach ((array) array_keys($categories) as $key) {
        _make_cat_compat($categories[$key]);
    }
    return $categories;
}
开发者ID:VanessaGarcia-Freelance,项目名称:ButtonHut,代码行数:22,代码来源:misc.functions.php


示例8: duplicate_taxonomies

 /**
  * Copy the taxonomies of a post to another post
  *
  * @since  4.0
  *
  * @uses  get_object_taxonomies()   Gets taxonomies for the given object.
  * @uses  wpsc_get_product_terms()  Gets terms for the product taxonomies.
  * @uses  wp_set_object_terms()     Sets the terms for a post object.
  */
 public function duplicate_taxonomies()
 {
     $new_post_id = $this->get_new_post_id();
     if ($new_post_id) {
         $id = $this->get_post_id();
         $post_type = get_post_type($id);
         $taxonomies = get_object_taxonomies($post_type);
         foreach ($taxonomies as $taxonomy) {
             $post_terms = wpsc_get_product_terms($id, $taxonomy);
             foreach ($post_terms as $post_term) {
                 wp_set_object_terms($new_post_id, $post_term->slug, $taxonomy, true);
             }
         }
     }
 }
开发者ID:RJHanson292,项目名称:WP-e-Commerce,代码行数:24,代码来源:duplicate-product-class.php


示例9: wpsc_product_link

/**
 * wpsc_product_link function.
 * Gets the product link, hooks into post_link
 * Uses the currently selected, only associated or first listed category for the term URL
 * If the category slug is the same as the product slug, it prefixes the product slug with "product/" to counteract conflicts
 *
 * @access public
 * @return void
 */
function wpsc_product_link($permalink, $post, $leavename)
{
    global $wp_query, $wpsc_page_titles, $wpsc_query, $wp_current_filter;
    $rewritecode = array('%wpsc_product_category%', $leavename ? '' : '%postname%');
    if (is_object($post)) {
        // In wordpress 2.9 we got a post object
        $post_id = $post->ID;
    } else {
        // In wordpress 3.0 we get a post ID
        $post_id = $post;
        $post = get_post($post_id);
    }
    // Only applies to WPSC products, don't stop on permalinks of other CPTs
    // Fixes http://code.google.com/p/wp-e-commerce/issues/detail?id=271
    if ('wpsc-product' !== $post->post_type) {
        return $permalink;
    }
    if ('inherit' === $post->post_status && 0 !== $post->post_parent) {
        $post_id = $post->post_parent;
        $post = get_post($post_id);
    }
    global $wp_rewrite;
    $our_permalink_structure = $wp_rewrite->root;
    // This may become customiseable later
    $our_permalink_structure .= str_replace(basename(home_url()), '', $wpsc_page_titles['products']) . "/%wpsc_product_category%/%postname%/";
    // Mostly the same conditions used for posts, but restricted to items with a post type of "wpsc-product "
    if ($wp_rewrite->using_permalinks() && !in_array($post->post_status, array('draft', 'pending'))) {
        $product_categories = wpsc_get_product_terms($post_id, 'wpsc_product_category');
        $product_category_slugs = array();
        foreach ($product_categories as $product_category) {
            $product_category_slugs[] = $product_category->slug;
        }
        // If the product is associated with multiple categories, determine which one to pick
        if (count($product_categories) == 0) {
            $category_slug = apply_filters('wpsc_uncategorized_product_category', 'uncategorized');
        } elseif (count($product_categories) > 1) {
            if (isset($wp_query->query_vars['products']) && $wp_query->query_vars['products'] != null && in_array($wp_query->query_vars['products'], $product_category_slugs)) {
                $product_category = $wp_query->query_vars['products'];
            } else {
                $link = $product_categories[0]->slug;
                if (!in_array('wp_head', $wp_current_filter) && isset($wpsc_query->query_vars['wpsc_product_category'])) {
                    $current_cat = $wpsc_query->query_vars['wpsc_product_category'];
                    if (in_array($current_cat, $product_category_slugs)) {
                        $link = $current_cat;
                    }
                }
                $product_category = $link;
            }
            $category_slug = $product_category;
        } else {
            // If the product is associated with only one category, we only have one choice
            if (!isset($product_categories[0])) {
                $product_categories[0] = '';
            }
            $product_category = $product_categories[0];
            if (!is_object($product_category)) {
                $product_category = new stdClass();
            }
            if (!isset($product_category->slug)) {
                $product_category->slug = null;
            }
            $category_slug = $product_category->slug;
        }
        $post_name = $post->post_name;
        if (get_option('product_category_hierarchical_url', 0)) {
            $selected_term = get_term_by('slug', $category_slug, 'wpsc_product_category');
            if (is_object($selected_term)) {
                $term_chain = array($selected_term->slug);
                while ($selected_term->parent) {
                    $selected_term = get_term($selected_term->parent, 'wpsc_product_category');
                    array_unshift($term_chain, $selected_term->slug);
                }
                $category_slug = implode('/', $term_chain);
            }
        }
        if (isset($category_slug) && empty($category_slug)) {
            $category_slug = 'product';
        }
        $category_slug = apply_filters('wpsc_product_permalink_cat_slug', $category_slug, $post_id);
        $rewritereplace = array($category_slug, $post_name);
        $permalink = str_replace($rewritecode, $rewritereplace, $our_permalink_structure);
        $permalink = user_trailingslashit($permalink, 'single');
        $permalink = home_url($permalink);
    }
    return apply_filters('wpsc_product_permalink', $permalink, $post->ID);
}
开发者ID:osuarcher,项目名称:WP-e-Commerce,代码行数:95,代码来源:product.php


示例10: fetch_variation_terms

 /**
  * Initialize variation terms for this product
  *
  * @since 3.8.14
  */
 private function fetch_variation_terms()
 {
     // don't do anything if this is already initialized
     if (!is_null($this->variation_sets) && !is_null($this->variation_terms)) {
         return;
     }
     $this->variation_terms = array();
     $this->variation_sets = array();
     // get all the attached variation terms
     $terms = wpsc_get_product_terms($this->post->ID, 'wpsc-variation');
     foreach ($terms as $term) {
         // Terms with no parents are variation sets (e.g. Color, Size)
         if (!$term->parent) {
             $this->variation_sets[$term->term_id] = $term->name;
         } else {
             // Terms with parents are called "variation terms" (e.g. Blue, Red or Large, Medium)
             if (!array_key_exists($term->parent, $this->variation_terms)) {
                 $this->variation_terms[$term->parent] = array();
             }
             $this->variation_terms[$term->parent][$term->term_id] = $term->name;
         }
     }
 }
开发者ID:dreamteam111,项目名称:dreamteam,代码行数:28,代码来源:product.class.php


示例11: __construct

 /**
  * wpsc__breadcrumbs function.
  *
  * @access public
  * @return void
  */
 public function __construct()
 {
     global $wp_query, $wpsc_query;
     $this->breadcrumbs = array();
     $query_data = array();
     if (isset($wp_query->query_vars['post_type']) && 'wpsc-product' == $wp_query->query_vars['post_type'] && 1 == $wp_query->query_vars['posts_per_page'] && isset($wp_query->post) && is_single()) {
         $query_data['product'] = $wp_query->post->post_title;
     }
     if (!empty($wpsc_query->query_vars['wpsc_product_category'])) {
         $query_data['category'] = $wpsc_query->query_vars['wpsc_product_category'];
     }
     if (!empty($query_data['product']) && !empty($wp_query->post)) {
         $this->breadcrumbs[] = array('name' => esc_html($wp_query->post->post_title), 'url' => '', 'slug' => $query_data['product']);
     }
     if (is_single()) {
         $categories = wpsc_get_product_terms($wp_query->post->ID, 'wpsc_product_category');
         //if product is associated w more than one category
         if (count($categories) > 1 && isset($wpsc_query->query_vars['wpsc_product_category'])) {
             $query_data['category'] = $wpsc_query->query_vars['wpsc_product_category'];
         } elseif (count($categories) > 0) {
             $query_data['category'] = $categories[0]->slug;
         }
     }
     if (isset($query_data['category'])) {
         $term_data = get_term_by('slug', $query_data['category'], 'wpsc_product_category');
     } else {
         $term_data = get_term_by('slug', 'uncategorized', 'wpsc_product_category');
     }
     if ($term_data != false) {
         $this->breadcrumbs[] = array('name' => esc_html($term_data->name), 'url' => get_term_link($term_data->slug, 'wpsc_product_category'), 'slug' => $term_data->slug);
         $i = 0;
         while ($term_data->parent > 0 && $i <= 20) {
             $term_data = get_term($term_data->parent, 'wpsc_product_category');
             $this->breadcrumbs[] = array('name' => esc_html($term_data->name), 'url' => get_term_link($term_data->slug, 'wpsc_product_category'));
             $i++;
         }
     }
     $this->breadcrumbs = apply_filters('wpsc_breadcrumbs', array_reverse($this->breadcrumbs));
     $this->breadcrumb_count = count($this->breadcrumbs);
 }
开发者ID:AngryBird3,项目名称:WP-e-Commerce,代码行数:46,代码来源:breadcrumbs.php


示例12: wpsc_ajax_ie_save

/**
 * wpsc_ajax_ie_save save changes made using inline edit
 *
 * @since  3.8
 * @access public
 *
 * @uses get_post_type_object()       Gets post object for given registered post type name
 * @uses current_user_can()           Checks the capabilities of the current user
 * @uses absint()                     Converts to a nonnegative integer
 * @uses get_post()                   Gets the post object given post id
 * @uses wp_get_object_terms()        Gets terms for given post object
 * @uses wp_update_post()             Updates the post in the database
 * @uses get_product_meta()           An alias for get_post_meta prefixes with the WPSC key
 * @uses wpsc_convert_weight()        Converts to weight format specified by user
 * @uses json_encode()                Encodes array for JS
 * @uses esc_js()                     Escape single quotes, htmlspecialchar " < > &, and fix line endings.
 *
 * @returns nothing
 */
function wpsc_ajax_ie_save()
{
    $product_post_type = get_post_type_object('wpsc-product');
    if (!current_user_can($product_post_type->cap->edit_posts)) {
        echo '({"error":"' . __('Error: you don\'t have required permissions to edit this product', 'wp-e-commerce') . '", "id": "' . esc_js($_POST['id']) . '"})';
        die;
    }
    $id = absint($_POST['id']);
    $post = get_post($_POST['id']);
    $parent = get_post($post->post_parent);
    $terms = wpsc_get_product_terms($id, 'wpsc-variation', 'name');
    $product = array('ID' => $_POST['id'], 'post_title' => $parent->post_title . ' (' . implode(', ', $terms) . ')');
    $id = wp_update_post($product);
    if ($id > 0) {
        //need parent meta to know which weight unit we are using
        $parent_meta = get_product_meta($post->post_parent, 'product_metadata', true);
        $product_meta = get_product_meta($product['ID'], 'product_metadata', true);
        if (is_numeric($_POST['weight']) || empty($_POST['weight'])) {
            $product_meta['weight'] = wpsc_convert_weight($_POST['weight'], $parent_meta['weight_unit'], 'pound', true);
            $product_meta['weight_unit'] = $parent_meta['weight_unit'];
        }
        update_product_meta($product['ID'], 'product_metadata', $product_meta);
        update_product_meta($product['ID'], 'price', (double) $_POST['price']);
        update_product_meta($product['ID'], 'special_price', (double) $_POST['special_price']);
        update_product_meta($product['ID'], 'sku', sanitize_text_field($_POST['sku']));
        if (!is_numeric($_POST['stock'])) {
            update_product_meta($product['ID'], 'stock', '');
        } else {
            update_product_meta($product['ID'], 'stock', absint($_POST['stock']));
        }
        $meta = get_product_meta($id, 'product_metadata', true);
        $price = get_product_meta($id, 'price', true);
        $special_price = get_product_meta($id, 'special_price', true);
        $sku = get_product_meta($id, 'sku', true);
        $sku = $sku ? $sku : __('N/A', 'wp-e-commerce');
        $stock = get_product_meta($id, 'stock', true);
        $stock = $stock === '' ? __('N/A', 'wp-e-commerce') : $stock;
        $results = array('id' => $id, 'title' => $post->post_title, 'weight' => wpsc_convert_weight($meta['weight'], 'pound', $parent_meta['weight_unit']), 'price' => wpsc_currency_display($price), 'special_price' => wpsc_currency_display($special_price), 'sku' => $sku, 'stock' => $stock);
        echo '(' . json_encode($results) . ')';
        die;
    } else {
        echo '({"error":"' . __('Error updating product', 'wp-e-commerce') . '", "id": "' . esc_js($_POST['id']) . '"})';
    }
    die;
}
开发者ID:ashik968,项目名称:digiplot,代码行数:64,代码来源:admin.php


示例13: compare_logic

 /**
  * Comparing logic with the product information
  *
  * Checks if the product matches the logic
  *
  * @todo  Is this ever even used?
  *
  * @return bool True if all conditions are matched, False otherwise.
  */
 function compare_logic($condition, $product)
 {
     global $wpdb;
     if ('item_name' == $condition['property']) {
         $product_data = $wpdb->get_results("SELECT * FROM " . $wpdb->posts . " WHERE id='{$product->product_id}'");
         $product_data = $product_data[0];
         switch ($condition['logic']) {
             case 'equal':
                 //Checks if the product name is exactly the same as the condition value
                 if ($product_data->post_title == $condition['value']) {
                     return true;
                 }
                 break;
             case 'greater':
                 //Checks if the product name is not the same as the condition value
                 if ($product_data->post_title > $condition['value']) {
                     return true;
                 }
                 break;
             case 'less':
                 //Checks if the product name is not the same as the condition value
                 if ($product_data->post_title < $condition['value']) {
                     return true;
                 }
                 break;
             case 'contains':
                 //Checks if the product name contains the condition value
                 preg_match("/(.*)" . preg_quote($condition['value'], '/') . "(.*)/", $product_data->post_title, $match);
                 if (!empty($match)) {
                     return true;
                 }
                 break;
             case 'category':
                 //Checks if the product category is the condition value
                 if ($product_data->post_parent) {
                     $categories = wpsc_get_product_terms($product_data->post_parent, 'wpsc_product_category');
                 } else {
                     $categories = wpsc_get_product_terms($product_data->ID, 'wpsc_product_category');
                 }
                 foreach ($categories as $cat) {
                     if (strtolower($cat->name) == strtolower($condition['value'])) {
                         return true;
                     }
                 }
                 break;
             case 'not_contain':
                 //Checks if the product name contains the condition value
                 preg_match("/(.*)" . preg_quote($condition['value'], '/') . "(.*)/", $product_data->post_title, $match);
                 if (empty($match)) {
                     return true;
                 }
                 break;
             case 'begins':
                 //Checks if the product name begins with condition value
                 preg_match("/^" . preg_quote($condition['value'], '/') . "/", $product_data->post_title, $match);
                 if (!empty($match)) {
                     return true;
                 }
                 break;
             case 'ends':
                 //Checks if the product name ends with condition value
                 preg_match("/" . preg_quote($condition['value'], '/') . "\$/", $product_data->post_title, $match);
                 if (!empty($match)) {
                     return true;
                 }
                 break;
             default:
                 return false;
         }
     } else {
         if ('item_quantity' == $condition['property']) {
             switch ($condition['logic']) {
                 case 'equal':
                     //Checks if the quantity of a product in the cart equals condition value
                     if ($product->quantity == (int) $condition['value']) {
                         return true;
                     }
                     break;
                 case 'greater':
                     //Checks if the quantity of a product is greater than the condition value
                     if ($product->quantity > $condition['value']) {
                         return true;
                     }
                     break;
                 case 'less':
                     //Checks if the quantity of a product is less than the condition value
                     if ($product->quantity < $condition['value']) {
                         return true;
                     }
                     break;
                 case 'contains':
//.........这里部分代码省略.........
开发者ID:AngryBird3,项目名称:WP-e-Commerce,代码行数:101,代码来源:coupons.class.php


示例14: completed_order

 /**
  * Adds product properties to analytics.track() when the order is completed successfully.
  *
  * @since  1.0.0
  * @access public
  *
  * @uses  func_get_args() Because our abstract class doesn't know how many parameters are passed to each hook
  *                        for each different platform, we use func_get_args().
  *
  * @return array Filtered array of name and properties for analytics.track().
  */
 public function completed_order()
 {
     $args = func_get_args();
     $track = $args[0];
     if (did_action('wpsc_transaction_results_shutdown') && isset($_GET['sessionid'])) {
         $log = new WPSC_Purchase_Log($_GET['sessionid'], 'sessionid');
         /* We like checking is_order_received(), as that's what the manual payment gateway uses. */
         if ($log->is_transaction_completed() || $log->is_order_received()) {
             $gateway_data = $log->get_gateway_data();
             $items = $log->get_cart_contents();
             $products = array();
             foreach ($items as $item) {
                 $product = array('id' => $item->prodid, 'sku' => wpsc_product_sku($item->prodid), 'name' => $item->name, 'price' => $item->price, 'quantity' => $item->quantity, 'category' => implode(', ', wp_list_pluck(wpsc_get_product_terms($item->prodid, 'wpsc_product_category'), 'name')));
                 $products[] = $product;
             }
             $track = array('event' => __('Completed Order', 'segment'), 'properties' => array('id' => $log->get('id'), 'total' => $log->get('totalprice'), 'revenue' => $gateway_data['subtotal'], 'shipping' => $gateway_data['shipping'], 'tax' => $gateway_data['tax'], 'products' => $products));
         }
     }
     return $track;
 }
开发者ID:qfrery,项目名称:analytics-wordpress,代码行数:31,代码来源:wp-e-commerce.php



注:本文中的wpsc_get_product_terms函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
PHP wpsc_get_region函数代码示例发布时间:2022-05-23
下一篇:
PHP wpsc_get_option函数代码示例发布时间: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