admin5916
Forum Replies Created
-
Here is the solution :
// Add discount for local pickup
add_action( ‘woocommerce_cart_calculate_fees’, ‘custom_discount_for_pickup_shipping_method’, 10, 1 );
// Add discount for local pickup
function custom_discount_for_pickup_shipping_method( $cart ) {
if ( is_admin() && ! defined( ‘DOING_AJAX’ ) )
return;$addons_price_before_calc = 0;
if( $cart ){
foreach( $cart->get_cart() as $cart_values ){
$product = wc_get_product( $cart_values[‘product_id’] );
if( $product ){
$row_price = wc_get_price_excluding_tax( $product, array( ‘qty’ => $cart_values[‘quantity’]) );
$addons_price_before_calc = $addons_price_before_calc + $row_price;
}
}
}$percentage = 7; // <=== Discount percentage
$chosen_shipping_method_id = WC()->session->get( ‘chosen_shipping_methods’ )[0];
$chosen_shipping_method = explode(‘:’, $chosen_shipping_method_id)[0];// Only for Local pickup chosen shipping method
if ( strpos( $chosen_shipping_method_id, ‘local_pickup’ ) !== false ) {
// Calculate the discount
if( $addons_price_before_calc )
$discount = $addons_price_before_calc * $percentage / 100;
else
$discount = $cart->get_subtotal() * $percentage / 100;
// Add the discount
$cart->add_fee( __(‘Offre Drive’) . ‘ (-‘ . $percentage . ‘% sauf consignes)’, -$discount );
}
}Forum: Plugins
In reply to: [Quick View WooCommerce] How to translate the lightbox cardI have the premium version.
Hi,
You’re my savior, it works perfectly now !!! ??
Many thanks,
Anna
Pleaaaaaase ??????
Is anyone there ?