К сожалению, я не могу понять, как удалить исходную функцию, поэтому сейчас отображаются два экземпляра.
Вот исходная функция из плагина:
Код: Выделить всё
function aspwc_split_package_total_rows( $total_rows, $order, $tax_display ) {
if ( get_option( 'advanced_shipping_packages_display_separately', 'no' ) != 'yes' ) {
return $total_rows;
}
/** @var WC_Order $order */
$shipping_items = $order->get_items( 'shipping' );
$key_position = array_search( 'shipping', array_keys( $total_rows ) );
$new_shipping_rows = array();
foreach ( $shipping_items as $item ) {
$package_name = $item->get_meta( 'package_name' ) ?: str_replace( ':', '', __( 'Shipping:', 'woocommerce' ) );
$new_shipping_rows[ 'shipping_' . $item->get_id() ] = array(
'label' => $package_name . ':', // Package name
'value' => '[b]' . $item->get_name() . ':[/b] ' . aspwc_get_shipping_to_display( $item, $order, $tax_display ) . '
' . $item->get_meta( 'Items' ) . '',
);
}
// Remove original shipping line - Only when new rows are set (which should only happen when package names are stored)
if ( ! empty( $new_shipping_rows ) ) {
unset( $total_rows['shipping'] );
}
// Add package line(s)
array_splice( $total_rows, $key_position, 0, $new_shipping_rows ); // splice in at position 3
return $total_rows;
}
add_filter( 'woocommerce_get_order_item_totals', 'aspwc_split_package_total_rows', 10, 3 );
Код: Выделить всё
remove_filter( 'woocommerce_get_order_item_totals', 'aspwc_split_package_total_rows', 10, 3 );
Код: Выделить всё
add_filter( 'woocommerce_get_order_item_totals', 'custom_split_package_total_rows', 10, 3 );
function custom_split_package_total_rows( $total_rows, $order, $tax_display ) {
if ( get_option( 'advanced_shipping_packages_display_separately', 'no' ) != 'yes' ) {
return $total_rows;
}
/** @var WC_Order $order */
$shipping_items = $order->get_items( 'shipping' );
$key_position = array_search( 'shipping', array_keys( $total_rows ) );
$new_shipping_rows = array();
foreach ( $shipping_items as $item ) {
$package_name = $item->get_meta( 'package_name' ) ?: str_replace( ':', '', __( 'Shipping:', 'woocommerce' ) );
$new_shipping_rows[ 'shipping_' . $item->get_id() ] = array(
'label' => $package_name . ':', // Package name
'value' => aspwc_get_shipping_to_display( $item, $order, $tax_display ) . '
[b]via ' . $item->get_name() . '[/b]
' . $item->get_meta( 'Items' ) . '',
);
}
// Remove original shipping line - Only when new rows are set (which should only happen when package names are stored)
if ( ! empty( $new_shipping_rows ) ) {
unset( $total_rows['shipping'] );
}
// Add package line(s)
array_splice( $total_rows, $key_position, 0, $new_shipping_rows ); // splice in at position 3
return $total_rows;
}
Любые предложения будут полезны будем очень признательны!
Подробнее здесь: https://stackoverflow.com/questions/785 ... ith-my-own