Skip to content

Instantly share code, notes, and snippets.

@rdhimanam
Created January 4, 2022 17:51
Show Gist options
  • Save rdhimanam/b07dfa8d0fdb0126b9c73756ad3d18ac to your computer and use it in GitHub Desktop.
Save rdhimanam/b07dfa8d0fdb0126b9c73756ad3d18ac to your computer and use it in GitHub Desktop.
Fix prices for products including tax
function monsterinsights_attach_tax_details( $body ){
if ( ! empty( $body ) && is_array( $body ) && array_key_exists( 'ea', $body ) && $body['ea'] === 'Completed Checkout' ) {
if ( class_exists( 'WooCommerce' ) && function_exists( 'wc_get_order' ) ) {
$order = wc_get_order( $body['el'] );
$items = $order->get_items();
$count = 1;
foreach ( $items as $item ){
$product_id = $item['variation_id'] ? $item['variation_id'] : $item['product_id'];
$product = wc_get_product( $product_id );
$price = wc_get_price_including_tax( $product );
$body_price = "pr" . $count . "pr";
$body[ $body_price ] = $price;
$count ++;
}
}
}
return $body;
}
add_filter( 'monsterinsights_mp_api_call', 'monsterinsights_attach_tax_details', 999, 1 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment