autoship_load_product_summary_data_display_notice (function)

(src/product-page.php) Loads Autoship Cloud Data on Edit Product page. 

Function

/**
* Load Autoship Cloud Data on Edit Product Screen.
* TODO: Currently hooked into the admin notices but could try to find
*       better hook for early data load.
*/
function autoship_load_product_summary_data_display_notice (){

  // Get the Current Screen object and if doesn't exist escape.
  $screen = get_current_screen();
  if ( !$screen )
  return;

  if ( 'product' !== $screen->id || 'edit' !== $screen->parent_base )
  return;

  global $post;
	$product  = wc_get_product( $post->ID );
  $valid    = autoship_is_valid_sync_product( $post->ID );
  $active   = 'yes' == autoship_sync_active_enabled( $product );

  // Allow devs to disable admin notice if desired.
  if( apply_filters('autoship_display_edit_product_sync_admin_notice', !$active || !$valid, $product ) )
  return;

  /**
  * Get the Stored Autoship Product Sync Data
  * Retrieved and Initially stored in @see autoship_product_metaboxes_template_data()
  * hooked to add_meta_boxes_product
  */
  $summary_data = $active ? autoship_get_stored_product_sync_summary_data( $post->ID ) : array();

  // Get any Error or Warning Data.
  $error_data = autoship_get_product_summary_error_details( $summary_data, $product );

  // Check for Sync Error for active and valid products
  if ( $active && $valid && ( !empty( $error_data['type'] ) && ( 'error' == $error_data['type'] ) ) ){

    $title  = __( 'Error', 'autoship' );
    $status = 'error';
    $notice = sprintf( "<p>%s</p>", $error_data['msg'] );

  // If active and no general sync error
  } else if ( !empty( $summary_data ) && $active ){

    if ( $summary_data['QuantityScheduled'] ){

      $total_string = array();
      if ( $summary_data['TotalQuantityScheduledActive'] )
      $total_string[] = $summary_data['TotalQuantityScheduledActive'] . ' Active';

      if ( $summary_data['TotalQuantityScheduledActive'] )
      $total_string[] = $summary_data['TotalQuantityScheduledPaused'] . ' Paused';

      if ( $summary_data['TotalQuantityFailed'] )
      $total_string[] = $summary_data['TotalQuantityFailed'] . ' Failed';

      if ( $summary_data['TotalQuantityProcessing'] )
      $total_string[] = $summary_data['TotalQuantityProcessing'] . ' Processing';

    }

    // get the notice
    $scheduled_notice = autoship_get_active_product_summary_general_notice( $summary_data, $product );

    $title  = __( 'Active', 'autoship' );
    $status = 'active';
    $notice = apply_filters( 'autoship_product_admin_summary_metabox_notice', sprintf( __('<p>This product is currently <strong>Active</strong>.%s', 'autoship'), $scheduled_notice ), $status, $summary_data, $product );


  // Active but for some reason summary data isn't loaded.
  } else if ( $active ){

    $products_report_url = autoship_admin_products_page_url();
    $api_health_url = autoship_admin_settings_page_url();

    $title  = __( 'Error', 'autoship' );
    $status = 'error';
    $notice = sprintf( __( '<p>Product not synchronized: A problem was encountered while trying to retrieve this Product\'s Sync Information.  Please confirm your <a href="%s">API connection is healthy</a> and ensure there are no issues with this product in the <a href="%s">Autoship Cloud > Products</a> report.</p>', "autoship" ), $api_health_url, $products_report_url);

  }

  ?>
  <div class="autoship-admin-notice notice autoship-<?php echo $status;?>-notice is-dismissible">
    <h2><?php echo sprintf( __( 'Autoship Product Status: <span class="%s %s">%s</span>', 'autoship' ), $status, $error_data['type'], $title ); ?></h2>
    <?php echo $notice; ?>
    <?php do_action( 'autoship_product_admin_summary_metabox_notice', $status, $summary_data, $product ); ?>
  </div>
  <?php

}