【发布时间】:2015-10-08 09:18:57
【问题描述】:
我正在进行 woocommerce 自定义。但是我现在还不够好如何获取产品的属性。我还想获取属性存档页面的链接。
我将 woocommerce 文件夹放在我的主题文件夹中。这样我可以做出自定义行为。在这个 woocommerce 文件夹中有一个文件 theme-name/woocommerce/single-product/tabs/tabs.php
此文件用于打印产品描述。之后,我输入代码 sn-p 以打印类别名称及其描述。我还希望它打印产品的属性。 (最好带有指向其存档页面的链接)。
有没有办法使用部分sn-p来呼应产品的属性?
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 wordpress woocommerce