Skip to content

Instantly share code, notes, and snippets.

@arioch1984
arioch1984 / wp_percentage_discount
Created May 16, 2014 16:04
WP filter price for add discount as percentage
<?php
add_filter( 'woocommerce_get_price_html', 'wpa83367_price_html', 100, 2 );
function wpa83367_price_html( $price, $product ){
preg_match_all('!\d+\,*\d*!', $price, $prices);
$discount = '';
if(isset($prices[0]) && !empty($prices[0])){
if(count($prices[0])==2){ //There's total and discount prices
$total_price = floatval(str_replace(',', '.', $prices[0][0]));
$discount_price = floatval(str_replace(',', '.', $prices[0][1]));
$discount_amount = $total_price - $discount_price;
@arioch1984
arioch1984 / parse_string_for_numbers
Created May 16, 2014 15:47
Parse string for float numbers
<?php
preg_match_all('!\d+\,*\d*!', $price, $matches);
?>
@arioch1984
arioch1984 / console_log_wrap_coffee_script
Last active August 29, 2015 14:01
console log wrapper coffee script
window.debugMode = document.location.hash.match(/debug/) and console?   console.log 'This is the first of many debug-mode outputs' if debugMode