autoship_check_lock_status_info()

(src/scheduled-orders.php) Used to calculate a Scheduled Order's Lock duration. It takes the Scheduled Order, the Wordpress User Id, and returns an array of Lock data for a supplied Autoship order.

Example

/**
* Returns the Duration Lock information for an order
*
* @param array|stdClass $autoship_order The scheduled order.
* @param int $customer_id Optional. The wc customer id to retrieve the orders for.
*
* @return array The Lock Information for an order.
*/
function autoship_check_lock_status_info ( $autoship_order, $customer_id = NULL, $settings = array() ){

  // Convert stdClass objects to array if needed.
  if ( $autoship_order instanceof stdClass )
  $autoship_order = autoship_convert_object_to_array( $autoship_order );

  // Grab the customer id
  if ( !isset( $customer_id ) )
  $customer_id = $autoship_order['customerId'];

  // Get the Site Settings and Allow for Customized Lock Durations by Product, Order, and/or Customer.
  $settings = empty( $settings ) ? autoship_get_site_order_settings() : $settings;

  // Set up the current settings
  $lock_data = array(

    'locked'           => $autoship_order['locked'],
    'notice'           => '',
    'duration'         => $settings['lockDurationDays'],
    'processing_start' => autoship_get_formatted_date ( $autoship_order['lastEditableDate'] )

  );

  // If no Lock Duration or if filtered to not enable return the default.
  if ( empty( $lock_data['duration'] ) || !apply_filters('autoship_enable_lock_duration_restriction', true ) ){
  $lock_data['locked'] = false;
  return $lock_data; }

  // Allow merchants to filter the locked status based on order status and order details.
  $lockable_status  = apply_filters('autoship_order_is_lockable_status', $lock_data['locked'], $autoship_order['status'], $autoship_order, $customer_id );

  if ( $lockable_status ){

    // Add the default notice
    $lock_data['notice'] = apply_filters( 'autoship_lock_duration_restriction_notification', __( "Your order started processing on <strong>{$lock_data['processing_start']}</strong>.  Only the Payment Method can be changed on this order.", 'autoship' ), $lock_data );

  }

  return $lock_data;

}

Still need help? Contact Us Contact Us