autoship_customer_has_scheduled_orders (function)

(src/scheduled-orders.php) Used to check if a logged in customer has any Scheduled Orders. It takes the $customer_id as its parameter and calls the QPilot API for all of your connected site's Scheduled Orders and filtering it by the logged in customer and will return true if the customer has Scheduled Orders and there is no error. 

For this reason it is recommended to cache the return or use the customer metrics user metadata added by QPilot to your users. Learn more about the customer metrics user metadata fields in this helpful doc.

Function

/**
 * Checks if a use has one or more scheduled orders.
 *
 * @param int $customer_id The wc_customer id to retrieve the orders for.
 * @return bool True they have scheduled orders else false.
 */
function autoship_customer_has_scheduled_orders ( $customer_id ){

  // Check if
  $autoship_orders = autoship_get_customer_scheduled_orders ( $customer_id );

  // Add check in case API error occurs
  return !empty( $autoship_orders ) && !is_wp_error( $autoship_orders  );

}