【问题标题】:Move Discount field below Shipping field in Orders Details将折扣字段移动到订单详细信息中的运输字段下方
【发布时间】:2021-07-04 09:47:45
【问题描述】:

我想将“折扣:”字段移到订单详细信息中的运费字段下方。我也希望这也反映在 woocommerce 电子邮件中。

请参阅附图以更好地理解。

Order details screenshot

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

【问题讨论】:

    标签: php ajax wordpress email woocommerce


    【解决方案1】:

    内嵌解释的代码:

    /**
     * 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.
    }
    

    之前:


    之后:

    【讨论】:

    • 非常感谢。你的代码就像一个魅力。 :)
    猜你喜欢
    • 2021-08-06
    • 2015-12-10
    • 1970-01-01
    • 2020-12-06
    • 2017-06-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-07-02
    相关资源
    最近更新 更多