Php 在订单详细信息中将折扣字段移到发货字段下方

Php 在订单详细信息中将折扣字段移到发货字段下方,php,ajax,wordpress,email,woocommerce,Php,Ajax,Wordpress,Email,Woocommerce,我想将“折扣:”字段移到发货字段下方,以查看订单详细信息。我也希望这也能反映在woocommerce的电子邮件中 请参阅所附图片,以便更好地理解 我试图在woocommerce插件中找到文件来进行更改,但是有太多的条目,比如折扣,这让我完全困惑。任何帮助都将不胜感激。希望儿童主题的解决方案是一件好事。提前感谢。带内联解释的代码: 之前: 之后: 非常感谢您。您的代码工作起来很有魅力。:)很高兴你的问题解决了。 /** * Filter to rearrange the order de

我想将“折扣:”字段移到发货字段下方,以查看订单详细信息。我也希望这也能反映在woocommerce的电子邮件中

请参阅所附图片,以便更好地理解

我试图在woocommerce插件中找到文件来进行更改,但是有太多的条目,比如折扣,这让我完全困惑。任何帮助都将不胜感激。希望儿童主题的解决方案是一件好事。提前感谢。

带内联解释的代码:
之前:


之后:

非常感谢您。您的代码工作起来很有魅力。:)很高兴你的问题解决了。
/**
 * 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.
}