Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Sample functions for specific date filters in Order Delivery Date Pro plugin
<?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
You can’t perform that action at this time.