autoship_get_schedulable_products_script_data (function)

( src/scheduled-orders.php) Used to output the product information for adding to Scheduled Orders.

Code

/**
 * Outputs the Product Infor for Adding to Order
 *
 * @return string The html output
 */
function autoship_get_schedulable_products_script_data( $reply_type = 'output_return' ){

  // Pull Products from Session if available else use api for fresh pull.
  $all_products = autoship_pull_schedulable_products_session();
  $all_products = empty( $all_products ) ?
  autoship_search_available_products( array( 'availability' => 1, 'addToScheduledOrder' => 'true', 'active' => 'true' ) ) : $all_products;

  // Check if error
  if ( is_wp_error( $all_products ) ){

    do_action( "autoship_after_{$action}_get_autoship_get_available_products_failure", $all_products );
    wc_add_notice( __( 'An issue was encountered while trying to retrieve the available products. <br/>Additional Details: ' . $all_products->get_error_message(), 'autoship' ),  'error' );
    $all_products = '';

  }

  $all_products = apply_filters('autoship_filter_schedulable_products_data', $all_products );

  // Store the pulled products into the session if not empty,
  // If empty clear session since there are no available products.
  if ( !empty( $all_products ) ){
    autoship_load_schedulable_products_into_session( $all_products );
  } else {
    autoship_clear_schedulable_products_sessions();
  }

  if ( 'output_return' == $reply_type ){

    autoship_print_scripts_data( array(
      'autoship_available_products_data' => $all_products
    ) );

    return $all_products;

  } else if ( 'output' == $reply_type ) {

    autoship_print_scripts_data( array(
      'autoship_available_products_data' => $all_products
    ) );

  } else if ( 'json' == $reply_type ) {

    return json_encode( array( 'autoship_available_products_data' => $all_products ) );

  }

  return $all_products;

}