相关疑难解决方法(0)

Woocommerce - 在前端显示带有短代码的单个产品属性

在过去的几天里,我在这里阅读了许多 Q/A,但不幸的是,它们都没有解决我的问题。

我正在尝试获取产品属性并使用短代码在前端显示它们。我已经设法显示所有可用的属性并将它们显示在列表中,但我只需要在不同的位置选择其中的一两个(这就是使用简码的原因)。例如像 [shortcode_attribute name="brand"]。

任何帮助表示高度赞赏!

到目前为止我的代码:

function tutsplus_list_attributes( $product ) {

global $product;
global $post;

$attributes = $product->get_attributes();

if ( ! $attributes ) {

return;

}

foreach ( $attributes as $attribute ) {

// Get the taxonomy.
$terms = wp_get_post_terms( $product->id, $attribute[ 'name' ], 'all' );
$taxonomy = $terms[ 0 ]->taxonomy;

// Get the taxonomy object.
$taxonomy_object = get_taxonomy( $taxonomy );

// Get the attribute label.
$attribute_label = $taxonomy_object->labels->name;

// Display the label followed by a clickable list of …
Run Code Online (Sandbox Code Playgroud)

attributes woocommerce

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

标签 统计

attributes ×1

woocommerce ×1