当前位置: 首页>>代码示例>>PHP>>正文


PHP wc_get_product_terms函数代码示例

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


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

示例1: as_ajax_add_compare_product

function as_ajax_add_compare_product()
{
    $product_id = $_REQUEST["product_id"];
    $response = array("status" => 0, "message" => "something error");
    if (!empty($product_id) && is_numeric($product_id)) {
        $product = wc_get_product($product_id);
        if (!empty($product)) {
            $compare_product = as_get_product_compare();
            if (isset($compare_product[$product_id])) {
                $response["message"] = __("Product is in compare", AS_DOMAIN) . ' | <a target="_blank" href="' . get_page_link(get_option("as-compare-page-id")) . '">' . __("Go to compare", AS_DOMAIN) . '</a>';
            } else {
                $product_attrs = $product->get_attributes();
                $new_product_attrs = array();
                foreach ($product_attrs as $attribute) {
                    if (empty($attribute['is_visible']) || $attribute['is_taxonomy'] && !taxonomy_exists($attribute['name'])) {
                        continue;
                    } else {
                        if ($attribute['is_taxonomy']) {
                            $values = wc_get_product_terms($product->id, $attribute['name'], array('fields' => 'names'));
                            $values = apply_filters('woocommerce_attribute', wpautop(wptexturize(implode(', ', $values))), $attribute, $values);
                        } else {
                            // Convert pipes to commas and display values
                            $values = array_map('trim', explode(WC_DELIMITER, $attribute['value']));
                            $values = apply_filters('woocommerce_attribute', wpautop(wptexturize(implode(', ', $values))), $attribute, $values);
                        }
                        $data_attr = array("name" => $attribute["name"], "title" => wc_attribute_label($attribute['name']), "values" => $values);
                        $new_product_attrs[$attribute["name"]] = $data_attr;
                    }
                }
                $data_product = array("id" => $product_id, "name" => $product->get_title(), "price" => $product->get_price(), "image" => $product->get_image(), "attributes" => $new_product_attrs);
                as_save_product_compare($data_product);
                $response = array("status" => 1, "message" => "Success", "notice" => __("Product is in compare", AS_DOMAIN) . ' | <a target="_blank" href="' . get_page_link(get_option("as-compare-page-id")) . '">' . __("Go to compare", AS_DOMAIN) . '</a>');
            }
        } else {
            $response["message"] = __("Product does not existed", AS_DOMAIN);
        }
    } else {
        $response["message"] = __("Product does not true", AS_DOMAIN);
    }
    wp_send_json($response);
}
开发者ID:bibiangel1989,项目名称:vespatour,代码行数:41,代码来源:compare.php

示例2: wc_get_product_terms

 public static function wc_get_product_terms($object_id, $taxonomy, $fields = 'all')
 {
     global $woocommerce;
     if (self::is_wc_version_gte_2_1()) {
         return wc_get_product_terms($object_id, $taxonomy, array('fields' => $fields));
     } else {
         return woocommerce_get_product_terms($object_id, $taxonomy, $fields);
     }
 }
开发者ID:jmagallanes,项目名称:cultura-woo-bulk-variations,代码行数:9,代码来源:class-wc-bulk-variations-compatibility.php

示例3: get_categories

 /**
  * Returns the product categories as HTML links with adjustable sorting.
  *
  * @since 1.0.0
  *
  * @param string $sep
  * @param string $before
  * @param string $after
  * @param string $orderby
  * @param string $order
  *
  * @return string
  */
 public function get_categories($sep = ', ', $before = '', $after = '', $orderby = 'name', $order = 'ASC')
 {
     $cats = wc_get_product_terms($this->id, 'product_cat', ['orderby' => $orderby, 'order' => $order, 'fields' => 'ids']);
     $links = [];
     foreach ($cats as $k => $v) {
         if (($cat = get_term((int) $v, 'product_cat')) && is_object($cat)) {
             $link = get_term_link($cat);
             $links[] = '<a href="' . esc_url($link) . '" rel="tag">' . esc_html($cat->name) . '</a>';
         }
     }
     $links = apply_filters("term_links-product_cat", $links);
     return $before . join($sep, $links) . $after;
 }
