How to make woocommerce-pdf-invoice works with WOOCS
The plugin woocommerce-pdf-invoice allows you print invoices in pdf format. But one thing – no filters and actions to make it works fine with the WOOCS. So I decided investigate this question and resilve this tasks by hacking woocommerce-pdf-invoice plugin code. You can do the same if you are want use woocommerce-pdf-invoice with WOOCS.
- Go to plugins/woocommerce-pdf-invoice/includes/woo-pdf-invoice.class.php
- We need make changes in 8 places in file woo-pdf-invoice.class.php
- Finf function total and change code on next:
public function total() { if(class_exists('WOOCS')) { return (double) WOOCS::normalize_order_data($this->orderData->id, $this->orderData->order_total); } else { return (double) $this->orderData->order_total; } }
- You will get something like this:
- Then find function row_total and insert next code there as on screen:
if(class_exists('WOOCS')) { $line_subtotal = WOOCS::normalize_order_data($this->orderData->id, $line_subtotal); }
- Then find function item_price and replace code by this as on screen:
if((((double) $price) * (int) $item['qty']) == (double) $this->row_total($item, $this->orderData)) { if(class_exists('WOOCS')) { return WOOCS::normalize_order_data($this->orderData->id, $price); } else { return $price; } } else { if(class_exists('WOOCS')) { return WOOCS::normalize_order_data($this->orderData->id, $price); } else { return $price; } }
- Then find function get_totals and replace next code as on screen:
if(class_exists('WOOCS')) { $totals['subtotal'] = array( 'name'=>$this->invoiceOptions['woo_pdf_title_subtotal'], 'value'=>(double) WOOCS::normalize_order_data($this->orderData->id, $subtotal), ); } else { $totals['subtotal'] = array( 'name'=>$this->invoiceOptions['woo_pdf_title_subtotal'], 'value'=>(double) $subtotal, ); }
- In the same function find string //Display taxes below total only if subtotal is displayed including taxes and insert next code:
if(class_exists('WOOCS')) { $totals['total'] = array( 'name'=>$this->invoiceOptions['woo_pdf_title_total'], 'value'=>(double) WOOCS::normalize_order_data($this->orderData->id, $this->orderData->order_total), ); } else { $totals['total'] = array( 'name'=>$this->invoiceOptions['woo_pdf_title_total'], 'value'=>(double) $this->orderData->order_total, ); }
- Find function render_left_block and replace next code:
if(class_exists('WOOCS')) { $blocks = array( 'amount_in_words'=>array( 'title'=>$this->invoiceOptions['woo_pdf_title_amount_in_words'], 'text'=>$this->get_amount_in_words((double)WOOCS::normalize_order_data($this->orderData->id, $this->orderData->order_total), $this->invoiceOptions), ), ); } else { $blocks = array( 'amount_in_words'=>array( 'title'=>$this->invoiceOptions['woo_pdf_title_amount_in_words'], 'text'=>$this->get_amount_in_words((double) $this->orderData->order_total, $this->invoiceOptions), ), ); }
- Go to function amount_in_words and replace next code:
if(class_exists('WOOCS')) { $currency = get_post_meta($this->orderData->id, '_woocs_order_currency', TRUE); if(!$self) { $string .= ' '; $string .= $currency; } }else{ if(!$self) { $string .= ' '; $string .= _n('dollar', 'dollars', $number, 'woo_pdf'); } }
That is all!