我正在使用下面的代码来显示WooCommerce中价格变化旁边的价格。
当变体的长度不同时,它很出色,但价格不一致。 (附有图片)。
如何对齐这些文本(价格)?这是site。
代码:
//Add prices to variations
add_filter( 'woocommerce_variation_option_name', 'display_price_in_variation_option_name' );
function display_price_in_variation_option_name( $term ) {
global $wpdb, $product;
$result = $wpdb->get_col( "SELECT slug FROM {$wpdb->prefix}terms WHERE name = '$term'");
$term_slug = ( !empty( $result ) ) ? $result[0] : $term;
$query = "SELECT postmeta.post_id AS product_id
FROM {$wpdb->prefix}postmeta AS postmeta
LEFT JOIN {$wpdb->prefix}posts AS products ON ( products.ID = postmeta.post_id )
WHERE postmeta.meta_key LIKE 'attribute_%'
AND postmeta.meta_value = '$term_slug'
AND products.post_parent = $product->id";
$variation_id = $wpdb->get_col( $query );
$parent = wp_get_post_parent_id( $variation_id[0] );
if ( $parent > 0 ) {
$_product = new WC_Product_Variation( $variation_id[0] );
//this is where you can actually customize how the price is displayed
return $term . ' ' . woocommerce_price( $_product->get_price() ) . '';
}
return $term;
}
答案 0 :(得分:1)
请添加此CSS。
serialized_example = example.SerializeToString()
理想情况下,这样的CSS应该在WordPress child theme之内。但是,如果您只是在解决问题,该插件也可以为您提供帮助:https://en-gb.wordpress.org/plugins/simple-custom-css/
谢谢