我想始终在产品页面上显示每个变体的变体描述(目前它只会显示通过下拉列表选择的任何变体的描述)。我似乎无法访问
在plugins/woocommerce/templates/single-product/add-to-cart/variation.php
中,它似乎可以通过以下方式访问:
{{{ data.variation.variation_description }}}
在编辑产品页面中检查所需字段时,它name=
是:
variable_description0
我尝试通过这两种方式访问,以及:
if($product && taxonomy_exists($attribute)) {
$terms = wc_get_product_terms($product->get_id(), $attribute, array(
'fields' => 'all',
));
foreach($terms as $term) {
$variable_description = get_post_meta( $id, '_variation_description', true );
if(in_array($term->slug, $options, true)) {
$radios .= '<div><input type="radio" name="'.esc_attr($name).'" value="'.esc_attr($term->slug).'" '.checked(sanitize_title($args['selected']), $term->slug, false).'><label for="'.esc_attr($term->slug).'">'.esc_html(apply_filters('woocommerce_variation_option_name', $term->name)).' <span class="description">' . 'DESCRIPTION' . '</span></label></div>';
}
}
} else {
foreach($options as $option) {
// var_dump($options);
$variable_description = get_post_meta( $id, '_variation_description', true );
$checked = sanitize_title($args['selected']) === $args['selected'] ? checked($args['selected'], sanitize_title($option), false) : checked($args['selected'], $option, false);
$radios .= '<div><input type="radio" name="'.esc_attr($name).'" value="'.esc_attr($option).'" id="'.sanitize_title($option).'" '.$checked.'><label for="'.sanitize_title($option).'">'.esc_html(apply_filters('woocommerce_variation_option_name', $option)).' <span class="description">' . $variable_description . '</span></label></div>';
}
}
然而,一切都返回为 NULL。
我应该为 $id 使用什么/如何为所有变量打印出来?