Created
June 7, 2024 14:35
-
-
Save braddalton/f96bfe965626d23c06821c820258297c to your computer and use it in GitHub Desktop.
WooCommerce Get the custom price per square meter
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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