开发者ID:boguslawski-piotr,项目名称:pbo-tools,代码行数:26,代码来源:wc-product-ex.php

示例4: add_single_product

 /**
  * Add single product trailings
  *
  * @since  4.0.0
  */
 private function add_single_product()
 {
     $terms = false;
     if (function_exists('wc_get_product_terms')) {
         global $post;
         $terms = wc_get_product_terms($post->ID, 'product_cat', array('orderby' => 'parent', 'order' => 'DESC'));
     }
     if ($terms) {
         $main_term = apply_filters('woocommerce_breadcrumb_main_term', $terms[0], $terms);
         $this->term_ancestors($main_term->term_id, 'product_cat');
         $this->_add_item('link_format', $main_term->name, get_term_link($main_term));
     }
     $this->_add_item('target_format', get_the_title($post->ID));
     $this->page_title = false;
 }
开发者ID:xav335,项目名称:sfnettoyage,代码行数:20,代码来源:class-cherry-woo-breadcrumbs.php

示例5: wc_bundles_get_product_terms

function wc_bundles_get_product_terms($product_id, $attribute_name, $args)
{
    if (WC_PB_Core_Compatibility::is_wc_version_gte_2_3()) {
        return wc_get_product_terms($product_id, $attribute_name, $args);
    } else {
        $orderby = wc_attribute_orderby(sanitize_title($attribute_name));
        switch ($orderby) {
            case 'name':
                $args = array('orderby' => 'name', 'hide_empty' => false, 'menu_order' => false);
                break;
            case 'id':
                $args = array('orderby' => 'id', 'order' => 'ASC', 'menu_order' => false);
                break;
            case 'menu_order':
                $args = array('menu_order' => 'ASC');
                break;
        }
        $terms = get_terms(sanitize_title($attribute_name), $args);
        return $terms;
    }
}
开发者ID:puppy09,项目名称:madC,代码行数:21,代码来源:wc-pb-functions.php

示例6: wc_radio_variation_attribute_options

function wc_radio_variation_attribute_options($args = array())
{
    $args = wp_parse_args(apply_filters('woocommerce_radio_variation_attribute_options_args', $args), array('options' => false, 'attribute' => false, 'product' => false, 'selected' => false, 'name' => '', 'id' => '', 'class' => ''));
    $options = $args['options'];
    $product = $args['product'];
    $attribute = $args['attribute'];
    $name = $args['name'] ? $args['name'] : 'attribute_' . sanitize_title($attribute) . '_' . uniqid();
    $id = $args['id'] ? $args['id'] : sanitize_title($attribute) . uniqid();
    $class = $args['class'];
    if (empty($options) && !empty($product) && !empty($attribute)) {
        $attributes = $product->get_variation_attributes();
        $options = $attributes[$attribute];
    }
    echo '<ul id="radio_select_' . esc_attr($id) . '" class="' . esc_attr($class) . '" data-attribute_name="attribute_' . esc_attr(sanitize_title($attribute)) . '">';
    if (!empty($options)) {
        if ($product && taxonomy_exists($attribute)) {
            // Get terms if this is a taxonomy - ordered. We need the names too.
            $terms = wc_get_product_terms($product->id, $attribute, array('fields' => 'all'));
            foreach ($terms as $term) {
                if (in_array($term->slug, $options)) {
                    echo '<li>';
                    echo '<input class="radio-option" name="' . esc_attr($name) . '" id="radio_' . esc_attr($id) . '_' . esc_attr($term->slug) . '" type="radio" data-value="' . esc_attr($term->slug) . '" value="' . esc_attr($term->slug) . '" ' . checked(sanitize_title($args['selected']), $term->slug, false) . ' /><label for="radio_' . esc_attr($id) . '_' . esc_attr($term->slug) . '">' . esc_html(apply_filters('woocommerce_variation_option_name', $term->name)) . '</label>';
                    echo '</li>';
                }
            }
        } else {
            foreach ($options as $option) {
                // This handles < 2.4.0 bw compatibility where text attributes were not sanitized.
                $selected = sanitize_title($args['selected']) === $args['selected'] ? checked($args['selected'], sanitize_title($option), false) : checked($args['selected'], $option, false);
                echo '<li>';
                echo '<input class="radio-option" name="' . esc_attr($name) . '" id="radio_' . esc_attr($id) . '_' . esc_attr($option) . '" type="radio" data-value="' . esc_attr($option) . '" value="' . esc_attr($option) . '" ' . $selected . ' /><label for="radio_' . esc_attr($id) . '_' . esc_attr($option) . '">' . esc_html(apply_filters('woocommerce_variation_option_name', $option)) . '</label>';
                echo '</li>';
            }
        }
    }
    echo '</ul>';
}
开发者ID:AndyA,项目名称:River,代码行数:37,代码来源:woocommerce-swatches-template-functions.php

示例7: esc_attr

							} 	
							?>
						</select>

						<!-- Creamos una variable global que almacenara el id del select oculto  -->
						<script> var _sl_clousure_type_ = "<?php echo esc_attr( sanitize_title( $name ) ); ?>" </script>

						<ul id="js-chkbox-type-closeures" data-attribute_name="attribute_<?php echo sanitize_title( $name ); ?>" class="list-inline list-type-closueres hidden-xs">

							<?php  
								/* Aquí desplagamos las variaciones del producto */
								global $post;
								$tax_var = "pa_tipo-de-cierre"; //taxonomia tipo de cierre

								if ( taxonomy_exists( $tax_var ) ) { //si la taxonomia existe
									$terms = wc_get_product_terms( $post->ID, $tax_var , array( 'fields' => 'all' ) );
									
									foreach ( $terms as $term ) {

										$image_html = s8_get_taxonomy_image( $term , array(200,210)); 
										$atribute   = "attribute_" . sanitize_title( $name );

										echo '<li><a href="#" data-attr="'. $term->name .'"><figure>' . $image_html . '</figure><p>'. $term->name . '<span>' . $term->description  . '</span></p></a></li>';
									}
								}
							?>


						</ul> <!-- /js-chkbox-type-closeures -->
					</td>
				</tr>
开发者ID:JDarkGreen,项目名称:wpmaletek,代码行数:31,代码来源:simple.php

示例8: cupid_filter_breadcrumb_items

 function cupid_filter_breadcrumb_items()
 {
     $item = array();
     $shop_page_id = wc_get_page_id('shop');
     if (get_option('page_on_front') != $shop_page_id) {
         $shop_name = $shop_page_id ? get_the_title($shop_page_id) : '';
         if (!is_shop()) {
             $item[] = '<li typeof="v:Breadcrumb"><a rel="v:url" property="v:title" href="' . get_permalink($shop_page_id) . '">' . $shop_name . '</a></li>';
         } else {
             $item['last'] = $shop_name;
         }
     }
     if (is_tax('product_cat') || is_tax('product_tag')) {
         $current_term = get_term_by('slug', get_query_var('term'), get_query_var('taxonomy'));
     } elseif (is_product()) {
         global $post;
         $terms = wc_get_product_terms($post->ID, 'product_cat', array('orderby' => 'parent', 'order' => 'DESC'));
         $current_term = $terms[0];
     }
     if (!empty($current_term)) {
         if (is_taxonomy_hierarchical($current_term->taxonomy)) {
             $item = array_merge($item, cupid_breadcrumb_get_term_parents($current_term->parent, $current_term->taxonomy));
         }
         if (is_tax('product_cat') || is_tax('product_tag')) {
             $item['last'] = $current_term->name;
         } else {
             $item[] = '<li typeof="v:Breadcrumb"><a rel="v:url" property="v:title" href="' . get_term_link($current_term->term_id, $current_term->taxonomy) . '">' . $current_term->name . '</a></li>';
         }
     }
     if (is_product()) {
         $item['last'] = get_the_title();
     }
     return apply_filters('cupid_filter_breadcrumb_items', $item);
 }
开发者ID:adwleg,项目名称:site,代码行数:34,代码来源:breadcrumb.php

示例9: get_product_attribute

 /**
  * Return/show product attribute
  */
 public function get_product_attribute($attribute_name, $product)
 {
     // first, check the text attributes
     $attributes = $product->get_attributes();
     $attribute_key = @wc_attribute_taxonomy_name($attribute_name);
     if (array_key_exists(sanitize_title($attribute_name), $attributes)) {
         $attribute = $product->get_attribute($attribute_name);
         return $attribute;
     } elseif (array_key_exists(sanitize_title($attribute_key), $attributes)) {
         $attribute = $product->get_attribute($attribute_key);
         return $attribute;
     }
     // not a text attribute, try attribute taxonomy
     $attribute_key = @wc_attribute_taxonomy_name($attribute_name);
     $product_terms = @wc_get_product_terms($product->id, $attribute_key, array('fields' => 'names'));
     // check if not empty, then display
     if (!empty($product_terms)) {
         $attribute = array_shift($product_terms);
         return $attribute;
     } else {
         // no attribute under this name
         return false;
     }
 }
开发者ID:congkv,项目名称:wordpress,代码行数:27,代码来源:woocommerce-pdf-invoices-packingslips.php

示例10: woocommerce_get_product_terms

/**
 * @deprecated
 */
function woocommerce_get_product_terms($object_id, $taxonomy, $fields = 'all')
{
    return wc_get_product_terms($object_id, $taxonomy, array('fields' => $fields));
}
开发者ID:nayemDevs,项目名称:woocommerce,代码行数:7,代码来源:wc-deprecated-functions.php

示例11: link_all_variations

 /**
  * Link all variations via ajax function.
  */
 public static function link_all_variations()
 {
     if (!defined('WC_MAX_LINKED_VARIATIONS')) {
         define('WC_MAX_LINKED_VARIATIONS', 49);
     }
     check_ajax_referer('link-variations', 'security');
     if (!current_user_can('edit_products')) {
         die(-1);
     }
     if (function_exists('set_time_limit') && false === strpos(ini_get('disable_functions'), 'set_time_limit') && !ini_get('safe_mode')) {
         @set_time_limit(0);
     }
     $post_id = intval($_POST['post_id']);
     if (!$post_id) {
         die;
     }
     $variations = array();
     $_product = wc_get_product($post_id, array('product_type' => 'variable'));
     // Put variation attributes into an array
     foreach ($_product->get_attributes() as $attribute) {
         if (!$attribute['is_variation']) {
             continue;
         }
         $attribute_field_name = 'attribute_' . sanitize_title($attribute['name']);
         if ($attribute['is_taxonomy']) {
             $options = wc_get_product_terms($post_id, $attribute['name'], array('fields' => 'slugs'));
         } else {
             $options = explode(WC_DELIMITER, $attribute['value']);
         }
         $options = array_map('trim', $options);
         $variations[$attribute_field_name] = $options;
     }
     // Quit out if none were found
     if (sizeof($variations) == 0) {
         die;
     }
     // Get existing variations so we don't create duplicates
     $available_variations = array();
     foreach ($_product->get_children() as $child_id) {
         $child = $_product->get_child($child_id);
         if (!empty($child->variation_id)) {
             $available_variations[] = $child->get_variation_attributes();
         }
     }
     // Created posts will all have the following data
     $variation_post_data = array('post_title' => 'Product #' . $post_id . ' Variation', 'post_content' => '', 'post_status' => 'publish', 'post_author' => get_current_user_id(), 'post_parent' => $post_id, 'post_type' => 'product_variation');
     $variation_ids = array();
     $added = 0;
     $possible_variations = wc_array_cartesian($variations);
     foreach ($possible_variations as $variation) {
         // Check if variation already exists
         if (in_array($variation, $available_variations)) {
             continue;
         }
         $variation_id = wp_insert_post($variation_post_data);
         $variation_ids[] = $variation_id;
         foreach ($variation as $key => $value) {
             update_post_meta($variation_id, $key, $value);
         }
         // Save stock status
         update_post_meta($variation_id, '_stock_status', 'instock');
         $added++;
         do_action('product_variation_linked', $variation_id);
         if ($added > WC_MAX_LINKED_VARIATIONS) {
             break;
         }
     }
     delete_transient('wc_product_children_' . $post_id);
     echo $added;
     die;
 }
开发者ID:tronsha,项目名称:woocommerce,代码行数:74,代码来源:class-wc-ajax.php

示例12: pedal_dropdown_variation_attribute_options

 /**
  * Output a list of variation attributes for use in the cart forms.
  *
  * @param array $args
  * @since 2.4.0
  */
 function pedal_dropdown_variation_attribute_options($args = array())
 {
     $args = wp_parse_args($args, array('options' => false, 'attribute' => false, 'product' => false, 'selected' => false, 'name' => '', 'id' => '', 'class' => '', 'show_option_none' => __('Choose an option', 'woocommerce')));
     $options = $args['options'];
     $product = $args['product'];
     $attribute = $args['attribute'];
     $name = $args['name'] ? $args['name'] : 'attribute_' . sanitize_title($attribute);
     $id = $args['id'] ? $args['id'] : sanitize_title($attribute);
     $class = $args['class'];
     if (empty($options) && !empty($product) && !empty($attribute)) {
         $attributes = $product->get_variation_attributes();
         $options = $attributes[$attribute];
     }
     echo '<select id="' . esc_attr($id) . '" class="' . esc_attr($class) . '" name="' . esc_attr($name) . '" data-attribute_name="attribute_' . esc_attr(sanitize_title($attribute)) . '">';
     if ($args['show_option_none']) {
         echo '<option value="">' . esc_html($args['show_option_none']) . '</option>';
     }
     if (!empty($options)) {
         if ($product && taxonomy_exists($attribute)) {
             // Get terms if this is a taxonomy - ordered. We need the names too.
             $terms = wc_get_product_terms($product->id, $attribute, array('fields' => 'all'));
             foreach ($terms as $term) {
                 if (in_array($term->slug, $options)) {
                     echo '<option value="' . esc_attr($term->slug) . '" ' . selected(sanitize_title($args['selected']), $term->slug, false) . '>' . apply_filters('woocommerce_variation_option_name', $term->name) . '</option>';
                 }
             }
         } else {
             foreach ($options as $option) {
                 ///PEDAL MODIFICATION
                 if ($product->id == 218) {
                     $pedal_append = pedal_function_test_bookings_in_term(esc_attr($option));
                     $class = 'available';
                     if (!$pedal_append) {
                         $disabled = 'disabled';
                         $pedal_append = 'FULLY BOOKED';
                         $class = 'booked';
                     }
                 }
                 // This handles < 2.4.0 bw compatibility where text attributes were not sanitized.
                 $selected = sanitize_title($args['selected']) === $args['selected'] ? selected($args['selected'], sanitize_title($option), false) : selected($args['selected'], $option, false);
                 echo '<option class="' . $class . '" value="' . esc_attr($option) . '"  ' . $selected . '>' . esc_html(apply_filters('woocommerce_variation_option_name', $option)) . '  ' . $pedal_append . '</option>';
             }
         }
     }
     echo '</select>';
 }
开发者ID:baperrou,项目名称:pedal-bookings,代码行数:52,代码来源:pedal-bookings-mods.php

