autoship_get_scheduled_order_product_data

(src > orders.php) This function gathers the product data for the orders. 

It takes the following parameters:

  • WC Product id
  • frequency_type
  • frequency 

The function also includes the following filters:

  1. autoship_create_scheduled_order_item_product_price filter
  2. autoship_create_scheduled_order_item_product_sale_price filter
/**
* Gathers the scheduled order product data
*
* @param int          $external_id A WC_Product id.
* @param string       $frequency_type. The frequency type assigned to this product
* @param int          $frequency.      The actual frequency duration.
* @return array       An array containing the Autoship Scheduled
*                     order data for the supplied WC Order
*/
function autoship_get_scheduled_order_product_data ( $external_id, $frequency_type, $frequency ) {

  $product     = wc_get_product( $external_id );

	// Get site settings
	$site_id = autoship_get_site_id();

  // Item price
  $item_price               = floatval( $product->get_regular_price() );
  $item_price               = apply_filters( 'autoship_create_scheduled_order_item_product_price', $item_price, $frequency_type, $frequency,$product );


  // Get the Autoship re-order Sale Price
  $autoship_recurring_price = autoship_get_product_recurring_price( $external_id, $frequency_type, $frequency );
  $item_recurring_price     = isset( $autoship_recurring_price ) ? floatval( $autoship_recurring_price ) : NULL;

  $item_recurring_price = apply_filters( 'autoship_create_scheduled_order_item_product_sale_price', $item_recurring_price, $frequency_type, $frequency,$product );

  $scheduled_order_item_data                     = array(
    "Product"   => array(
      "SiteId"        => $site_id,
      "ExternalId"    => $external_id,
      "Type"          => substr( $product->get_type(), 0, 20 ),
      "Title"         => substr( autoship_get_product_display_name( $product ), 0, 100 ),
      "Sku"           => empty($product->get_sku()) ? null : substr( $product->get_sku(), 0, 32 ),
      "Price"         => $item_price,
      "SalePrice"     => isset( $item_recurring_price ) ? $item_recurring_price : $product->get_sale_price(),
      "Length"        => empty($product->get_length()) ? null : substr( $product->get_length(), 0, 10 ),
      "Width"         => empty($product->get_width()) ? null : substr( $product->get_width(), 0, 10 ),
      "Height"        => empty($product->get_height()) ? null : substr( $product->get_height(), 0, 10 ),
      "Weight"        => empty($product->get_weight()) ? null : substr( $product->get_weight(), 0, 10 ),
      "ShippingClass" => empty($product->get_shipping_class()) ? null : substr( $product->get_shipping_class(), 0, 20 ),
      "TaxClass"      => empty($product->get_tax_class()) ? null : substr( $product->get_tax_class(), 0, 20 ),
      "ImageUrl"      => empty(autoship_get_wc_product_image_url( $external_id )) ? null : substr( autoship_get_wc_product_image_url( $external_id ), 0, 128 ),
      "Url"           => empty($product->get_permalink()) ? null : substr( $product->get_permalink(), 0, 128 ),
      "Availability"  => 'AddToScheduledOrder, ProcessScheduledOrder'

    ),
    "Price"     => $item_price,
    "SalePrice" => $item_recurring_price
  );

  return apply_filters( 'autoship_get_scheduled_order_item_product_data', $scheduled_order_item_data, $frequency_type, $frequency );

}