Добавить рассчитанную сумму сохранения в строки итогов заказа Woocommerce

Это ДЕЙСТВИТЕЛЬНО изменчиво, но попробуйте:

void cls() {
    for (int i = 0; i < 250; ++i) {
        std::cout << endl;
    }
}
1
задан LoicTheAztec 28 February 2019 в 18:43
поделиться

1 ответ

Вот способ добавить то же самое в таблицу итогов заказов:

// Display the chosen delivery information
add_filter( 'woocommerce_get_order_item_totals', 'add_saving_total_order_totals', 10, 3 );
function add_saving_total_order_totals( $total_rows, $order, $tax_display ) {;
    $saving_total = 0;

    // Loop through Order items
    foreach($order->get_items() as $item ){
        $product = $item->get_product();

        if( $product->is_on_sale() ){
            $regular_price   = (float) $product->get_regular_price();
            $active_price    = (float) $product->get_price();

            $saving_total   += ($regular_price - $active_price) * $item->get_quantity();
        }
    }

    if( $saving_total > 0 ) {
        $discount_total = $order->get_discount_total();

        $label  = __( 'Saved', 'tsavedis' );
        $value  = wc_price( $saving_total + $discount_total );

        $total_rows['saving'] = array( 'label' => $label,'value' => $value );
    }
    return $total_rows;
}

Код находится в файле function.php вашей активной дочерней темы (или активной темы). проверено и работает.

0
ответ дан LoicTheAztec 28 February 2019 в 18:43
поделиться
Другие вопросы по тегам:

Похожие вопросы: