单个span标记内的多个变量

时间:2018-01-06 03:59:27

标签: php html wordpress woocommerce global-variables

我有以下几行:

$output .= '<span class="product__price">' . $product->get_price_html() . '</span>';

这将输出Woocommerce产品的价格。

我创建了一个自定义的Woocommerce字段 - 一个标签 - 我想添加这个标签,以便它显示在这个价格的后面。

要获取我的标签自定义字段,我使用:

$price_label = get_post_meta( $post->ID, 'custom_product_price_labels', true );

我尝试通过以下字符串实现此目的:

$output .= '<span class="product__price">' . $product->get_price_html() . '</span><span class="product__price">' . get_post_meta( $post->ID, 'custom_product_price_labels', true ) . '</span>';

所以我有2个span标签彼此相邻。它提取价格和我的标签,但它将它们放在彼此的顶部,而不是像价格一样紧挨着标签。

理想情况下,我需要将第二个变量字符串放在同一个span标记内。

我正在尝试这个:

$output .= '<span class="product__price">' . $product->get_price_html(); get_post_meta( $post->ID, 'custom_product_price_labels', true ) .'</span>';

但这不会奏效。

有没有办法实现这个目标?

1 个答案:

答案 0 :(得分:2)

通过在每个字符串段或函数调用之间使用.来实现此目的!

在您的情况下,它看起来像这样:$output .= '<span class="product__price">' . $product->get_price_html() . " " . get_post_meta( $post->ID, 'custom_product_price_labels', true ) .'</span>';