Woocommerce php code get_price_html()

Woocommerce php code get_price_html()

  1. Blog
  2. 15 November 2026
  3. 3 min read

Stefan Bogdanescu

Founder & Senior Architect

Decoupling Product Titles and Prices in WooCommerce Templates

When inspecting a standard WooCommerce product archive or single page, you'll often find the price rendered inline directly after the product title. In your specific case using the Artificer theme, this is happening because the index.php template explicitly calls echo $_product->get_price_html(); immediately following the title output. While this approach works for basic layouts, it tightly couples two distinct data points: the human-readable name of the item and its calculated cost. If your design requires a vertical separation—displaying the title on one line and the price on the next—you need to modify how these elements are rendered or ensure the HTML structure supports the line break without breaking the layout flow.

The core function driving this behavior is get_price_html(). This method is part of the WC_Product class and returns a string that includes both the formatted currency symbol, the amount, and often applies filters to handle tax logic or display text like "Incl. VAT" if configured in your store settings. Because it returns a fully formed HTML string (typically inside a <span>), inserting a raw <br /> tag directly before or after the echo statement can sometimes lead to inconsistent rendering depending on how CSS handles whitespace and block-level elements.

To achieve the desired "Black Stone
$43" layout, you must look at the template hierarchy rather than just appending an HTML tag manually. The most robust solution involves creating a custom child theme for your Artificer installation. Inside that child theme, locate the archive-product.php or single-product.php file corresponding to the section showing the title and price. You can override the specific loop variable output or create a new partial template using the WordPress Template Hierarchy rules.

If you prefer a minimal change within the existing file structure provided by the theme, wrap the output in a container that explicitly handles the line break. Instead of relying on get_price_html() to be the sole source of truth for the layout, consider separating the title and price into distinct HTML elements:

<h3>
    <?php the_title(); ?>
</h3>
<span class="price">
    <?php echo wc_price( get_price_html() ); ?> 
</span>

Wait—there is a nuance here. The get_price_html() method returns the formatted string already. If you simply echo it, you are outputting whatever filters have been applied. To ensure clean separation, you might want to check if wc_price() is available in your version of WooCommerce. In modern versions (3.5+), wc_price() is often preferred over manually echoing get_price_html() because it offers better hookability and respects global settings like currency symbols more dynamically.

However, the most direct fix for your immediate layout requirement is to modify the HTML structure in the Artificer theme's product loop. You can insert a <br /> tag between the title closing tag and the price opening span. This forces a line break in the DOM. Alternatively, apply CSS classes to force the block behavior:

.price-wrapper {
    display: block;
}
.price-title {
    display: block;
}

By assigning specific classes to your title and price elements, you can control spacing without relying on <br /> tags, which are often discouraged in modern CSS-driven designs. This approach also opens the door for responsive adjustments; you could use media queries to stack them vertically on mobile but align them horizontally on desktop if needed.

Be cautious when overriding theme files directly. If you update the Artificer theme in the future, your custom changes to index.php will be overwritten. Always copy the necessary template files into a child theme directory to preserve your layout modifications. This practice ensures that your specific design requirement—separating the product title and price with a line break—remains intact regardless of upstream theme updates.

If you find yourself needing to manipulate the price string further before outputting it, remember that get_price_html() supports filters like woocommerce_product_get_price_html. You can hook into this to modify the output programmatically, but for simple layout changes like adding a line break, structural HTML adjustments in the template file remain the most efficient and maintainable path.

Our network