Browse Source

Permite combos sem cupons.

master
Guilherme Capanema 6 years ago
parent
commit
32a5d40acd
3 changed files with 17 additions and 12 deletions
  1. +1
    -1
      admin/class-wc-cdp-admin.php
  2. +12
    -9
      public/class-wc-cdp-public.php
  3. +4
    -2
      public/partials/product-bundle-modal.php

+ 1
- 1
admin/class-wc-cdp-admin.php View File

@ -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'] );
}


+ 12
- 9
public/class-wc-cdp-public.php View File

@ -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();


+ 4
- 2
public/partials/product-bundle-modal.php View File

@ -83,7 +83,7 @@
</div>
<div class="<?php echo apply_filters( 'wc_cdp_bundle_amount_class', 'wc_cdp_bundle_amount' ); ?>">
<?php if ($bundle_discount_price): ?>
<?php if ($bundle_coupon): ?>
<del>
<?php echo wc_price($bundle_regular_price); ?>
</del>
@ -100,7 +100,9 @@
<input type="hidden" name="action" value="wc_cdp_add_to_cart" />
<input type="hidden" name="wc_cdp_bundle_coupon" value="<?php echo $bundle_coupon->get_code(); ?>" />
<?php if ($bundle_coupon): ?>
<input type="hidden" name="wc_cdp_bundle_coupon" value="<?php echo $bundle_coupon->get_code(); ?>" />
<?php endif; ?>
<button type="submit" class="<?php echo apply_filters( 'wc_cdp_add_to_cart_button_class', 'button wc-forward alt wc_cdp_add_to_cart_button' ); ?>">
<?php echo apply_filters( 'wc_cdp_add_to_cart_text', get_option( 'wc_cdp_add_to_cart_text' ) ); ?>


Loading…
Cancel
Save