Skip to content

Commit

Permalink
Fixed WC sale landing page not always showing discounts if applying d…
Browse files Browse the repository at this point in the history
…iscount code automatically
  • Loading branch information
dparker1005 committed Sep 17, 2020
1 parent 6f13cac commit e18d791
Showing 1 changed file with 19 additions and 2 deletions.
21 changes: 19 additions & 2 deletions modules/class-swsales-module-wc.php
Original file line number Diff line number Diff line change
Expand Up @@ -289,9 +289,26 @@ public static function strike_prices( $price, $product ) {
if ( null === $active_sitewide_sale || 'wc' !== $active_sitewide_sale->get_sale_type() || is_admin() ) {
return $price;
}

$coupon_id = $active_sitewide_sale->get_meta_value( 'swsales_wc_coupon_id', null );
if ( null !== $coupon_id && WC()->cart->has_discount( wc_get_coupon_code_by_id( $coupon_id ) ) ) {
if ( null === $coupon_id ) {
return $price;
}
// Check if we are on the landing page
$landing_page_post_id = intval( $active_sitewide_sale->get_landing_page_post_id() );
$on_landing_page = false;
if (
( ! empty( $_SERVER['REQUEST_URI'] ) && intval( url_to_postid( $_SERVER['REQUEST_URI'] ) ) === $landing_page_post_id ) ||
( ! empty( $_SERVER['HTTP_REFERER'] ) && intval( url_to_postid( $_SERVER['HTTP_REFERER'] ) ) === $landing_page_post_id )
) {
$on_landing_page = true;
}
$should_apply_discount_on_landing = ( 'none' !== $active_sitewide_sale->get_automatic_discount() );

// If discount code is already applied or we are on the landing page and should apply discount...
if (
( ! empty( WC()->cart ) && WC()->cart->has_discount( wc_get_coupon_code_by_id( $coupon_id ) ) ) ||
( $on_landing_page && $should_apply_discount_on_landing )
) {
$coupon = new \WC_Coupon( wc_get_coupon_code_by_id( $coupon_id ) );
if ( $coupon->is_valid() && $coupon->is_valid_for_product( $product ) ) {
// Get pricing for simple products.
Expand Down

0 comments on commit e18d791

Please sign in to comment.