Woocommerce deposits en coupons

Pagina: 1
Acties:

Onderwerpen

Vraag


Acties:
  • 0 Henk 'm!

Verwijderd

Topicstarter
Mijn vraag

Ik heb een woocommerce website waarmee tours geboekt kunnen worden in Koh Samui, Thailand. Deze draait op Woocommerce bookings, Woocommerce Deposits en nog een aantal andere minder relevante plugins. Nu is de standaard functionaliteit van Woocommerce dat een discount coupon een bedrag van het totaalbedrag afhaalt. In mijn geval is de situatie zo:

Tour kost €50 per persoon, waarvan €10 als aanbetaling geldt om de boeking te garanderen. Dat betekent dat er €40 overblijft, wat cash betaald kan worden.

Nu heb ik ook een kortingscode, van bijvoorbeeld €5. Wanneer die wordt ingevuld bij het afrekenen, gaat het bedrag echter van de €40 af, niet van de aanbetaling. Dat moet ik precies andersom hebben. Support van de kant van Woocommerce is erg traag dus ik probeer het even hier.

Relevante software en hardware die ik gebruik
Wordpress, Woocommerce, Woocommerce bookings, Woocommerce deposits

Wat ik al gevonden of geprobeerd heb

In php ziet de cart berekening er zo uit:

<tr class="order-total">
<th><?php _e( 'Due Today', 'woocommerce-deposits' ); ?></th>
<td><?php wc_cart_totals_order_total_html(); ?></td>
</tr>
<?php
if ( $deferred_discount_amount > 0 ) {
?>
<tr class="order-total">
<th><?php _e( 'Discount Applied Toward Future Payments', 'woocommerce-deposits' ); ?></th>
<td><?php echo wc_price( -$deferred_discount_amount ); ?></td>
</tr>
<?php
}
?>
<tr class="order-total">
<th><?php _e( 'Pay on tour', 'woocommerce-deposits' ); ?></th>
<td><?php echo wc_price( $future_payment_amount ); ?><?php echo $tax_element; ?></td>
</tr><?php
}

Ik heb alleen geen idee wat ik moet aanpassen om de kortingscode van toepassing te laten zijn op de aanbetaling. Iemand hier die dat wel weet?

Alle reacties


Acties:
  • 0 Henk 'm!

Verwijderd

Da's de weergave van de resultaten, niet de berekening zelf... ;)

Acties:
  • 0 Henk 'm!

Verwijderd

Topicstarter
Dat dacht ik al. Ik kom er niet uit, maar es wat externe hulp inroepen dus.

Acties:
  • 0 Henk 'm!

Verwijderd

Topicstarter
Update: heb de juiste code gevonden (For products with fixed deposits, defer the entire fixed discount). Is dit iets dat ik zelf kan aanpassen en wat zou ik ervoor moeten doen om ervoor te zorgen dat de fixed discount niet ' deferred' wordt?

public function get_discount_amount( $discount, $discounting_amount, $cart_item, $single, $coupon ) {
if ( ! empty( $cart_item['is_deposit'] ) ) {
$old_wc = version_compare( WC_VERSION, '3.0', '<' );
$coupon_type = $old_wc ? $coupon->type : $coupon->get_discount_type(); // fixed_cart or fixed_product or percent or percent_product
$coupon_id = $old_wc ? $coupon->id : $coupon->get_id();

$deposit_type = WC_Deposits_Product_Manager::get_deposit_type( $cart_item['product_id'] ); // fixed or percent or plan

// Initialize default condition
$present_discount_amount = floatval( $discount );
$deferred_discount_amount = 0.0;

// For fixed coupons (fixed_cart or fixed_product)
// For products with payment plans, discount a proportional amount of the fixed discount now, the rest defer for later
// For products with fixed deposits, defer the entire fixed discount
// For products with percentage based deposits, defer the entire fixed discount
if ( in_array( $coupon_type, array( 'fixed_cart', 'fixed_product' ) ) ) {
if ( 'plan' === $deposit_type ) {
$full_amount = floatval( $cart_item['full_amount'] );
$deposit_amount = floatval( $cart_item['deposit_amount'] );
// Calculate proportion due now, avoiding (unlikely) division by zero
if ( $full_amount > 0 ) {
$present_proportion = $deposit_amount / $full_amount;
} else {
$present_proportion = 1.0;
}
// Present discount amount is always for quantity 1
$present_discount_amount = round( $discount * $present_proportion, 2 );
// Deferred discount amount is always for the line quantity
$deferred_discount_amount = round( $discount * $cart_item['quantity'] * ( 1 - $present_proportion ), 2 );
} else if ( in_array( $deposit_type, array( 'percent', 'fixed' ) ) ) {
$present_discount_amount = 0;
$deferred_discount_amount = round( $discount * $cart_item['quantity'], 2 ); // total for (line) quantity, not just unit
}
}

// For percentage based coupons (percent or percent_product)
// For products with payment plans, pass through the provided discount AND scale and defer it for later
// For products with fixed deposits, defer the entire discount
// For products with percentage based deposits, pass through the provided discount AND scale and defer it for later
if ( in_array( $coupon_type, array( 'percent', 'percent_product' ) ) ) {
$full_amount = floatval( $cart_item['full_amount'] );
$deposit_amount = floatval( $cart_item['deposit_amount'] );
if ( in_array( $deposit_type, array( 'plan', 'percent' ) ) ) {
// Applies discount toward future amounts to ensure complete discount is not lost
if ( $deposit_amount > 0 ) {
$deferred_scaler = ( $full_amount - $deposit_amount ) / $deposit_amount;
$deferred_discount_amount = round( $discount * $cart_item['quantity'] * $deferred_scaler, 2 );
}
} else if( 'fixed' === $deposit_type ) {
// First, zero the present discount
$present_discount_amount = 0;
// Then scale and defer the entire discount
if ( $deposit_amount > 0 ) {
$deferred_scaler = $full_amount / $deposit_amount;
$deferred_discount_amount = round( $discount * $cart_item['quantity'] * $deferred_scaler, 2 );
}
}
}

if ( $deferred_discount_amount > 0 ) {
// Save the discount to be applied toward the future amount due
$search_key = WC()->cart->generate_cart_id( $cart_item['product_id'], $cart_item['variation_id'], $cart_item['variation'] );
$deferred_discounts = WC()->session->get( 'deposits_deferred_discounts', array() );
$deferred_discounts[ $search_key ][ $coupon_id ] = $deferred_discount_amount;
WC()->session->set( 'deposits_deferred_discounts', $deferred_discounts );
}

// Return the discount to be applied now
return $present_discount_amount;
}

// Otherwise, just pass through the original amount
return $discount;
}

/**
* Calculates the sum of all deferred discounts in the cart for all items
* Totals are for (line) quantity, not just unit
*
* @since 1.2.0
*
* @return float
*/
public static function get_deferred_discount_amount() {
$deferred_discount_amount = 0;
$deferred_discounts = WC()->session->get( 'deposits_deferred_discounts', array() );
foreach( $deferred_discounts as $item_key => $item_discounts ) {
foreach( $item_discounts as $coupon_id => $discount ) {
$deferred_discount_amount += $discount;
}
}
return $deferred_discount_amount;
}

Acties:
  • 0 Henk 'm!

  • DJMaze
  • Registratie: Juni 2002
  • Niet online
Verwijderd schreef op vrijdag 7 juli 2017 @ 12:17:
Nu heb ik ook een kortingscode, van bijvoorbeeld €5. Wanneer die wordt ingevuld bij het afrekenen, gaat het bedrag echter van de €40 af, niet van de aanbetaling. Dat moet ik precies andersom hebben.
Waarom zou je dat andersom willen hebben?
Wat maakt het uit dat ze eerst €5 en later €40, of eerst €10 en later €35 betalen?
In beide gevallen is het gewoon €50 minus €5 korting.

Maak je niet druk, dat doet de compressor maar


Acties:
  • 0 Henk 'm!

Verwijderd

Topicstarter
DJMaze schreef op zaterdag 8 juli 2017 @ 10:58:
[...]

Waarom zou je dat andersom willen hebben?
Wat maakt het uit dat ze eerst €5 en later €40, of eerst €10 en later €35 betalen?
In beide gevallen is het gewoon €50 minus €5 korting.
Omdat ze de aanbetaling bij mij doen en het resterende bedrag rechtstreeks aan de tour operator, cash.

Acties:
  • 0 Henk 'm!

Verwijderd

Verwijderd schreef op zaterdag 8 juli 2017 @ 10:22:
Is dit iets dat ik zelf kan aanpassen...
Misschien, maar als je niet weet wat je doet zou ik er niet aan beginnen. Zoek gewoon iemand met WooCommerce ervaring, en betaal die een paar tientjes om het voor je te regelen!
Pagina: 1