FOX - Currency Switcher for WooCommerce

Cómo hacer que woocommerce-pdf-invoice funcione con WOOCS

El plugin woocommerce-pdf-invoice te permite imprimir facturas en formato PDF. Pero hay un problema: no hay filtros ni acciones para que funcione correctamente con WOOCS. Así que decidí investigar este tema y resolver esta tarea modificando el código del plugin woocommerce-pdf-invoice. Puedes hacer lo mismo si deseas usar woocommerce-pdf-invoice con WOOCS.
  1. Ve a plugins/woocommerce-pdf-invoice/includes/woo-pdf-invoice.class.php
  2. Necesitamos hacer cambios en 8 lugares del archivo woo-pdf-invoice.class.php
  3. Encuentra la función total y cambia el código por el siguiente:
    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;
                }
            }
  4. Obtendrás algo como esto: How to make woocommerce-pdf-invoice works with WOOCS
  5. Luego encuentra la función row_total e inserta el siguiente código allí como en la pantalla: How to make woocommerce-pdf-invoice works with WOOCS
    if(class_exists('WOOCS')) {
                    $line_subtotal = WOOCS::normalize_order_data($this->orderData->id, $line_subtotal);
                }
  6. Luego encuentra la función item_price y reemplaza el código por este como en la pantalla: How to make woocommerce-pdf-invoice works with WOOCS
    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;
                    }
                }
  7. Luego encuentra la función get_totals y reemplaza el siguiente código como en la pantalla: How to make woocommerce-pdf-invoice works with WOOCS
    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,
                    );
                }
  8. En la misma función encuentra la cadena //Display taxes below total only if subtotal is displayed including taxes e inserta el siguiente código: How to make woocommerce-pdf-invoice works with WOOCS
    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,
                    );
                }
  9. Encuentra la función render_left_block y reemplaza el siguiente código: How to make woocommerce-pdf-invoice works with WOOCS
    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),
                        ),
                    );
                }
  10. Ve a la función amount_in_words y reemplaza el siguiente código: How to make woocommerce-pdf-invoice works with WOOCS
     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');
                    }
                 }
  ¡Eso es todo!