Personalizzare la visualizzazione dell’ordine nel proprio account

Rimuoviamo la action di woocommerce per la visualizzazione dell’ordine

remove_action( 'woocommerce_view_order', 'woocommerce_order_details_table', 10 );

Aggiungiamo la nostra action customizzata

add_action( 'woocommerce_view_order', 'intergraf_woocommerce_view_order', 10 );

La funzione è molto simile all’originale , ma vogliamo mostrare un postmeta aggiunto da noi ai prodotti, nel caso specifico la url di un video con la quale creiamo un link alla pagina che farà lo streaming

function intergraf_woocommerce_view_order( $order_id ) {
global $woocommerce;
$order = new WC_Order( $order_id );
?>
<div class="woocommerce-content-box full-width">
<h2><?php _e( 'Order Details', 'woocommerce' ); ?></h2>
<table class="shop_table order_details">
<thead>
<tr>
<th class="product-name"><?php _e( 'Product', 'woocommerce' ); ?></th>
<th class="product-quantity"><?php _e( 'Quantity', 'woocommerce' ); ?></th>
<th class="product-total"><?php _e( 'Total', 'woocommerce' ); ?></th>
</tr>
</thead>
<tfoot>
<?php
if ( $totals = $order->get_order_item_totals() ) {
foreach ( $totals as $total ) :
?>
<tr>
<td class="filler-td">&nbsp;</td>
<th scope="row"><?php echo $total['label']; ?></th>
<td class="product-total"><?php echo $total['value']; ?></td>
</tr>
<?php
endforeach;
}
?>
</tfoot>
<tbody>
<?php
if ( sizeof( $order->get_items() ) > 0 ) {
foreach ( $order->get_items() as $item ) {
$_product = apply_filters( 'woocommerce_order_item_product', $order->get_product_from_item( $item ), $item );
$item_meta = new WC_Order_Item_Meta( $item['item_meta'] );

?>
<tr class="<?php echo esc_attr( apply_filters( 'woocommerce_order_item_class', 'order_item', $item, $order ) ); ?>">
<td class="product-name">


<div class="product-info">
<?php
if ( $_product && ! $_product->is_visible() ) {
echo apply_filters( 'woocommerce_order_item_name', $item['name'], $item );
} else {
$timage = $_product->get_image(); //$item['name']
echo apply_filters( 'woocommerce_order_item_name', sprintf( '<a href="%s" ><span class="product-thumbnail">%s</span></a>', get_permalink( $item['product_id'] ), $timage ), $item );
}

do_action( 'woocommerce_order_item_meta_start', $item['product_id'], $item, $order );
$order->display_item_meta( $item );
$order->display_item_downloads( $item );
do_action( 'woocommerce_order_item_meta_end', $item['product_id'], $item, $order );
//########### leggiamo un postmeta (videourl) e lo mostriamo nell'ordine ##########
if(get_post_meta( $item['product_id'], 'videourl', true )) { 
echo '<a href="'.get_site_url().'/view-stream.php?order='.$order_id.'&prod='.$item['product_id'].'" rel="nofollow" target="_blank"style="clear:both;float:left; padding: 5px 0;" >PLAY</a>';
}
//################################################################################à
?> 
</div>
</td>
<td class="product-quantity">
<?php echo apply_filters( 'woocommerce_order_item_quantity_html', $item['qty'], $item ); ?>
</td>
<td class="product-total">
<?php echo $order->get_formatted_line_subtotal( $item ); ?>
</td>
</tr>
<?php
if ( in_array( $order->status, array(
'processing',
'completed'
) ) && ( $purchase_note = get_post_meta( $_product->id, '_purchase_note', true ) )
) {
?>
<tr class="product-purchase-note">
<td colspan="3"><?php echo apply_filters( 'the_content', $purchase_note ); ?></td>
</tr>
<?php
}
}
}
do_action( 'woocommerce_order_items_table', $order );
?>
</tbody>
</table>
<?php do_action( 'woocommerce_order_details_after_order_table', $order ); ?>
</div>
<div class="woocommerce-content-box full-width">
<header>
<h2><?php _e( 'Customer details', 'woocommerce' ); ?></h2>
</header>
<dl class="customer_details">
<?php
if ( $order->billing_email ) {
echo '<dt>' . __( 'Email:', 'woocommerce' ) . '</dt> <dd>' . $order->billing_email . '</dd><br />';
}
if ( $order->billing_phone ) {
echo '<dt>' . __( 'Telephone:', 'woocommerce' ) . '</dt> <dd>' . $order->billing_phone . '</dd>';
}
// Additional customer details hook
do_action( 'woocommerce_order_details_after_customer_details', $order );
?>
</dl>
<?php if (get_option( 'woocommerce_ship_to_billing_address_only' ) === 'no' && get_option( 'woocommerce_calc_shipping' ) !== 'no') : ?>
<div class="col2-set addresses">
<div class="col-1">
<?php endif; ?>
<header class="title">
<h3><?php _e( 'Billing Address', 'woocommerce' ); ?></h3>
</header>
<address><p>
<?php
if ( ! $order->get_formatted_billing_address() ) {
_e( 'N/A', 'woocommerce' );
} else {
echo $order->get_formatted_billing_address();
}
?>
</p></address>
<?php if (get_option( 'woocommerce_ship_to_billing_address_only' ) === 'no' && get_option( 'woocommerce_calc_shipping' ) !== 'no') : ?>
</div>
<div class="col-2">
<header class="title">
<h3><?php _e( 'Shipping Address', 'woocommerce' ); ?></h3>
</header>
<address><p>
<?php
if ( ! $order->get_formatted_shipping_address() ) {
_e( 'N/A', 'woocommerce' );
} else {
echo $order->get_formatted_shipping_address();
}
?>
</p></address>
</div>
</div>
<?php endif; ?>
<div class="clear"></div>
</div>
<?php
}

Commenta

Questo sito usa Akismet per ridurre lo spam. Scopri come i tuoi dati vengono elaborati.

Benvenuto su Intergraf! Questo sito usa i cookie per migliorare la tua esperienza.

Cookie policy