Php 在Woocommerce Thankyu页面和电子邮件的订单总数中添加新行
我对在电子邮件和感谢页面中添加行的代码有问题Php 在Woocommerce Thankyu页面和电子邮件的订单总数中添加新行,php,wordpress,woocommerce,hook-woocommerce,orders,Php,Wordpress,Woocommerce,Hook Woocommerce,Orders,我对在电子邮件和感谢页面中添加行的代码有问题 add_filter( 'woocommerce_get_order_item_totals', 'bbloomer_add_recurring_row_email', 10, 2 ); function bbloomer_add_recurring_row_email( $total_rows, $myorder_obj ) { $total_rows['recurr_not'] = array( 'label' =>
add_filter( 'woocommerce_get_order_item_totals', 'bbloomer_add_recurring_row_email', 10, 2 );
function bbloomer_add_recurring_row_email( $total_rows, $myorder_obj ) {
$total_rows['recurr_not'] = array(
'label' => __( 'Rec:', 'woocommerce' ),
'value' => 'blabla'
);
return $total_rows;
}
我有一个在购物车中添加“不含增值税总额”行的功能:
<?php
global $woocommerce;
$frais = 1.01;
echo '<tr class ="totalht">
<th>'. __( 'Total HT', 'woocommerce' ) .'</th>
<td data-title=" '. __( 'Total HT', 'woocommerce' ) .' ">'
. wc_price( ( $woocommerce->cart->cart_contents_total * $frais ) + $woocommerce->cart->shipping_total ) .'<span class="ht-panier">HT</span></td>
</tr>';
?>
它不起作用了但它在起作用
有人可以向我解释为什么它在电子邮件上工作,但在“感谢页面”中不工作?更新:由于此挂钩用于订单数据,但不用于购物车数据,您应该尝试此操作,我在最后一行之前设置了附加行:
add_filter( 'woocommerce_get_order_item_totals', 'add_custom_order_totals_row', 30, 3 );
function add_custom_order_totals_row( $total_rows, $order, $tax_display ) {
$costs = 1.01;
// Set last total row in a variable and remove it.
$gran_total = $total_rows['order_total'];
unset( $total_rows['order_total'] );
// Insert a new row
$total_rows['recurr_not'] = array(
'label' => __( 'Total HT :', 'woocommerce' ),
'value' => wc_price( ( $order->get_total() - $order->get_total_tax() ) * $costs ),
);
// Set back last total row
$total_rows['order_total'] = $gran_total;
return $total_rows;
}
代码进入活动子主题(或活动主题)的function.php文件经过测试并正常工作
对于购物车,您应该使用它(因为不再需要
global$woocommerce;
):
@ArthurM Ok这只是一个小小的打字错误,请再试一次。@ArthurM刚刚进行了另一次更新,使“Total HT”出现在最后一行“Total”之前……试试看。它起作用了。
add_filter( 'woocommerce_get_order_item_totals', 'add_custom_order_totals_row', 30, 3 );
function add_custom_order_totals_row( $total_rows, $order, $tax_display ) {
$costs = 1.01;
// Set last total row in a variable and remove it.
$gran_total = $total_rows['order_total'];
unset( $total_rows['order_total'] );
// Insert a new row
$total_rows['recurr_not'] = array(
'label' => __( 'Total HT :', 'woocommerce' ),
'value' => wc_price( ( $order->get_total() - $order->get_total_tax() ) * $costs ),
);
// Set back last total row
$total_rows['order_total'] = $gran_total;
return $total_rows;
}
<?php
$costs = 1.01;
echo '<tr class ="totalht">
<th>'. __( 'Total HT', 'woocommerce' ) .'</th>
<td data-title=" '. __( 'Total HT', 'woocommerce' ) .' ">'
. wc_price( ( WC()->cart->cart_contents_total * $costs ) + WC()->cart->shipping_total ) .'<span class="ht-panier">HT</span></td>
</tr>';
?>