当前,我在woocommerce中修改单个产品,我将一个acf字段创建为一个名为配方的自定义帖子类型,我想基于acf值显示与当前产品相关的配方... 这是我的代码
/**
* Product Recipes
*/
function show_product_recipes() {
$product = new WC_product( get_the_ID() );
$product_id = get_the_ID();
$product_recipes = get_field( 'zf_recipes', $product_id );
// print_r( $product );
if ( $product_recipes ) :
echo '<div class="product-recipes">';
echo '<h2 class="section-title">'. __( 'Product recipes', 'zumra' ) .'</h2>';
echo '</div>';
wp_reset_postdata();
endif;
}
add_action( 'woocommerce_after_single_product_summary', 'show_product_recipes', 20 );
/**
* Product Recipes
*/
function show_product_recipes() {
$product = new WC_product( get_the_ID() );
$product_id = get_the_ID();
$product_recipes = get_field( 'zf_recipes', $product_id );
// print_r( $product );
if ( $product_recipes ) :
echo '<div class="product-recipes">';
echo '<h2 class="section-title">'. __( 'Product recipes', 'zumra' ) .'</h2>';
echo '</div>';
wp_reset_postdata();
endif;
}
add_action( 'woocommerce_after_single_product_summary', 'show_product_recipes', 20 );