• Resolved alexthomson1994

    (@alexthomson1994)


    Hi,

    I’m using a plugin which is currently getting the order date from woocommerce however, I need this to use today’s date rather than getting it from the order date.

    See a few bits of code that I feel may be responsible/need changing.

    If anyone could help out here it would be really appreciated.

    `
    /**
    * @var string
    */
    private $date = ”;

    /**
    * Construct
    *
    * @param WC_XR_Settings $settings
    * @param WC_XR_Contact $contact
    * @param string $date

    public function __construct( $settings, $contact, $date, $due_date, $invoice_number, $line_items, $currency_code, $total_tax, $total ) {
    $this->settings = $settings;
    $this->contact = $contact;
    $this->date = $date;

    /**
    * @return string
    */
    public function get_date() {
    return apply_filters( ‘woocommerce_xero_invoice_date’, $this->date, $this );
    }

    /**
    * @param string $date
    */
    public function set_date( $date ) {
    $this->date = $date;
    }

    */
    public function get_invoice_by_order( $order ) {

    $old_wc = version_compare( WC_VERSION, ‘3.0’, ‘<‘ );

    $order_date = $old_wc ? $order->order_date : $order->get_date_created()->date( ‘Y-m-d H:i:s’ );
    $date_parts = explode( ‘ ‘, $order_date );
    $order_ymd = $date_parts[0];

    • This topic was modified 7 years, 4 months ago by Jan Dembowski.
Viewing 2 replies - 1 through 2 (of 2 total)
  • Ewout

    (@pomegranate)

    Hello Alex,
    Judging from this code, it looks like you should be able to get this to show todays date rather than the invoice date by utilizing that woocommerce_xero_invoice_date filter:

    
    add_filter( 'woocommerce_xero_invoice_date', 'woocommerce_xero_invoice_date_today', 10, 2 );
    function woocommerce_xero_invoice_date_today($date,$invoice){
    	return date_i18n('Y-m-d');
    }
    

    Hope that helps!
    Ewout

    Thread Starter alexthomson1994

    (@alexthomson1994)

    Thanks Ewout,

    That works perfectly. Unfortunately the due date still populated as the order date however, learning from your reply I integrated a second snippet – which also works perfectly. You’ve been a great help.

    add_filter( ‘woocommerce_xero_invoice_due_date’, ‘woocommerce_xero_invoice_due_date_month’, 10, 2 );
    function woocommerce_xero_invoice_due_date_month($due_date){
    return date_i18n(‘Y-m-d’, strtotime(“+30 days”));
    }

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Forcing today’s date’ is closed to new replies.