autoship_customer_view_order_header_attribution (function)

(src/orders.php) Used to include the Scheduled Order attributions and details in the View Order header for customers. It takes the (WooCommerce) $order_id as a parameter.

Function

/**
 * Includes the Scheduled Order Attribution and Details in the View Order Header.
 * @param int $order_id The WC Order ID currently being viewed.
 */
function autoship_customer_view_order_header_attribution( $order_id ){

  $order = wc_get_order( $order_id );

  if ( !$order )
  return;

  // Get the Source flag.
  $external_data['source']        = autoship_get_scheduled_order_related_flag( $order );

  // Get the Scheduled order id if it exists
  $external_data['origin_id']     = autoship_get_order_scheduled_order_origin_id( $order );

  // Get the Scheduled orders generated from this order if they exist.
  $external_data['scheduled_ids'] = autoship_get_order_created_scheduled_orders_key( $order );

  if ( empty( $external_data['origin_id'] ) && empty( $external_data['scheduled_ids'] ) && empty( $external_data['source'] ))
  return;

  $scheduled_order_label  = autoship_search_for_translate_text( 'Scheduled Order' );
  $scheduled_orders_label = autoship_search_for_translate_text( 'Scheduled Orders' );

  $scheduled_orders_url = autoship_get_scheduled_orders_url();

  // If this is an Order generated from a Scheduled Order
  if ( !empty( $external_data['origin_id'] ) ){

    $external_data['source']  = 'result';
    $external_data['class']   = 'created';
    $external_data['notice']  = sprintf( __( 'Created by %s <a href="%s">%d</a>','autoship' ), $scheduled_order_label, $scheduled_orders_url, $external_data['origin_id'] );

  // If this is an order from which Scheduled Orders are Generated
  } else if ( !empty( $external_data['scheduled_ids'] ) ) {

    $external_data['source']  = 'source';
    $external_data['class']   = 'scheduled';
    $external_data['notice']  = sprintf( __( 'Created %s(s) <a href="%s">%s</a>','autoship' ), $scheduled_order_label, $scheduled_orders_url, implode( ', ', $external_data['scheduled_ids'] ) );

  // Otherwise do we know if this is even a source or result?
  } else if ( !empty( $external_data['source'] ) ) {


    $external_data['class']  = 'source' === $external_data['source'] ? 'maybe-scheduled' : 'maybe-created';
    $external_data['notice'] = 'source' === $external_data['source'] ?
    sprintf( __( 'This order contains Items with associated Schedules and may have produced %s.','autoship' ), $scheduled_orders_label ) :
    sprintf( __( 'This order might have been generated by a Scheduled Order.','autoship' ), $scheduled_order_label );

    do_action( 'autoship_customer_view_order_header_attribution_maybe_scheduled_order', $external_data, $order );

    return;

  }

  $external_data['notice']  = apply_filters( 'autoship_populate_customer_view_order_header_attribution', $external_data['notice'], $external_data, $order );
  echo apply_filters( 'autoship_populate_customer_view_order_header_attribution_html',
  sprintf( '<h3 class="autoship-order-attribution %s">%s</h3>', $external_data['class'], $external_data['notice'] ),
  $external_data, $order );

}