Я использую плагин WooCommerce PDF Invoices & Packing Slips.
К сожалению, у меня возникла проблема, и я хочу, чтобы при генерации PDF отображалось следующее количество счетов:
€13,00
(incl.
7 % VAT €0,52 ,
19 % VAT €0,80)
Боюсь, что так оно и есть сейчас:
€13,00 (incl. €0,52
7 % VAT, €0,80
19 % VAT)
Как мне сделать так, чтобы это выглядело?
Вы можете мне помочь?Мне это нужно, потому что это законное требование.
У меня уже есть файл: plugins / woocommerce-pdf-invoices-packaging-slips / templates / Simple / invoice.pdf и я нашел место, где отображается общая сумма и налоги:
<td class="no-borders" colspan="2">
<table class="totals">
<tfoot>
<?php foreach( $this->get_woocommerce_totals() as $key => $total ) : ?>
<tr class="<?php echo $key; ?>">
<td class="no-borders"></td>
<th class="description"><?php echo ($total['label'] == 'Gesamt' ? 'Rechnungsbetrag' : $total['label']) ?> </th>
<td class="price"><span class="totals-price"><?php echo $total['value']; ?></span></td>
</tr>
<?php endforeach; ?>
</tfoot>
</table>
</td>
Это как-то связано с функцией "get_woocommerce_totals ()".Я также искал его и нашел файл .plugins / woocommerce-pdf-invoices-packaging-slips / includes / documents / abstract-wcpdf-order-document-method.php
<?php
.
.
.
.
/**
* Return the order totals listing
*/
public function get_woocommerce_totals() {
// get totals and remove the semicolon
$totals = apply_filters( 'wpo_wcpdf_raw_order_totals', $this->order->get_order_item_totals(), $this->order );
// remove the colon for every label
foreach ( $totals as $key => $total ) {
$label = $total['label'];
$colon = strrpos( $label, ':' );
if( $colon !== false ) {
$label = substr_replace( $label, '', $colon, 1 );
}
$totals[$key]['label'] = $label;
}
// WC2.4 fix order_total for refunded orders
// not if this is the actual refund!
if ( ! $this->is_refund( $this->order ) ) {
$total_refunded = method_exists($this->order, 'get_total_refunded') ? $this->order->get_total_refunded() : 0;
if ( version_compare( WOOCOMMERCE_VERSION, '2.4', '>=' ) && isset($totals['order_total']) && $total_refunded ) {
if ( version_compare( WOOCOMMERCE_VERSION, '3.0', '>=' ) ) {
$tax_display = get_option( 'woocommerce_tax_display_cart' );
} else {
$tax_display = WCX_Order::get_prop( $this->order, 'tax_display_cart' );
}
$totals['order_total']['value'] = wc_price( $this->order->get_total(), array( 'currency' => WCX_Order::get_prop( $this->order, 'currency' ) ) );
$order_total = $this->order->get_total();
$tax_string = '';
// Tax for inclusive prices
if ( wc_tax_enabled() && 'incl' == $tax_display ) {
$tax_string_array = array();
if ( 'itemized' == get_option( 'woocommerce_tax_total_display' ) ) {
foreach ( $this->order->get_tax_totals() as $code => $tax ) {
$tax_amount = $tax->formatted_amount;
$tax_string_array[] = sprintf( '%s %s', $tax_amount, $tax->label );
}
} else {
$tax_string_array[] = sprintf( '%s %s', wc_price( $this->order->get_total_tax() - $this->order->get_total_tax_refunded(), array( 'currency' => WCX_Order::get_prop( $this->order, 'currency' ) ) ), WC()->countries->tax_or_vat() );
}
if ( ! empty( $tax_string_array ) ) {
if ( version_compare( WOOCOMMERCE_VERSION, '2.6', '>=' ) ) {
$tax_string = ' ' . sprintf( __( '(includes %s)', 'woocommerce' ), implode( ', ', $tax_string_array ) );
} else {
// use old capitalized string
$tax_string = ' ' . sprintf( __( '(Includes %s)', 'woocommerce' ), implode( ', ', $tax_string_array ) );
}
}
}
$totals['order_total']['value'] .= $tax_string;
}
// remove refund lines (shouldn't be in invoice)
foreach ( $totals as $key => $total ) {
if ( strpos($key, 'refund_') !== false ) {
unset( $totals[$key] );
}
}
}
return apply_filters( 'wpo_wcpdf_woocommerce_totals', $totals, $this->order, $this->get_type() );
}
/**
* Return/show the order subtotal
*/
public function get_order_subtotal( $tax = 'excl', $discount = 'incl' ) { // set $tax to 'incl' to include tax, same for $discount
//$compound = ($discount == 'incl')?true:false;
$subtotal = $this->order->get_subtotal_to_display( false, $tax );
$subtotal = ($pos = strpos($subtotal, ' <small')) ? substr($subtotal, 0, $pos) : $subtotal; //removing the 'excluding tax' text
$subtotal = array (
'label' => __('Subtotal', 'woocommerce-pdf-invoices-packing-slips' ),
'value' => $subtotal,
);
return apply_filters( 'wpo_wcpdf_order_subtotal', $subtotal, $tax, $discount, $this );
}
public function order_subtotal( $tax = 'excl', $discount = 'incl' ) {
$subtotal = $this->get_order_subtotal( $tax, $discount );
echo $subtotal['value'];
}
/**
* Return/show the order shipping costs
*/
public function get_order_shipping( $tax = 'excl' ) { // set $tax to 'incl' to include tax
$shipping_cost = WCX_Order::get_prop( $this->order, 'shipping_total', 'view' );
$shipping_tax = WCX_Order::get_prop( $this->order, 'shipping_tax', 'view' );
if ($tax == 'excl' ) {
$formatted_shipping_cost = $this->format_price( $shipping_cost );
} else {
$formatted_shipping_cost = $this->format_price( $shipping_cost + $shipping_tax );
}
$shipping = array (
'label' => __('Shipping', 'woocommerce-pdf-invoices-packing-slips' ),
'value' => $formatted_shipping_cost,
'tax' => $this->format_price( $shipping_tax ),
);
return apply_filters( 'wpo_wcpdf_order_shipping', $shipping, $tax, $this );
}
public function order_shipping( $tax = 'excl' ) {
$shipping = $this->get_order_shipping( $tax );
echo $shipping['value'];
}
/**
* Return/show the total discount
*/
public function get_order_discount( $type = 'total', $tax = 'incl' ) {
if ( $tax == 'incl' ) {
switch ($type) {
case 'cart':
// Cart Discount - pre-tax discounts. (deprecated in WC2.3)
$discount_value = $this->order->get_cart_discount();
break;
case 'order':
// Order Discount - post-tax discounts. (deprecated in WC2.3)
$discount_value = $this->order->get_order_discount();
break;
case 'total':
// Total Discount
if ( version_compare( WOOCOMMERCE_VERSION, '2.3' ) >= 0 ) {
$discount_value = $this->order->get_total_discount( false ); // $ex_tax = false
} else {
// WC2.2 and older: recalculate to include tax
$discount_value = 0;
$items = $this->order->get_items();;
if( sizeof( $items ) > 0 ) {
foreach( $items as $item ) {
$discount_value += ($item['line_subtotal'] + $item['line_subtotal_tax']) - ($item['line_total'] + $item['line_tax']);
}
}
}
break;
default:
// Total Discount - Cart & Order Discounts combined
$discount_value = $this->order->get_total_discount();
break;
}
} else { // calculate discount excluding tax
if ( version_compare( WOOCOMMERCE_VERSION, '2.3' ) >= 0 ) {
$discount_value = $this->order->get_total_discount( true ); // $ex_tax = true
} else {
// WC2.2 and older: recalculate to exclude tax
$discount_value = 0;
$items = $this->order->get_items();;
if( sizeof( $items ) > 0 ) {
foreach( $items as $item ) {
$discount_value += ($item['line_subtotal'] - $item['line_total']);
}
}
}
}
$discount = array (
'label' => __('Discount', 'woocommerce-pdf-invoices-packing-slips' ),
'value' => $this->format_price( $discount_value ),
'raw_value' => $discount_value,
);
if ( round( $discount_value, 3 ) != 0 ) {
return apply_filters( 'wpo_wcpdf_order_discount', $discount, $type, $tax, $this );
}
}
public function order_discount( $type = 'total', $tax = 'incl' ) {
$discount = $this->get_order_discount( $type, $tax );
echo $discount['value'];
}
/**
* Return the order fees
*/
public function get_order_fees( $tax = 'excl' ) {
if ( $_fees = $this->order->get_fees() ) {
foreach( $_fees as $id => $fee ) {
if ($tax == 'excl' ) {
$fee_price = $this->format_price( $fee['line_total'] );
} else {
$fee_price = $this->format_price( $fee['line_total'] + $fee['line_tax'] );
}
$fees[ $id ] = array(
'label' => $fee['name'],
'value' => $fee_price,
'line_total' => $this->format_price( $fee['line_total'] ),
'line_tax' => $this->format_price( $fee['line_tax'] )
);
}
return $fees;
}
}
/**
* Return the order taxes
*/
public function get_order_taxes() {
$tax_label = __( 'VAT', 'woocommerce-pdf-invoices-packing-slips' ); // register alternate label translation
$tax_label = __( 'Tax rate', 'woocommerce-pdf-invoices-packing-slips' );
$tax_rate_ids = $this->get_tax_rate_ids();
if ( $order_taxes = $this->order->get_taxes() ) {
foreach ( $order_taxes as $key => $tax ) {
if ( WCX::is_wc_version_gte_3_0() ) {
$taxes[ $key ] = array(
'label' => $tax->get_label(),
'value' => $this->format_price( $tax->get_tax_total() + $tax->get_shipping_tax_total() ),
'rate_id' => $tax->get_rate_id(),
'tax_amount' => $tax->get_tax_total(),
'shipping_tax_amount' => $tax->get_shipping_tax_total(),
'rate' => isset( $tax_rate_ids[ $tax->get_rate_id() ] ) ? ( (float) $tax_rate_ids[$tax->get_rate_id()]['tax_rate'] ) . ' %': '',
);
} else {
$taxes[ $key ] = array(
'label' => isset( $tax[ 'label' ] ) ? $tax[ 'label' ] : $tax[ 'name' ],
'value' => $this->format_price( ( $tax[ 'tax_amount' ] + $tax[ 'shipping_tax_amount' ] ) ),
'rate_id' => $tax['rate_id'],
'tax_amount' => $tax['tax_amount'],
'shipping_tax_amount' => $tax['shipping_tax_amount'],
'rate' => isset( $tax_rate_ids[ $tax['rate_id'] ] ) ? ( (float) $tax_rate_ids[$tax['rate_id']]['tax_rate'] ) . ' %': '',
);
}
}
return apply_filters( 'wpo_wcpdf_order_taxes', $taxes, $this );
}
}
/**
* Return/show the order grand total
*/
public function get_order_grand_total( $tax = 'incl' ) {
if ( version_compare( WOOCOMMERCE_VERSION, '2.1' ) >= 0 ) {
// WC 2.1 or newer is used
$total_unformatted = $this->order->get_total();
} else {
// Backwards compatibility
$total_unformatted = $this->order->get_order_total();
}
if ($tax == 'excl' ) {
$total = $this->format_price( $total_unformatted - $this->order->get_total_tax() );
$label = __( 'Total ex. VAT', 'woocommerce-pdf-invoices-packing-slips' );
} else {
$total = $this->format_price( ( $total_unformatted ) );
$label = __( 'Total', 'woocommerce-pdf-invoices-packing-slips' );
}
$grand_total = array(
'label' => $label,
'value' => $total,
);
return apply_filters( 'wpo_wcpdf_order_grand_total', $grand_total, $tax, $this );
}
public function order_grand_total( $tax = 'incl' ) {
$grand_total = $this->get_order_grand_total( $tax );
echo $grand_total['value'];
}
.
.
.
.
Я попытался проанализировать все это, и я думаю, что используется ФИЛЬТР, который снова приводит к чему-то другому:
return apply_filters( 'wpo_wcpdf_woocommerce_totals', $totals, $this->order, $this->get_type() );
но я не нашел, где найти wpo_wcpdf_woocommerce_totals здесь и где я могу что-то изменить.я уже связался со службой поддержки, но они хотят продать мне свой премиум-шаблон.
Кто-нибудь может мне помочь?