diff --git a/admin/class-wc-cdp-admin.php b/admin/class-wc-cdp-admin.php index 896724e..e21c39a 100755 --- a/admin/class-wc-cdp-admin.php +++ b/admin/class-wc-cdp-admin.php @@ -190,7 +190,7 @@ class Wc_Cdp_Admin { $product->update_meta_data( '_wc_cdp_bundle_products', $_POST['_wc_cdp_bundle_products'] ); } - if ( isset($_POST['_wc_cdp_bundle_coupon']) && $_POST['_wc_cdp_bundle_coupon'] ) { + if ( isset($_POST['_wc_cdp_bundle_coupon']) ) { $product->update_meta_data( '_wc_cdp_bundle_coupon', $_POST['_wc_cdp_bundle_coupon'] ); } diff --git a/public/class-wc-cdp-public.php b/public/class-wc-cdp-public.php index 2f10eab..c1853d3 100755 --- a/public/class-wc-cdp-public.php +++ b/public/class-wc-cdp-public.php @@ -118,6 +118,8 @@ class Wc_Cdp_Public { { $product = wc_get_product( $product_id ); + if ( !$product->get_meta( '_wc_cdp_bundle_coupon' ) ) return null; + $bundle_coupon = new WC_Coupon( $product->get_meta( '_wc_cdp_bundle_coupon' ) ); $bundle_coupon_type = $bundle_coupon->get_discount_type(); @@ -131,10 +133,6 @@ class Wc_Cdp_Public { private function should_display_bundle_modal($product_id) { - $bundle_coupon = $this->get_bundle_coupon($product_id); - - if (!$bundle_coupon) return false; - $bundle_products = $this->get_bundle_products($product_id); if (!$bundle_products) return false; @@ -180,12 +178,15 @@ class Wc_Cdp_Public { $bundle_coupon = $this->get_bundle_coupon( $product->get_id() ); - if ($bundle_coupon->get_discount_type() === 'percent') { - $bundle_discount_price = $bundle_regular_price * ( 1 - $bundle_coupon->get_amount()/100 ); - } else { - $bundle_discount_price = $bundle_regular_price - $bundle_coupon->get_amount(); + if ($bundle_coupon) { + if ($bundle_coupon->get_discount_type() === 'percent') { + $bundle_discount_price = $bundle_regular_price * ( 1 - $bundle_coupon->get_amount()/100 ); + } else { + $bundle_discount_price = $bundle_regular_price - $bundle_coupon->get_amount(); + } } + require('partials/product-bundle-modal.php'); } @@ -214,7 +215,9 @@ class Wc_Cdp_Public { } } - WC()->cart->apply_coupon( $_POST['wc_cdp_bundle_coupon'] ); + if ( isset( $_POST['wc_cdp_bundle_coupon'] ) && $_POST['wc_cdp_bundle_coupon'] ) { + WC()->cart->apply_coupon( $_POST['wc_cdp_bundle_coupon'] ); + } wc_clear_notices(); diff --git a/public/partials/product-bundle-modal.php b/public/partials/product-bundle-modal.php index eed3b01..e856268 100644 --- a/public/partials/product-bundle-modal.php +++ b/public/partials/product-bundle-modal.php @@ -83,7 +83,7 @@