标签: custom-taxonomy

WooCommerce - 将列添加到 Product Cat 管理表

我想在产品类别的后端表中添加一个新列。此列将包含一个链接“查看类别”,并将所有链接链接到 www.domain.com/category/category-name 页面。

我查看了 WordPress 文档,这是我想出的代码......但它不起作用!

function product_cat_cpt_columns($columns) {
    $new_columns = array(
        'Link' => "Link to page"
    );
    return array_merge($columns, $new_columns);
}
add_filter('manage_product_cat_posts_custom_columns' , 'product_cat_cpt_columns');
Run Code Online (Sandbox Code Playgroud)

知道我该怎么做吗?我真的很感谢你的帮助!

php wordpress taxonomy custom-taxonomy woocommerce

3
推荐指数
2
解决办法
2669
查看次数

限制显示的分类术语的数量

我有2个分类集product_cattvshows_cat.每套有12个术语.

一个产品最多可以有12个术语(但不能同时使用2个).

我使用此代码在产品页面中显示术语列表:

$cats = get_the_term_list($post->ID, 'product_cat', '', '  ', ''); 
$tvcats = get_the_term_list($post->ID, 'tvshows_cat', '', '  ', ''); 

if (!empty($cats)){
    echo strip_tags($cats, '   ');
}elseif(!empty($tvcats)){
    echo strip_tags($tvcats, '    ');
}
Run Code Online (Sandbox Code Playgroud)

结果是:

动作,戏剧,冒险,传记,动画

问题是,在某些情况下,没有足够的空间来显示所有术语.

我需要将条款数量限制为2个条款.

题:

如何限制应用于两个的术语数量?

谢谢

php wordpress categories custom-taxonomy woocommerce

3
推荐指数
1
解决办法
675
查看次数

WordPress:如何在自定义帖子类型中添加多个分类法

我创建了一个名为的自定义帖子类型user-story。该$args如下所示:

$args = array(
   'labels' => $labels,
   'hierarchical' => true,
   'description' => 'description',
   'taxonomies' => array('category', 'story-type', 'genre'),
   'show_ui' => true,
   'show_in_menu' => true,
   'menu_position' => 5,
   'menu_icon' => 'http://webmaster.webmastersuccess.netdna-cdn.com/wp-content/uploads/2015/03/pencil.png',
   'public' => true,
   'has_archive' => true,
   'query_var' => true,
   'capability_type' => 'post',
   'supports' => $supports,
   'rewrite' => $rewrite,
   'register_meta_box_cb' => 'add_story_metaboxes' );

register_post_type('user_story', $args);
Run Code Online (Sandbox Code Playgroud)

问题就在这里'taxonomies' => array('category', 'story-type', 'genre'),。我看不到我的分类story-type,并genre添加新的故事在管理页面。仅category显示。

这两个story-typegenre是自定义分类。我停用了CPT插件(user_story),然后重新激活了它。但是仍然没有超出自定义分类标准。 …

wordpress custom-post-type custom-taxonomy

3
推荐指数
1
解决办法
2839
查看次数

在Woocommerce中将自定义单一产品模板用于特定产品类别

我正在尝试对woocommerce商店中的仅一种产品使用自定义页面。我一直在尝试应用附加功能,但没有成功(该代码来自此答案)。

我在/ woocommerce文件夹中创建了single-product.php文件的副本,并添加了一些代码,但是单一产品视图仅显示“标准”单一产品php,而不显示我的single-product-mock.php。文件。

并且该产品确实具有“定制”产品类别。

add_filter( 'template_include', 'so_43621049_template_include', 10 );

function so_43621049_template_include( $template ) {
  if ( is_singular('product') && (has_term( 'custom', 'product_cat')) ) {
    $template = get_stylesheet_directory() . '/woocommerce/single-product-mock.php';
  } 
  retur
Run Code Online (Sandbox Code Playgroud)

php wordpress templates custom-taxonomy woocommerce

3
推荐指数
1
解决办法
4038
查看次数

在 Woocommerce 的单个产品页面上显示特定的自定义产品属性

我发现以下代码可以在产品详细信息页面上显示所有自定义属性(具有我需要的特定栏样式设计)。代码的工作方式就像一个魅力,我有适当的 CSS 来显示我的自定义属性的水平条。

我的问题是我只想显示特定的命名属性,并且不知道如何更改循环来做到这一点......

function isa_woocommerce_all_pa(){

global $product;
$attributes = $product->get_attributes();

if ( ! $attributes ) {
    return;
}

$out = '<ul class="taste-attributes">';

foreach ( $attributes as $attribute ) {


    // skip variations
    if ( $attribute->get_variation() ) {
    continue;
    }
    $name = $attribute->get_name();
    if ( $attribute->is_taxonomy() ) {

        $terms = wp_get_post_terms( $product->get_id(), $name, 'all' );
        // get the taxonomy
        $tax = $terms[0]->taxonomy;
        // get the tax object
        $tax_object = get_taxonomy($tax);
        // get tax label
        if ( isset ( …
Run Code Online (Sandbox Code Playgroud)

php wordpress custom-taxonomy woocommerce hook-woocommerce

3
推荐指数
1
解决办法
1万
查看次数

在 Woocommerce 购物车/结帐中将变体属性值显示为单独的行

我的产品上有多种可变产品。https://alcocovers.com/shop/我面临的问题是:添加到购物车后,垃圾箱防水布在购物车页面上列出了项目数据,但产品Lugger Cover没有。这是一个屏幕截图: 在此输入图像描述 我认为我在网站上使用的购物车项目数据模板存在一些问题,但我检查后发现没有任何问题(作为参考,这里是模板代码https://pastebin.com/fswKRZ8a)。我禁用了所有自定义模板,结果是相同的。我还仔细检查了这两种产品的设置方式是否完全相同,所以我不知道这背后的原因是什么。任何人都知道这会是什么原因造成的?

更新 #1:一位朋友建议,也许是因为 Lugger Cover 页面只有一个属性,这就是为什么它没有列出购物车上的商品数据。但我创建了一个测试页面,该页面也没有在购物车上列出商品数据...

更新 #2:我向测试页面添加了第三个属性,现在商品数据显示在购物车页面上。不知道为什么对于在产品页面上使用一个/两个属性的产品,项目数据不会显示在购物车上。我重新检查了模板文件,没有问题。

php wordpress cart custom-taxonomy woocommerce

3
推荐指数
1
解决办法
4083
查看次数

获取与 Woocommerce 中的产品类别相关的所有属性及其术语

众所周知,要获得添加到产品中的特定属性的术语,我们可以使用:

$attr_terms = $product->get_attribute( 'attr_slug' );
Run Code Online (Sandbox Code Playgroud)

或获取特定属性的所有术语,而不管我们可以使用什么产品

$attr_terms = get_terms( 'pa_attr_slug' );
Run Code Online (Sandbox Code Playgroud)

但是如何将所有属性及其术语添加到特定产品类别的产品中?

就像是:

$cat_attrs = ... ($cat->id);

foreach($cat_attrs as $cat_attr) {

    echo $cat_attr->name; // name of attribute

    foreach($cat_attr->terms as $term) {
        echo $term->name; // name of attribute term
    }
}
Run Code Online (Sandbox Code Playgroud)

php wordpress product custom-taxonomy woocommerce

3
推荐指数
1
解决办法
4372
查看次数

从 Woocommerce 中的产品 ID 列出产品类别层次结构

我有一个可以属于多个类别的产品,例如看一下以下字符串:

  • 类别1>产品1
  • 类别1>产品2
  • 类别 2>子类别 1>产品 1
  • 类别 3>子类别 1>子类别 2>产品 1

在 woocommerce 中,如果我有一个 ProductID,我可以执行以下操作:

    function alg_product_categories_names2( $atts ) {
    $product_cats = get_the_terms( $this->get_product_or_variation_parent_id( $this->the_product ), 'product_cat' );
    $cats = array();

    $termstest= '';
    if ( ! empty( $product_cats ) && is_array( $product_cats ) ) {
        foreach ( $product_cats as $product_cat ) {             
            if ( $term->parent == 0 ) { //if it's a parent category
                    $termstest .= ' PARENTCAT= '. $product_cat->name;
          }                             
        }
    }

    return htmlentities('<categories_names>'. $termstest .'</categories_names>');
}
Run Code Online (Sandbox Code Playgroud)

但这只是返回产品 …

php wordpress product custom-taxonomy woocommerce

3
推荐指数
1
解决办法
4756
查看次数

在 WooCommerce 电子邮件通知中显示特定产品属性

我无法将产品属性添加到 WooCommerce 新订单电子邮件中。我已将下面的代码片段添加到 email-order-items.php (在 // SKU.. 部分之后),但没有任何反应。甚至标题“位置:”也不可见。对此有什么想法吗?

// Attribute
if ( $item_meta->meta ) {echo '<br/><small>Location: ' . nl2br( $product->get_attribute( 'location' ) ) . '</small>';}
Run Code Online (Sandbox Code Playgroud)

php wordpress email-notifications custom-taxonomy woocommerce

3
推荐指数
1
解决办法
1744
查看次数

设置特定 WooCommerce 产品类别的购物车商品的最低数量

在 WooCommerce 中,我尝试为特定产品类别的购物车商品设置最低数量。

根据“ WooCommerce 中特定产品类别的最小购物车商品数量”,这是我的代码尝试:

add_action( 'woocommerce_check_cart_items', 'wc_min_item_required_qty' );
function wc_min_item_required_qty() {
    $category      = 'games'; // The targeted product category
    $min_item_qty  = 4; // Minimum Qty required (for each item)
    $display_error = false; // Initializing

    // Loop through cart items
    foreach(WC()->cart->get_cart() as $cart_item ) {
        $item_quantity = $cart_item['quantity']; // Cart item quantity
        $product_id    = $cart_item['product_id']; // The product ID

        // For cart items remaining to "Noten" producct category
        if( has_term( $category, 'product_cat', $product_id ) && $item_quantity < $min_item_qty …
Run Code Online (Sandbox Code Playgroud)

php wordpress cart custom-taxonomy woocommerce

3
推荐指数
1
解决办法
991
查看次数