【发布时间】:2016-12-07 15:09:59
【问题描述】:
我正在尝试将变量描述显示到 woocommerce 产品页面中。 我安装了一个名为 woocommerce 单选按钮的插件,用于将我的可变产品和价格显示为单选按钮而不是选择按钮。
我正在这个插件中编辑 variable.php 文件(完成后我会将它转移到我的子主题),基本上我需要将变量描述显示为标签,作为名为 $variable_description 的变量。
printf( '<div>
<input type="radio" name="%1$s" value="%2$s" id="%3$s" %4$s>
<label for="%3$s">%5$s</label>
<label>'.$variable_description.'</label>
</div>', $input_name, $esc_value, $id, $checked, $filtered_label );
由于我不了解数据库的结构,我无法从数据库中恢复这些数据。
你知道任何短代码或函数来恢复它并显示每个可变价格的变量描述吗?
在我正在编辑的函数中,作为第一个标签的单选按钮旁边的每个变体都正确显示了价格。该函数的完整代码为:
if ( ! function_exists( 'print_attribute_radio' ) ) {
function print_attribute_radio( $checked_value, $value, $label, $name, $product_id ) {
// This handles < 2.4.0 bw compatibility where text attributes were not sanitized.
$checked = sanitize_title( $checked_value ) === $checked_value ? checked( $checked_value, sanitize_title( $value ), false ) : checked( $checked_value, $value, false );
$input_name = 'attribute_' . esc_attr( $name ) ;
$esc_value = esc_attr( $value );
$id = esc_attr( $name . '_v_' . $value );
$filtered_label = apply_filters( 'woocommerce_variation_option_name', $label );
//here is where I try to recover the variable_description
global $wpdb;
$post_id = $product_id + 3;
$querystr = "SELECT wpostmeta.meta_value
FROM $wpdb->postmeta wpostmeta
WHERE wpostmeta.post_id = '$post_id'
AND wpostmeta.meta_key = '_variation_description'
ORDER BY wpostmeta.meta_value DESC
";
$variable_description = $wpdb->get_var($querystr);
printf( '<div>
<input type="radio" name="%1$s" value="%2$s" id="%3$s" %4$s>
<label for="%3$s">%5$s</label>
<label>'.$variable_description.'</label>
</div>', $input_name, $esc_value, $id, $checked, $filtered_label );
}
}
谢谢
【问题讨论】:
标签: php wordpress woocommerce product variations