Skip to content

Instantly share code, notes, and snippets.

@SiR-DanieL
Created February 1, 2021 04:28
Show Gist options
  • Save SiR-DanieL/cd8ac04c2ec85f56a1e10790bd610e67 to your computer and use it in GitHub Desktop.
Save SiR-DanieL/cd8ac04c2ec85f56a1e10790bd610e67 to your computer and use it in GitHub Desktop.
add_shortcode( 'price_per_weight', 'wc_custom_per_price_weight' );
function wc_custom_per_price_weight() {
global $product;
if ( $product ) {
$price = $product->get_price();
$weight = $product->get_weight();
$price_kg = $price / $weight;
return wc_price( $price_kg );
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment