Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save goliver79/8088adf30454a994730955930769e251 to your computer and use it in GitHub Desktop.
Save goliver79/8088adf30454a994730955930769e251 to your computer and use it in GitHub Desktop.
Woocommerce Plugin GLS - ASM: Add tracking button in "my orders" page
<?php
if ( !class_exists( 'GlsAsm' ) ) {
class GlsAsm{
function activate(){
add_filter ( 'woocommerce_my_account_my_orders_actions', array( $this, 'go_add_shipping_tracking_to_customer_orders_table' ), 10, 2 );
add_action( 'woocommerce_after_account_orders', array( $this, 'action_after_account_orders_js'));
}
function go_add_shipping_tracking_to_customer_orders_table($actions, $order) {
if ( $order->has_status( 'completed' ) ) {
$codbarras = get_post_meta( $order->get_id(), 'codbarras', TRUE );
if ( ! empty( $codbarras ) ) {
foreach ( $order->get_items( 'shipping' ) as $item_id => $shipping_item_obj ) {
$mid = $shipping_item_obj->get_method_id();
}
if ( $mid == 'parcelshop' ) {
$cp_destino = get_post_meta( $order->get_id(), 'parcel_cp', TRUE );
} else {
$cp_destino = get_post_meta( $order->get_id(), '_shipping_postcode', TRUE );
}
$url = 'https://www.asmred.com/Extranet/Public/ExpedicionASM.aspx?cpDst=' . $cp_destino . '&codigo=' . $codbarras;
$actions['gls-tracking'] = array(
'url' => $url,
'name' => __( 'Tracking', 'textdomain' )
);
}
}
return $actions;
}
function action_after_account_orders_js() {
$action_slug = 'gls-tracking';
?>
<script>
jQuery(function($){
$('a.<?php echo $action_slug; ?>').each( function(){
$(this).attr('target','_blank');
})
});
</script>
<?php
}
}
$glsasm = new GlsAsm();
$glsasm->activate();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment