wooCommerce与ACF商店/目录页面上的自定义相关产品
我有一家WooCommerce商店,希望能够在商店/目录页面上显示每种产品的自定义相关产品。
我的设置
使用高级自定义字段Pro
我创建了一个具有关系字段的字段组,称为:
每种产品的product_Realations我通过product_Realations字段选项选择了后端的“ product_relations”字段选项。
然后,我创建了一个可以在商店/目录页面上可见的短代码。
我确实看到只能输出我想要的输出。
当前输出
我只看到最新产品的关系>>请参阅屏幕截图

,这是我到目前为止的代码:
function yl_product_relations_shortcode() {
global $product;
$product_relations = get_field('product_relations');
if ($product_relations) {
$output .= '<ul class="uk-thumbnav uk-margin-bottom">';
foreach ($product_relations as $product_relation) {
$title = get_the_title($product_relation);
$image = get_the_post_thumbnail_url($product_relation);
$url = get_the_permalink($product_relation);
$output .= '<li><a href="' . $url . '" uk-tooltip="' . $title . '"><img src="' . $image . '" class="uk-border-rounded" width="40"></a></li>';
}
$output .= '</ul>';
}
return $output;
}
add_shortcode('yl_product_relations','yl_product_relations_shortcode');
没人? 我使用WordPress Cusomizer,我正在使用短码来收集TE数据。
[yl_product_relations]
当我尝试添加product_id时,
$id = $product->get_id();
$product_relations = get_field('product_relations', $id);
我会遇到错误。可能是因为我正在使用定制器,因此在产品循环本身中没有真正编码。
I have a WooCommerce shop and want to be able to display custom related products, for each product, on the shop/catalog page.
My setup
Using Advanced Custom Fields Pro
I have created a field group with a RELATION field called: product_relations
For each product I have selected several 'custom related products' via the product_relations field option on the product page in the backend.
I then created a shortcode to be visible on the shop/catalog page.
I do see output only not the output I would like.
The current output
I only see the relations of the LATEST PRODUCT >> See screenshot
Here's my code I have so far:
function yl_product_relations_shortcode() {
global $product;
$product_relations = get_field('product_relations');
if ($product_relations) {
$output .= '<ul class="uk-thumbnav uk-margin-bottom">';
foreach ($product_relations as $product_relation) {
$title = get_the_title($product_relation);
$image = get_the_post_thumbnail_url($product_relation);
$url = get_the_permalink($product_relation);
$output .= '<li><a href="' . $url . '" uk-tooltip="' . $title . '"><img src="' . $image . '" class="uk-border-rounded" width="40"></a></li>';
}
$output .= '</ul>';
}
return $output;
}
add_shortcode('yl_product_relations','yl_product_relations_shortcode');
Nobody?
I use the WordPress Cusomizer and I'm using a shortcode to collect te data.
[yl_product_relations]
When I try to add the product_id like this
$id = $product->get_id();
$product_relations = get_field('product_relations', $id);
I get an error. Probably because I'm using the customizer and therefor not really coding within the product loop itself..?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论