Skip to content

Instantly share code, notes, and snippets.

@helgatheviking
Created May 6, 2017 17:49
Show Gist options
  • Save helgatheviking/6278f960f5fb7fca101e75f30f33141c to your computer and use it in GitHub Desktop.
Save helgatheviking/6278f960f5fb7fca101e75f30f33141c to your computer and use it in GitHub Desktop.
Switch Free prices to "Price upon Request"
<?php
/**
* Plugin Name: Price Upon Request
* Plugin URI: https://gist.github.com/helgatheviking/6278f960f5fb7fca101e75f30f33141c
* Description: Switch Free prices to "Price upon Request"
* Version: 0.1.0
* Author: helgatheviking
* Author URI: https://kathyisawesome.com
* Requires at least: 4.7
* Tested up to: 4.7
*
* Text Domain: your-plugin
* Domain Path: /languages/
*
*/
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly.
}
/**
* Hides the 'Free!' price notice
* @param bool $price
* @param WC_Product obj $product
* return string
*/
function kia_hide_free_price_notice( $price, $product ) {
if ( $product->get_price() == 0 ) {
$price = '<span class="woocommerce-Price-amount amount">' . __( 'Price upon request.', 'your-plugin' ) . '</span>';
}
return $price;
}
add_filter( 'woocommerce_get_price_html', 'kia_hide_free_price_notice', 10, 2 );
/**
* Shows the notice for varitions
* @param bool $show
* @param WC_Product_Variation obj $variation
* return bool
*/
function kia_show_variation_price( $show, $variation ) {
if ( $variation->get_price() == 0 ) {
$show = true;
}
return $show;
}
add_filter( 'woocommerce_show_variation_price', 'kia_show_variation_price', 10, 2 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment