Created
December 7, 2019 12:12
-
-
Save felipe-pita/d0407d68ee41e762d8a7e7b6e550e368 to your computer and use it in GitHub Desktop.
Adiciona informações de frete nos meus pedidos
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Adicona a coluna de frete nos meus pedidos | |
*/ | |
add_filter('woocommerce_account_orders_columns', 'nerdstore_add_shipping_header_on_my_orders', 10, 1); | |
function nerdstore_add_shipping_header_on_my_orders($columns){ | |
$new_columns = array(); | |
foreach ( $columns as $key => $name ) { | |
$new_columns[ $key ] = $name; | |
// add ship-to after order status column | |
if ( 'order-total' === $key ) { //this is the line! | |
$new_columns['shipping'] = 'Frete'; | |
} | |
} | |
return $new_columns; | |
} | |
/** | |
* Adiciona as informações sobre frete nos meus pedidos | |
*/ | |
add_action('woocommerce_my_account_my_orders_column_shipping', 'nerdstore_add_shipping_content_on_my_orders'); | |
function nerdstore_add_shipping_content_on_my_orders( $order ) { | |
// Iterating through order shipping items | |
foreach( $order->get_items( 'shipping' ) as $item_id => $shipping_item_obj ){ | |
$order_item_name = $shipping_item_obj->get_name(); | |
$order_item_type = $shipping_item_obj->get_type(); | |
$shipping_method_title = $shipping_item_obj->get_method_title(); | |
$shipping_method_id = $shipping_item_obj->get_method_id(); // The method ID | |
$shipping_method_instance_id = $shipping_item_obj->get_instance_id(); // The instance ID | |
$shipping_method_total = $shipping_item_obj->get_total(); | |
$shipping_method_total_tax = $shipping_item_obj->get_total_tax(); | |
$shipping_method_taxes = $shipping_item_obj->get_taxes(); | |
} | |
echo str_replace('(', '<br>(', $shipping_method_title) . '<br>' . wc_price($shipping_method_total); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment