Created
September 17, 2017 06:57
-
-
Save neilgee/488450732c147510e2c283fe7bb2f70a to your computer and use it in GitHub Desktop.
WooCommerce add a weight amount after the price such as 'per kg'
This file contains 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
<?php //<~ don't add me in | |
add_filter( 'woocommerce_get_price_html', 'wb_change_product_html' ); | |
// Change and return $price_html variable using the $price and weight amount | |
function wb_change_product_html( $price ) { | |
$price_html = '<span class="amount">' . $price . ' per kg </span>'; // change weight measurement here | |
return $price_html; | |
} | |
add_filter( 'woocommerce_cart_item_price', 'wb_change_product_price_cart' ); | |
// Change the cart prices with $price variable and weight amount | |
function wb_change_product_price_cart( $price ) { | |
$price = $price . ' per kg'; // change weight measurement here | |
return $price; | |
} | |
add_filter( 'woocommerce_checkout_cart_item_quantity', 'wb_checkout_review', 10, 3 ); | |
// Change the checkput prices with $cart_item variable and weight amount | |
function wb_checkout_review ( $quantity, $cart_item, $cart_item_key ) { | |
$cart_item = ' <strong class="product-quantity">' . sprintf( '× %s', $cart_item['quantity'] ) . ' kg </strong>'; // change weight measurement here | |
return $cart_item; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment