PHP code to get the date of 10th day from today in the addon field

PHP code to get the date of 10th day from today in the addon field

Please use the below php function code to get the date of 10th day from today in the addon field 


function getDateAfter($days=10)
{


    $formatted_date = new DateTime();
    $date_timestamp = $formatted_date->getTimestamp();
    // loop for X days
    for ($i = 0; $i < ($days - 1); $i++) {
        // get what day it is next day
        $nextDay = date('w'strtotime('+1day'$date_timestamp));
        // if it's Sunday or Saturday get $i-1
        if ($nextDay == 0 || ($nextDay == 6)) {
            $i--;
        }
        // modify timestamp, add 1 day
        $date_timestamp = strtotime('+1day'$date_timestamp);
    }

    $formatted_date->setTimestamp($date_timestamp);
    return $formatted_date->format(get_option('date_format'));

}
add_filter('wcpa_product_form_fields'function ($data, $product_id) {
    // modify data from here
    foreach ($data as $k => $v) {
        if ($v->name == 'text-1595838503027') { // change this name with your field name
            $v->value = getDateAfter(10);
        }
        
    }
    return $data;
}, 102);

    • Related Articles

    • How to export order with Addon field values ?

      You need to instal  Advanced Order Export For WooCommerce. https://wordpress.org/plugins/woo-order-export-lite/ Using the above plugin you can export any custom field assigned to orders/products/coupons is easy and you can select from various formats ...
    • To Access WCPA Custom field value from Cart Object

      You can access the data from woocommmerce cart object. Below an example code which takes a particular custom field value  global $woocommerce; $items = $woocommerce->cart->get_cart(); if (isset($cart['wcpa_data']) && is_array($cart['wcpa_data'])) {   ...
    • How to resolve Issue with saving Addon fields?

      The Addon fields saving issue is mainly due to following reasons:- Check you have polylang plugin https://wordpress.org/plugins/polylang/ installed and kept  unconfigured without selecting the languages .The above issue may occur if you have ...
    • Basic Setup Instructions

      Instructions regarding Installation and activation, please visit: Installation & Activation Now let's checkout how to deal with WooCommerce Custom Product Addon. Product forms are the basic building block of our plugin. Let's get started with make ...
    • Styling Custom Product Addons

      The form fields in WCPA are easily customizable by styling it using CSS. There are numerous classes to style the fields in a form. You will be able to change the color, background, appearance and so on with using CSS and the concerned classes of the ...