本文整理汇总了PHP中wc_get_product_terms函数的典型用法代码示例。如果您正苦于以下问题:PHP wc_get_product_terms函数的具体用法?PHP wc_get_product_terms怎么用?PHP wc_get_product_terms使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了wc_get_product_terms函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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)) . '"> ' . 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)) . '"> ' . 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
示例16: get_attribute_options
/**
* Get attribute options.
*
* @param int $product_id
* @param array $attribute
* @return array
*/
protected function get_attribute_options($product_id, $attribute)
{
if (isset($attribute['is_taxonomy']) && $attribute['is_taxonomy']) {
return wc_get_product_terms($product_id, $attribute['name'], array('fields' => 'names'));
} elseif (isset($attribute['value'])) {
return array_map('trim', explode('|', $attribute['value']));
}
return array();
}
开发者ID:johnulist,项目名称:woocommerce,代码行数:16,代码来源:class-wc-api-products.php
示例17: add_crumbs_single
/**
* Single post trail
*
* @param int $post_id
* @param string $permalink
*/
private function add_crumbs_single($post_id = 0, $permalink = '')
{
if (!$post_id) {
global $post;
} else {
$post = get_post($post_id);
}
if ('product' === get_post_type($post)) {
$this->prepend_shop_page();
if ($terms = wc_get_product_terms($post->ID, 'product_cat', array('orderby' => 'parent', 'order' => 'DESC'))) {
$main_term = apply_filters('woocommerce_breadcrumb_main_term', $terms[0], $terms);
$this->term_ancestors($main_term->term_id, 'product_cat');
$this->add_crumb($main_term->name, get_term_link($main_term));
}
} elseif ('post' != get_post_type($post)) {
$post_type = get_post_type_object(get_post_type($post));
$this->add_crumb($post_type->labels->singular_name, get_post_type_archive_link(get_post_type($post)));
} else {
$cat = current(get_the_category($post));
if ($cat) {
$this->term_ancestors($cat->term_id, 'post_category');
$this->add_crumb($cat->name, get_term_link($cat));
}
}
$this->add_crumb(get_the_title($post), $permalink);
}
开发者ID:slavic18,项目名称:cats,代码行数:32,代码来源:class-wc-breadcrumb.php
示例18: widget
/**
* widget function.
*
* @see WP_Widget
*
* @param array $args
* @param array $instance
*/
public function widget($args, $instance)
{
global $wp_query, $post;
$c = isset($instance['count']) ? $instance['count'] : $this->settings['count']['std'];
$h = isset($instance['hierarchical']) ? $instance['hierarchical'] : $this->settings['hierarchical']['std'];
$s = isset($instance['show_children_only']) ? $instance['show_children_only'] : $this->settings['show_children_only']['std'];
$d = isset($instance['dropdown']) ? $instance['dropdown'] : $this->settings['dropdown']['std'];
$o = isset($instance['orderby']) ? $instance['orderby'] : $this->settings['orderby']['std'];
$dropdown_args = array('hide_empty' => false);
$list_args = array('show_count' => $c, 'hierarchical' => $h, 'taxonomy' => 'product_cat', 'hide_empty' => false);
// Menu Order
$list_args['menu_order'] = false;
if ($o == 'order') {
$list_args['menu_order'] = 'asc';
} else {
$list_args['orderby'] = 'title';
}
// Setup Current Category
$this->current_cat = false;
$this->cat_ancestors = array();
if (is_tax('product_cat')) {
$this->current_cat = $wp_query->queried_object;
$this->cat_ancestors = get_ancestors($this->current_cat->term_id, 'product_cat');
} elseif (is_singular('product')) {
$product_category = wc_get_product_terms($post->ID, 'product_cat', array('orderby' => 'parent'));
if ($product_category) {
$this->current_cat = end($product_category);
$this->cat_ancestors = get_ancestors($this->current_cat->term_id, 'product_cat');
}
}
// Show Siblings and Children Only
if ($s && $this->current_cat) {
// Top level is needed
$top_level = get_terms('product_cat', array('fields' => 'ids', 'parent' => 0, 'hierarchical' => true, 'hide_empty' => false));
// Direct children are wanted
$direct_children = get_terms('product_cat', array('fields' => 'ids', 'parent' => $this->current_cat->term_id, 'hierarchical' => true, 'hide_empty' => false));
// Gather siblings of ancestors
$siblings = array();
if ($this->cat_ancestors) {
foreach ($this->cat_ancestors as $ancestor) {
$ancestor_siblings = get_terms('product_cat', array('fields' => 'ids', 'parent' => $ancestor, 'hierarchical' => false, 'hide_empty' => false));
$siblings = array_merge($siblings, $ancestor_siblings);
}
}
if ($h) {
$include = array_merge($top_level, $this->cat_ancestors, $siblings, $direct_children, array($this->current_cat->term_id));
} else {
$include = array_merge($direct_children);
}
$dropdown_args['include'] = implode(',', $include);
$list_args['include'] = implode(',', $include);
if (empty($include)) {
return;
}
} elseif ($s) {
$dropdown_args['depth'] = 1;
$dropdown_args['child_of'] = 0;
$dropdown_args['hierarchical'] = 1;
$list_args['depth'] = 1;
$list_args['child_of'] = 0;
$list_args['hierarchical'] = 1;
}
$this->widget_start($args, $instance);
// Dropdown
if ($d) {
$dropdown_defaults = array('show_counts' => $c, 'hierarchical' => $h, 'show_uncategorized' => 0, 'orderby' => $o, 'selected' => $this->current_cat ? $this->current_cat->slug : '');
$dropdown_args = wp_parse_args($dropdown_args, $dropdown_defaults);
// Stuck with this until a fix for http://core.trac.wordpress.org/ticket/13258
wc_product_dropdown_categories(apply_filters('woocommerce
|
请发表评论