Posts

Showing posts with the label custom-taxonomy

Product attribute empty value from order item in Woocommerce 3

Image
Product attribute empty value from order item in Woocommerce 3 I know that there are a lot of questions already for that matter but im not able to figure out how to get a custom product attribute from an woocommerce order. here is what i have try: $order = wc_get_order( $order_id ); $order_data = $order->get_data(); foreach ($order->get_items() as $item_key => $item_values) { $product = $item_values->get_product(); // Get the product $product_id = $item_values->get_product_id(); // the Product id $tokens = get_post_meta($product_id, 'Tokens', true); } I have also try: $tokens = $product->get_attribute( 'Tokens' ); and $tokens = array_shift( wc_get_product_terms( $product_id, 'Tokens', array( 'fields' => 'names' ) ) ); My custom product attribute has the name " Tokens " and the value 5000 but im getting an empty return, what am i doing wrong? That can h...

Loop to return all Woocommerce product tags in alphabetical order

Loop to return all Woocommerce product tags in alphabetical order i am trying to make a loop in WordPress for woocommerce theme to get out all product tags in alphabetical order in a simple way "heading with A below it all tags starts with A letter etc." i am using the code but its return null <?php $tags = get_tags(); $html = '<div class="post_tags">'; foreach ( $tags as $tag ) { $tag_link = get_tag_link( $tag->term_id ); $html .= "<a href='{$tag_link}' title='{$tag->name} Tag' class='{$tag- >slug}'>"; $html .= "{$tag->name}</a>"; } $html .= '</div>'; echo $html; ?> 2 Answers 2 You can also use a WP_Term_Query with the Woocommerce product tag custom taxonomy, to get all related terms alphabetically by letter: WP_Term_Query $taxonomy = 'product_tag...