autoship_delete_product (function)

(src/products.php) Used to delete a product / variation in QPilot. It takes the $product (Id or WC Product object) as its parameter and returns true or false & the WP Error

Function

/**
 * Deletes a product / product variations in QPilot.
 *
 * @param mixed $product. WC Product ID or WC_Product Object.
 * @return bool|WP_Error True on success else false|wp_error
 */
function autoship_delete_product ( $product ){

  // Create the QPilot client
  // Grab the client and only continue if connection exists.
  if ( empty( $client = autoship_get_default_client() ) || empty( $client->get_token_auth() ) || !$product )
  return false;

  $id = !is_numeric( $product ) ? $product->get_id() : $product;

  try {

    // Delete product
    $client->delete_product( $id );

  } catch (Exception $e) {
    $notice = autoship_expand_http_code( $e->getCode() );
    autoship_log_entry( __( 'Autoship Products', 'autoship' ), sprintf( 'Product Delete Failed. Additional Details: %s', $e->getMessage() ) );
    return new WP_Error( 'Product Delete Failed', __( $notice['desc'], "autoship" ) );
  }

  do_action( 'autoship_after_delete_product', $id );
  return true;

}