Created
March 30, 2019 09:49
-
-
Save ashokrane/e5d126ecba895c68d4ba0dbbe2d4e2bd to your computer and use it in GitHub Desktop.
Sample functions for specific date filters in Order Delivery Date Pro plugin
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
add_filter( 'orddd_global_specific_delivery_dates', 'ts_add_global_specific_delivery_charges_by_variations', 10, 4 ); | |
function ts_add_global_specific_delivery_charges_by_variations( $specific_fees, $specific_date, $specific_date_charges, $specific_charges_label ) { | |
global $woocommerce; | |
$found = false; | |
// determine if selected variation is in cart or not | |
foreach ( $woocommerce->cart->get_cart() as $cart_item_key => $cart_item) { | |
if ( $cart_item['variation_id'] == 447 || | |
$cart_item['variation_id'] == 448 ) { | |
$qty = $qty + $cart_item['quantity']; | |
$found = true; | |
} | |
} | |
if( $found == true ) { | |
$specific_date_charges = $specific_date_charges * $qty; | |
$specific_charges_label = 'Special item'; | |
$specific_fees = "Yes"; | |
} else { | |
$specific_fees = 'No'; | |
$specific_date_charges = 0; | |
} | |
return array( 'specific_fees' => $specific_fees, | |
'specific_day_charges' => $specific_date_charges, | |
'specific_charges_label' => $specific_charges_label ); | |
} | |
add_filter( 'orddd_custom_specific_delivery_dates', 'ts_add_specific_delivery_charges_by_variations', 10, 4 ); | |
function ts_add_specific_delivery_charges_by_variations( $specific_fees, $specific_date, $specific_date_charges, $specific_charges_label ) { | |
global $woocommerce; | |
$found = false; | |
// determine if selected variation is in cart or not | |
foreach ( $woocommerce->cart->get_cart() as $cart_item_key => $cart_item) { | |
if ( $cart_item['variation_id'] == 447 || | |
$cart_item['variation_id'] == 448 ) { | |
$qty = $qty + $cart_item['quantity']; | |
$found = true; | |
} | |
} | |
if( $found == true ) { | |
$specific_date_charges = $specific_date_charges * $qty; | |
$specific_charges_label = 'Special charges for your items'; | |
$specific_fees = "Yes"; | |
} else { | |
$specific_fees = 'No'; | |
$specific_date_charges = 0; | |
} | |
return array( 'specific_fees' => $specific_fees, | |
'specific_day_charges' => $specific_date_charges, | |
'specific_charges_label' => $specific_charges_label ); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment