0

我需要在价格之后附加一个名为unit_description的自定义字段,这样它就会显示为例如 $7.00 per sandwich

我想它会从以下开始:

remove_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_price', 10 );
4

1 回答 1

3

尝试这个:

add_filter( 'woocommerce_price_format', 'overwrite_woocommerce_price_format', 10, 2 );

function overwrite_woocommerce_price_format( $format, $currency_pos ) {
    global $post;
    if ( $post->post_type != 'product' ) return $format;
    $custom_field = get_post_meta( $post->ID, 'unit_description', true );   // This will return your custom field value
    return $format . ' ' . __( $custom_field, 'woocommerce' );  // Here you'll append your custom field with price
}

希望这会有所帮助

于 2013-07-12T07:44:47.597 回答