Woocommerce product variation backorder

Question

I have a woocommerce site to fix. I need to allow +7 day delivery if the product is allowed to backorder. On simple product backorder works, but when it has variations backorder, its not working. My woocommerce plugin is updated. Thanks for the help! Here is my code:

function iconic_change_min_delivery_date( $min ) {
    global $variation;
    // The product ID to check for in the cart.
    foreach( WC()->cart->get_cart() as $cart_item ){
    // compatibility with WC +3
    if ( $product->backorders_allowed() ) {
        $product_id = $cart_item['data']->get_id();
    } 
    if ( $variation->backorders_allowed() ) {
    $product_id = $cart_item['data']->get_id();
    } 
}

    // If the product is not in the cart, return the original data.
    if ( ! iconic_is_product_in_cart( $product_id ) ) {
        return $min;
    }

    // Add 4 days.
    $days_to_add = 7;

    // This filter returns an array containing the days to add and a timestamp.
    return array(
        'days_to_add' => $days_to_add,
        'timestamp'   => strtotime( "+" . $days_to_add . " day", current_time( 'timestamp' ) ),
    );
}

add_filter( 'iconic_wds_min_delivery_date', 'iconic_change_min_delivery_date' );

/**
 * Is product in cart?
 *
 * @param $product_id
 *
 * @return bool
 */
function iconic_is_product_in_cart( $product_id ) {
    $product_cart_id = WC()->cart->generate_cart_id( $product_id );
    $in_cart = WC()->cart->find_product_in_cart( $product_cart_id );

    return ! empty( $in_cart );
}
0
Kulcsar Daniel 8 months 2020-12-01T09:10:23-05:00 0 Answers 12 views 0

Leave an answer

Browse
Browse