Hello I am looking to show a coupon discounted price on a woo-commerce product pages. I found code that is written for woo-commerce 3.x but that is pretty outdated and we are running the latest release 6.9.1. The code for 3.x is below. Any help would be fantastic.
with this code it returns this error
syntax error, unexpected '}', expecting end of file
if ( WC()->cart->has_discount() ) {
$values = array (
'data' => $product,
'quantity' => 1
);
$coupons = WC()->cart->get_coupons();
$_price = $product->get_price();
$undiscounted_price = $_price;
if ( ! empty( $coupons ) ) {
foreach ( $coupons as $code => $coupon ) {
if ( $coupon->is_valid() && ( $coupon->is_valid_for_product( $product, $values ) || $coupon->is_valid_for_cart() ) ) {
$discount_amount = $coupon->get_discount_amount( 'yes' === get_option( 'woocommerce_calc_discounts_sequentially', 'no' ) ? $_price : $undiscounted_price, $values, true );
$discount_amount = min( $_price, $discount_amount );
$_price = max( $_price - $discount_amount, 0 );
}
if ( 0 >= $_price ) {
break;
}
}
if ( ( $product->get_price() > 0 ) && ( $undiscounted_price !== $_price ) )
$price = wc_format_sale_price( wc_get_price_to_display( $product, array( 'price' => $undiscounted_price ) ), $_price ) . $product->get_price_suffix();
}
}
return $price;
}