plugins - I receive taxonomy id

Hello i want to get the value from field but i receive the id code is here:function add_product_column( $columns ) {ad

Hello i want to get the value from field but i receive the id code is here:

function add_product_column( $columns ) {
    //add column
    $columns['new_column'] = __( 'New column', 'woocommerce' );

    return $columns;
}
add_filter( 'manage_edit-product_columns', 'add_product_column', 10, 1 );


function add_product_column_content( $column, $postid ) {
    if ( $column == 'new_column' ) {
        // Get product object
        $product = wc_get_product( $postid );

        // Get Product Variations
        $product_attributes = $product->get_attributes();

        foreach ( $product_attributes as $product_attribute ) {         
            $attribute_options = $product_attribute->wp_get_post_terms($post->ID, 'portfolio_tags');

            foreach ( $attribute_options as $attribute_option ) {
                echo $attribute_option . '<br>';
            }
        }

    }
}
add_action( 'manage_product_posts_custom_column', 'add_product_column_content', 10, 2 );

Hello i want to get the value from field but i receive the id code is here:

function add_product_column( $columns ) {
    //add column
    $columns['new_column'] = __( 'New column', 'woocommerce' );

    return $columns;
}
add_filter( 'manage_edit-product_columns', 'add_product_column', 10, 1 );


function add_product_column_content( $column, $postid ) {
    if ( $column == 'new_column' ) {
        // Get product object
        $product = wc_get_product( $postid );

        // Get Product Variations
        $product_attributes = $product->get_attributes();

        foreach ( $product_attributes as $product_attribute ) {         
            $attribute_options = $product_attribute->wp_get_post_terms($post->ID, 'portfolio_tags');

            foreach ( $attribute_options as $attribute_option ) {
                echo $attribute_option . '<br>';
            }
        }

    }
}
add_action( 'manage_product_posts_custom_column', 'add_product_column_content', 10, 2 );

Share Improve this question edited Jan 30, 2020 at 9:56 Jacob Peattie 44.2k10 gold badges50 silver badges64 bronze badges asked Jan 30, 2020 at 9:26 LouisLouis 1
Add a comment  | 

1 Answer 1

Reset to default 1

there is a mistake in fetching the product attribute name. first of all, we have to get all options ids & attribute names than we have to fetch attribute name by its id & attribute slug.

please check below updated code snippet and let me know if this is worked for you or not.if not then please tell me I will definitely help you. Thanks.

function add_product_column( $columns ) {
    //add column
    $columns['new_column'] = __( 'New column', 'woocommerce' );
    return $columns;
}
add_filter( 'manage_edit-product_columns', 'add_product_column', 10, 1 );
function add_product_column_content( $column, $postid ) {
    if ( $column == 'new_column' ) {
        $product = wc_get_product( $postid );
        $product_attributes = $product->get_attributes();
        $attr_array = array();
        foreach ( $product_attributes as $product_attribute ) {
            $attribute_name = $product_attribute->get_name();
            $attribute_options = $product_attribute->get_options();
            foreach ($attribute_options as $key => $value) {
                $term_data = get_term_by( 'id',$value,$attribute_name );
                $term_name = $term_data->name;
                array_push($attr_array, $term_name);
            }
        }
        echo implode(', ', $attr_array);
    }
}
add_action( 'manage_product_posts_custom_column', 'add_product_column_content', 10, 2 );

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744789109a4593805.html

相关推荐

  • plugins - I receive taxonomy id

    Hello i want to get the value from field but i receive the id code is here:function add_product_column( $columns ) {ad

    10小时前
    30

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信