Friday, November 25, 2022
HomeWordPress Developmentphp - woocommerce block supply date primarily based on single product

php – woocommerce block supply date primarily based on single product


I would like to dam out a supply date on my transport calendar, if a sure product is chosen. E.g if we won’t ship sunflowers on the tenth Dec for some purpose and the shopper has added sunflowers to the cart, once they get to the checkout web page, the tenth Dec needs to be blocked out as unavailable.

I’ve discovered the next code, however I do not know methods to change it from product classes to single product ids.. and in addition to have the ability to particular the date I need blocked. Can anybody assist with this please

add_action( 'woocommerce_after_checkout_form', 'add_checkout_script' );
perform add_checkout_script() {
    // HERE outline your product classes within the array (Ids, slugs or names)
    $classes = array( 't-shirts', 'sweet-shirts' );

    $product_id = $cart_item['product_id'];
    $discovered = false;

    // Loop by means of cart objects to search out out particular product classes
    foreach( WC()->cart->get_cart() as $cart_item )
        if( has_term( $classes, 'product_cat', $product_id ) ) {
            $discovered = true;
            break;
        }

    // If product classes aren't present in cart objects, we exit
    if ( ! $discovered ) return

    ?>
    <script>
        jQuery(perform($) {
            var disableddates = ["14-02-2018", "25-12-2018"];

            perform DisableSpecificDates(date) {
                var string = $.datepicker.formatDate("dd-mm-yy", date);
                return [disableddates.indexOf(string) == -1];
            }

            $("#billing_delivery_date").datepicker({
                dateFormat: "DD, d MM, yy",
                beforeShowDay: DisableSpecificDates,
                minDate: new Date()
            });
        });
    </script>
    <?php    
}

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

- Advertisment -
Google search engine

Most Popular

Recent Comments