在可变产品页面上的添加到购物车按钮后,我试图在我的单个产品页面上显示选定的产品变体描述。
下面是我实现的代码,但它似乎没有工作:
add_action( 'woocommerce_after_add_to_cart_form', 'description_below_add_cart', 11 );
function description_below_add_cart() {
global $post;
$terms = wp_get_post_terms( $post->ID, 'product_cat' );
foreach ( $terms as $term ) $categories[] = $term->slug;
if ( in_array( 'cookware', $categories ) ) {
global $product;
$weight = $product->get_weight();
$dimensions = wc_format_dimensions($product->get_dimensions(false));
echo '<div class="short-description">' . $item['product']->get_description() .'</div>';
}
}
这是该网站的产品页面。
在将可变产品添加到购物车按钮后,如何在 Woocommerce 中显示所选产品变体的特定数据(变体描述) ?