Woocommerce定制单个产品视图


Woocommerce customize single product view

我正在做woocommerce定制。但我还不知道如何获得产品的属性。我还想获得到属性存档页面的链接。

我把woocommerce文件夹放在我的主题文件夹中。这样我就可以自定义行为。在这个woocommerce文件夹中有一个文件theme-name/woocommerce/single-product/tabs/tabs.php

这个文件是用来打印产品说明的。之后,我放入代码片段来打印类别名称及其描述。我还希望它打印产品的属性。(最好有链接到它的存档页面)。

是否有一种方法可以使用片段的一部分来回应产品的属性?

global $post;
    $terms = get_the_terms( $post->ID, 'product_cat' );
    $attribute_names = array( 'Producten');
        foreach ( $attribute_names as $attribute_name ) {
                    $taxonomy = get_taxonomy( $attribute_name );
                    if ( $taxonomy && ! is_wp_error( $taxonomy ) ) {
                            $terms = wp_get_post_terms( $post->ID, $attribute_name );
                            $terms_array = array();
                    if ( ! empty( $terms ) ) {
                            foreach ( $terms as $term ) {
                                   $archive_link = get_term_link( $term->slug, $attribute_name );
                                   $full_line = '<a href="' . $archive_link . '">'. $term->name . '</a>';
                                   array_push( $terms_array, $full_line );
                            }
                            echo $taxonomy->labels->name . ' ' . implode( $terms_array, ', ' );
                    }
            }
        }
    foreach ($terms as $term) {                             
        $name = $term->name;
        $desc = $term->description;
        break;
    }
echo $name;
echo '<br>';
echo $desc;

你需要编码这样的东西,不完全像这样,你需要在这里做一些修改,我只从我的工作中发布了一些代码部分,在那里我检索重量和价格。在争论中,你可以添加类别,如果你需要。并让我知道使用此代码后,如果你得到任何错误或问题,因为我还没有测试过它。

  <?php
         $arg = array('posts_per_page' => -1, 'numberposts' => -1, 'post_type' => 'product');
        $products = get_posts($arg);
        <?php $product_obj = new WC_Product_Factory();  ?>  <?php if ($products): ?>
        <?php foreach($products as $product): ?><?php $product = $product_obj->get_product($product); ?>
       <?php if ($product->product_type == 'variable'): ?>
        <?php $children = $product->get_children( $args = '', $output = OBJECT ); ?>
        <?php
        foreach ($children as $key=>$value) {
            $product_variatons = new WC_Product_Variation($value);
            if ( $product_variatons->exists() && $product_variatons->variation_is_visible() ) {
            $variations[$value] = $product_variatons->get_variation_attributes();
                }