我想将“折扣:”字段移到订单详细信息中的运输字段下方。我也希望这也能反映在 woocommerce 电子邮件中。
请参阅附图以便更好地理解。
我试图在 woocommerce 插件中找到该文件来进行更改,但是 Discount 条目太多了,这让我很困惑。任何帮助,将不胜感激。希望儿童主题解决方案是一种祝福。提前致谢。
答案 0 :(得分:0)
/**
* Filter to rearrange the order details template's footer part.
*/
function reordering_order_item_totals( $total_rows, $wc_order, $tax_display ) {
$total_rows = move_key_before( $total_rows, 'discount', 'shipping' );
return $total_rows;
}
add_filter( 'woocommerce_get_order_item_totals', 'reordering_order_item_totals', 10, 3 );
/**
* Rearrange associative array.
*
* @see https://codereview.stackexchange.com/a/166491
*
* @param array $arr Associative array.
* @param string $find Key of the element to be found out.
* @param string $move Key of the element to be moved before found element.
*/
function move_key_before( $arr, $find, $move ) {
if ( ! isset( $arr[ $find ], $arr[ $move ] ) ) { // Check both keys exists.
return $arr;
}
$elem = array( $move => $arr[ $move ] ); // Cache the element to be moved.
$start = array_splice( $arr, 0, array_search( $find, array_keys( $arr ), true ) ); // Chunked array holds elements before the $move element.
unset( $start[ $move ] ); // Only important if $move is in $start.
return $start + $elem + $arr; // Utilized union operator: https://www.php.net/manual/en/language.operators.array.php click the link to know more.
}