示例13: hpy_dropdown_variation_attribute_options

 function hpy_dropdown_variation_attribute_options($args = array())
 {
     $_pf = new WC_Product_Factory();
     $args = wp_parse_args(apply_filters('woocommerce_dropdown_variation_attribute_options_args', $args), array('options' => false, 'attribute' => false, 'product' => false, 'selected' => false, 'name' => '', 'id' => '', 'class' => ''));
     $sortby = get_option('hpy_variant_sort');
     $options = $args['options'];
     $product = $args['product'];
     $attribute = $args['attribute'];
     $name = $args['name'] ? $args['name'] : 'attribute_' . sanitize_title($attribute);
     $id = $args['id'] ? $args['id'] : sanitize_title($attribute);
     $class = $args['class'];
     if (empty($options) && !empty($product) && !empty($attribute)) {
         $attributes = $product->get_variation_attributes();
         $options = $attributes[$attribute];
     }
     echo '<select id="' . esc_attr($id) . '" class="' . esc_attr($class) . '" name="' . esc_attr($name) . '" data-attribute_name="attribute_' . esc_attr(sanitize_title($attribute)) . '">';
     if ($sortby == 'price-low' || $sortby == 'price-high') {
         $variantIDs = $product->children['visible'];
         $variant_list = array();
         foreach ($variantIDs as $variants) {
             $variant_product = $_pf->get_product($variants);
             $variant_list[] = array($variant_product->get_regular_price() => $variants);
         }
         $varcount = count($variant_list);
         $i = 0;
         $v = 0;
         $tmp = array();
         while ($i < $varcount) {
             $keys[] = key($variant_list[$i]);
             $i++;
         }
         if (count(array_unique($keys)) == 1) {
             if ($product && taxonomy_exists($attribute)) {
                 // Get terms if this is a taxonomy - ordered. We need the names too.
                 $terms = wc_get_product_terms($product->id, $attribute, array('fields' => 'all'));
                 foreach ($terms as $term) {
                     if (in_array($term->slug, $options)) {
                         $clearname = str_replace("-", " ", $term->name);
                         echo '<option value="' . esc_attr($term->slug) . '" ' . selected(sanitize_title($args['selected']), $term->slug, false) . '>' . apply_filters('woocommerce_variation_option_name', $clearname) . '</option>';
                     }
                 }
             } else {
                 foreach ($options as $option) {
                     // This handles < 2.4.0 bw compatibility where text attributes were not sanitized.
                     $selected = sanitize_title($args['selected']) === $args['selected'] ? selected($args['selected'], sanitize_title($option), false) : selected($args['selected'], $option, false);
                     $clearname = str_replace("-", " ", $option);
                     echo '<option value="' . esc_attr($option) . '" ' . $selected . '>' . esc_html(apply_filters('woocommerce_variation_option_name', $clearname)) . '</option>';
                 }
             }
         } else {
             foreach ($variant_list as $list) {
                 $tmp = array_merge($tmp, $list);
             }
             if ($sortby == 'price-low') {
                 ksort($tmp);
                 foreach ($tmp as $variant) {
                     $current_variant = get_post_meta($variant);
                     $option = $current_variant['attribute_' . strtolower($attribute)][0];
                     if ($v == 0) {
                         $selected = ' selected="selected"';
                         $v++;
                     } else {
                         $selected = '';
                     }
                     $clearname = str_replace("-", " ", $option);
                     echo '<option value="' . esc_attr($option) . '" ' . $selected . '>' . ucwords(esc_html(apply_filters('woocommerce_variation_option_name', $clearname))) . '</option>';
                 }
             } else {
                 if ($sortby == 'price-high') {
                     krsort($tmp);
                     foreach ($tmp as $variant) {
                         $current_variant = get_post_meta($variant);
                         $option = $current_variant['attribute_' . strtolower($attribute)][0];
                         if ($v == 0) {
                             $selected = ' selected="selected"';
                             $v++;
                         } else {
                             $selected = '';
                         }
                         $clearname = str_replace("-", " ", $option);
                         echo '<option value="' . esc_attr($option) . '" ' . $selected . '>' . ucwords(esc_html(apply_filters('woocommerce_variation_option_name', $clearname))) . '</option>';
                     }
                 } else {
                     if ($product && taxonomy_exists($attribute)) {
                         // Get terms if this is a taxonomy - ordered. We need the names too.
                         $terms = wc_get_product_terms($product->id, $attribute, array('fields' => 'all'));
                         foreach ($terms as $term) {
                             if (in_array($term->slug, $options)) {
                                 echo '<option value="' . esc_attr($term->slug) . '" ' . selected(sanitize_title($args['selected']), $term->slug, false) . '>' . apply_filters('woocommerce_variation_option_name', $term->name) . '</option>';
                             }
                         }
                     } else {
                         foreach ($options as $option) {
                             // This handles < 2.4.0 bw compatibility where text attributes were not sanitized.
                             $selected = sanitize_title($args['selected']) === $args['selected'] ? selected($args['selected'], sanitize_title($option), false) : selected($args['selected'], $option, false);
                             echo '<option value="' . esc_attr($option) . '" ' . $selected . '>' . esc_html(apply_filters('woocommerce_variation_option_name', $option)) . '</option>';
                         }
                     }
                 }
             }
//.........这里部分代码省略.........
开发者ID:HappyKite,项目名称:hpy_wc_fdv,代码行数:101,代码来源:variations.php

示例14: wc_attribute_label

						<strong><?php 
        echo wc_attribute_label($name);
        ?>
</strong><br />
						<?php 
        $attribute = $attribute_name;
        $name = 'attribute_' . sanitize_title($attribute);
        $id = sanitize_title($attribute);
        if (empty($options) && !empty($product) && !empty($attribute)) {
            $attributes = $product->get_variation_attributes();
            $options = $attributes[$attribute];
        }
        if (!empty($options)) {
            if ($product && taxonomy_exists($attribute)) {
                // Get terms if this is a taxonomy - ordered. We need the names too.
                $terms = wc_get_product_terms($product->id, $attribute, array('fields' => 'all'));
                foreach ($terms as $term) {
                    if (in_array($term->slug, $options)) {
                        echo '<div class="wvdrb-one-third"><input type="radio" value="' . esc_attr($term->slug) . '" ' . checked(sanitize_title($selected), $term->slug, false) . ' id="' . esc_attr($id) . '" name="' . esc_attr($name) . '" data-attribute_name="attribute_' . esc_attr(sanitize_title($attribute)) . '">  &nbsp; &nbsp; ' . apply_filters('woocommerce_variation_option_name', $term->name) . '</div><div class="wvdrb-two-thirds"><pre>' . $term->description . '</pre></div><br />';
                    }
                }
            } else {
                foreach ($options as $key => $option) {
                    // This handles < 2.4.0 bw compatibility where text attributes were not sanitized.
                    // Use attribute key to get the variation id from the $available_variations array
                    $var_id = $available_variations[$key]['variation_id'];
                    // Then use the variation_id to get the value from _isa_woo_variation_desc
                    $var_description = get_post_meta($var_id, '_isa_woo_variation_desc', true);
                    $selected = sanitize_title($selected) === $selected ? checked($selected, sanitize_title($option), false) : checked($selected, $option, false);
                    echo '<div class="wvdrb-one-third"><input type="radio" value="' . esc_attr($option) . '" ' . $selected . ' id="' . esc_attr($id) . '" name="' . esc_attr($name) . '" data-attribute_name="attribute_' . esc_attr(sanitize_title($attribute)) . '">  &nbsp; &nbsp; ' . esc_html(apply_filters('woocommerce_variation_option_name', $option)) . '</div><div class="wvdrb-two-thirds">' . $var_description . '</div><br />';
                }
开发者ID:BurlesonBrad,项目名称:woocommerce-variation-description-radio-buttons,代码行数:31,代码来源:variable.php

示例15: get_product_from_post


//.........这里部分代码省略.........
     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";
开发者ID:booklein,项目名称:wpbookle,代码行数:67,代码来源:wcis_plugin.php


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