Skip to content

Instantly share code, notes, and snippets.

@webtoffee-git
Last active March 3, 2025 04:30
Show Gist options
  • Save webtoffee-git/c9dd28bbb89f7c0813cde099ab0501dc to your computer and use it in GitHub Desktop.
Save webtoffee-git/c9dd28bbb89f7c0813cde099ab0501dc to your computer and use it in GitHub Desktop.
Code to hide the original price and display only the discounted price for the BOGO gift item(Old bogo) - By WebToffee (Smart Coupon For WooCommerce Plugin)
<?php //Do not copy this line of code
add_filter( 'woocommerce_cart_item_subtotal', 'wbte_sc_ctm_alter_cart_item_price', 1001, 2 );
add_filter( 'woocommerce_cart_item_price', function( $price, $cart_item ) {
return wbte_sc_ctm_alter_cart_item_price( $price, $cart_item, false );
}, 11, 2 );
function wbte_sc_ctm_alter_cart_item_price( $price, $cart_item, $is_total = true )
{
$out = $price;
if (
class_exists( 'Wt_Smart_Coupon_Giveaway_Product_Public' )
&& class_exists( 'Wt_Smart_Coupon_Giveaway_Product' )
&& method_exists( 'Wt_Smart_Coupon_Giveaway_Product_Public', 'is_a_free_item' )
&& method_exists( 'Wt_Smart_Coupon_Giveaway_Product', 'get_product_price' )
&& method_exists( 'Wt_Smart_Coupon_Giveaway_Product', 'get_available_discount_for_giveaway_product' )
&& method_exists( 'Wt_Smart_Coupon_Giveaway_Product', 'get_product_giveaway_data' )
&& Wt_Smart_Coupon_Giveaway_Product_Public::is_a_free_item( $cart_item )
) {
$giveaway_common_module = Wt_Smart_Coupon_Giveaway_Product::get_instance();
$coupon_code = wc_format_coupon_code( $cart_item['free_gift_coupon'] );
$item_id = ( $cart_item['variation_id'] > 0 ) ? $cart_item['variation_id'] : $cart_item['product_id'];
$product = wc_get_product( $item_id );
$product_price = Wt_Smart_Coupon_Giveaway_Product::get_product_price( $product );
$giveaway_data = $giveaway_common_module->get_product_giveaway_data( $item_id, $coupon_code, $cart_item );
$discount = Wt_Smart_Coupon_Giveaway_Product::get_available_discount_for_giveaway_product( $product, $giveaway_data );
$sale_price_after_discount = $product_price - $discount;
if ( $is_total ) {
$sale_price_after_discount *= $cart_item['quantity'];
}
$out = '<span>' . wc_price( $sale_price_after_discount ) . '</span>';
}
return $out;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment