Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save ejntaylor/6843817 to your computer and use it in GitHub Desktop.
Save ejntaylor/6843817 to your computer and use it in GitHub Desktop.
<?php
/**
* Plugin Name: WooCommerce VAT
* Plugin URI: http://raison.co/
* Description: Adds VAT at 20% to products on shop and archive pages
* Author: raisonon
* Author URI: http://www.raison.co/
* Version: 1.1
* License: GPLv2 or later
*/
/* IMPORTANT - Must have prices set to show product Exclusing Tax in WooCommerce Settings */
/**
* Calculates the price + 20% VAT
*
* @return string price + 20% VAT
*/
function cs_product_parceled() {
$product = get_product();
if ( $product->get_price_including_tax() ) {
$value = woocommerce_price( $product->get_price_including_tax() * 1.2 );
return $value;
}
}
/**
* Displays the price + 20% VAT on product loop.
*
* @return string price + 20% VAT
*/
function cs_product_parceled_loop() {
echo '<br /><span style="color: #666; font-size: 100%" class="price">' . __( 'Incl. VAT:' ) . ' ' . cs_product_parceled() . '</span>';
}
/**
* Displays the price + 20% VAT
*
* @return string price + 20% VAT
*/
function cs_product_parceled_single() {
$product = get_product();
?>
<div itemprop="offers" itemscope itemtype="http://schema.org/Offer">
<p style="margin: 0;" itemprop="price" class="price">
<?php echo $product->get_price_html(); ?>
</p>
<p>
<span style="color: #666; font-size: 100%" class="price"><?php _e( 'Incl. VAT:' ) ?> <?php echo cs_product_parceled(); ?></span>
</p>
<meta itemprop="priceCurrency" content="<?php echo get_woocommerce_currency(); ?>" />
<link itemprop="availability" href="http://schema.org/<?php echo $product->is_in_stock() ? 'InStock' : 'OutOfStock'; ?>" />
</div>
<?php
}
add_action( 'woocommerce_after_shop_loop_item_title', 'cs_product_parceled_loop', 20 );
remove_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_price', 10 );
add_action( 'woocommerce_single_product_summary', 'cs_product_parceled_single', 10 );
?>
@broadeye
Copy link

broadeye commented Oct 7, 2013

sounds about right - I have everything working fine using plugin combined with the remove action in child theme functions.php.

@ejntaylor
Copy link
Author

You can now find this as an extension here: http://codecanyon.net/item/woocommerce-tax-toggle/7796887

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment