Skip to content

Instantly share code, notes, and snippets.

@braddalton
Created June 7, 2024 14:35
Show Gist options
  • Save braddalton/f96bfe965626d23c06821c820258297c to your computer and use it in GitHub Desktop.
Save braddalton/f96bfe965626d23c06821c820258297c to your computer and use it in GitHub Desktop.
WooCommerce Get the custom price per square meter
// Get the product object
global $product;
// Get the regular price
$price_per_tile = $product->get_price();
// Get the custom price per square meter (assuming it is stored as a custom field)
$price_per_m2 = get_post_meta( $product->get_id(), 'price_per_square_meter', true );
// Display the prices with descriptions
if ( $price_per_tile ) {
echo '<p>' . wc_price( $price_per_tile ) . ' per tile</p>';
}
if ( $price_per_m2 ) {
echo '<p>' . wc_price( $price_per_m2 ) . ' per m²</p>';
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment