gpt4 book ai didi

wordpress - 在 WordPress/WooCommerce 中获取产品属性术语永久链接

转载 作者:行者123 更新时间:2023-12-04 00:08:01 24 4
gpt4 key购买 nike

我正在使用 WooCommerce 和 WordPress 来建立古董照片商店。

我正在使用 WooCommerce 产品属性功能来存储有关元素摄影师的信息。

看这里的例子,摄影师属性在左边的框中被拉出http://bit.ly/1Dp999O

拉出属性的代码如下:

if($attribute['is_taxonomy']) {
$values=wc_get_product_terms($product->id, $attribute['name'], array('fields' => 'names'));
echo apply_filters('woocommerce_attribute', wpautop(wptexturize(implode(', ', $values))), $attribute, $values);
}

$values 看起来像这样:

Array ( [0] => Photographer 1 )

问题是,我如何获得由 WordPress 和 WooCommerce 自动生成的摄影师的永久链接: http://bit.ly/1JtwBna

我在 WooCommerce 中找不到任何文档,这似乎是分类法中的分类法,比标准的 WordPress 更进一步,但我假设这是一个相当标准的要求。任何指针表示赞赏。

最佳答案

一旦你有了属性词(在本例中是摄影师的名字),你就可以使用 get_term_link()获取网址。因为 $product id 没有传递到 woocommerce_attribute 文件夹,所以我无法过滤它,而是创建了 product-attributes.php 的覆盖 模板。并将相关部分修改为:

if ( $attribute['is_taxonomy'] ) {

$terms = wc_get_product_terms( $product->id, $attribute['name'], array( 'fields' => 'all' ) );

$html = '';
$counter = 1;
$total = count( $terms );

foreach( $terms as $term ){

$html .= sprintf( '<a href="%s" title="Permalink to %s">%s</a>',
esc_url( get_term_link( $term ) ),
esc_attr( $term->name ),
wptexturize( $term->name )
);

if( $counter < $total ){
$html .= ', ';
}
$counter++;

}

echo wpautop( $html );

}

由于某种原因,该 URL 不是一个漂亮的固定链接。已经很晚了,我不知道这是否与我的配置有关,或者究竟是什么,但这是一个开始。

关于wordpress - 在 WordPress/WooCommerce 中获取产品属性术语永久链接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29548487/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com