Skip to content

Instantly share code, notes, and snippets.

@Auke1810
Last active February 7, 2022 11:39
Show Gist options
  • Save Auke1810/ff38d4b170d9a80307067ea5120c8393 to your computer and use it in GitHub Desktop.
Save Auke1810/ff38d4b170d9a80307067ea5120c8393 to your computer and use it in GitHub Desktop.
<?php
// Price including or excluding tax
function tax_price( $data, $feed_id, $product_id ) {
global $product, $woocommerce;
// Only add this to the feed with id 58
// change the number to the feed you want to affect the prices.
// OR remove the if statement if you want to affect all feeds
if($feed_id == 1){
$product = wc_get_product( $product_id );
$currency_symbol = get_woocommerce_currency_symbol();
// Get the prices
$price_excl_tax = wc_get_price_excluding_tax($product);
$price_incl_tax = wc_get_price_including_tax($product);
// Calculate tax amount
$tax_amount = $price_incl_tax - $price_excl_tax;
// Store the price with tax AND without tax in the feed custome label X element.
// Use $data['price'] OR/AND $data['sales_price'] to set the price to those elements in the feed.
$data['custom_label_0'] = "Including: " . wc_price($price_incl_tax);
$data['custom_label_1'] = "Excluding: " . wc_price($price_excl_tax);
$data['custom_label_2'] = "Tax ammount: " . wc_price($tax_amount);
// store the price including tax in the price attribute
// If you setup the price attribute with Woocommerce currency this will be added automaticaly. (Like EUR or USD)
$data['price'] = wc_price($price_incl_tax);
}
// Always return data!
return $data;
}
add_filter( 'wppfm_feed_item_value', 'tax_price', 10, 3 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment