Bonus System
-
Good afternoon, everyone!
I would like to develop a bonus form for ecommerce, I researched in several places and I did not find anything similar.
It seems like all woocommerce works this way:
Example: The customer makes the purchase and earns a 3% discount on the total value of the order:$100.00 (total)
– $3.00 (discount 3%)
= $97.00 (Amount to pay)I would like to do otherwise: Turn the discount into Bonus.
I added another line via a function with + 3% and I hid in the CSS the negative value of the discount:$100.00 (total)
-$3.00 (I Hid On CSS)
+ $3.00 (Bonus)
———–
= $100.00 (Total)Anyway, Is there any way to turn this $ 3.00(bonus) as credit for the next purchase automatically?
Example:
1o purchase: Done in the amount of $100.00;
Next purchase (2o): Holds $ 3.00 as a bonus.My function for the bonus
/** * function bonus */ add_action( 'woocommerce_cart_calculate_fees','woocommerce_custom_surcharge' ); function woocommerce_custom_surcharge() { global $woocommerce; if ( is_admin() && ! defined( 'DOING_AJAX' ) ) return; foreach ( $woocommerce->cart->get_cart() as $cart_item_key => $values) { $_product = $values['data']; if ( $_product->is_on_sale() ) { $discount = ($_product->regular_price - $_product->sale_price) * $values['quantity']; $discount_total += $discount; } } $surcharge = $discount_total + $woocommerce->cart->discount_cart; $woocommerce->cart->add_fee( 'Total de B?nus', $surcharge, true, '' ); }
Thank you!
- The topic ‘Bonus System’ is closed to new replies.