在 foreach 循环中显示 WooCommerce 产品 SKU(ACF 关系字段)
Display WooCommerce product SKU in foreach loop (ACF relationship field)
我正在使用 ACF 关系字段,以便在单个自定义 post 类型页面上显示特定的 woocommerce 产品。下面的代码工作正常,但我也想回应产品 SKU,但无法弄清楚。以下是我当前的代码:
<?php $posts = get_field('linked_realisaties');
if( $posts ): ?>
<?php foreach( $posts as $p): ?>
<a href="<?php echo get_permalink( $p->ID ); ?>">
<?php
echo get_the_post_thumbnail( $p->ID, 'thumbnail' )
?>
<div style="overflow:hidden">
<span><?php the_field('linked_product_1_qty'); ?>x <?php echo $p->post_title; ?></span>
</div>
</a>
<?php endforeach; ?>
<?php endif; ?>
<?php $posts = get_field('linked_realisaties');
if ($posts):
?>
<?php foreach ($posts as $p):
$product = wc_get_product($p->ID);
$product_perma_link = $product->get_permalink();
$sku = $product->get_sku();
$product_name = $product->get_name();
?>
<a href="<?php echo $product_perma_link ?>">
<?php
echo get_the_post_thumbnail($p->ID, 'thumbnail')
?>
<div style="overflow:hidden">
<span><?php the_field('linked_product_1_qty'); ?>x <?php echo $product_name ?></span>
</div>
</a>
<?php endforeach; ?>
<?php endif; ?>
我正在使用 ACF 关系字段,以便在单个自定义 post 类型页面上显示特定的 woocommerce 产品。下面的代码工作正常,但我也想回应产品 SKU,但无法弄清楚。以下是我当前的代码:
<?php $posts = get_field('linked_realisaties');
if( $posts ): ?>
<?php foreach( $posts as $p): ?>
<a href="<?php echo get_permalink( $p->ID ); ?>">
<?php
echo get_the_post_thumbnail( $p->ID, 'thumbnail' )
?>
<div style="overflow:hidden">
<span><?php the_field('linked_product_1_qty'); ?>x <?php echo $p->post_title; ?></span>
</div>
</a>
<?php endforeach; ?>
<?php endif; ?>
<?php $posts = get_field('linked_realisaties');
if ($posts):
?>
<?php foreach ($posts as $p):
$product = wc_get_product($p->ID);
$product_perma_link = $product->get_permalink();
$sku = $product->get_sku();
$product_name = $product->get_name();
?>
<a href="<?php echo $product_perma_link ?>">
<?php
echo get_the_post_thumbnail($p->ID, 'thumbnail')
?>
<div style="overflow:hidden">
<span><?php the_field('linked_product_1_qty'); ?>x <?php echo $product_name ?></span>
</div>
</a>
<?php endforeach; ?>
<?php endif; ?>