/** * Get the downloads for a product or product variation * * @since 2.1 * @param WC_Product|WC_Product_Variation $product * @return array */ private function get_downloads($product) { $downloads = array(); if ($product->is_downloadable()) { foreach ($product->get_files() as $file_id => $file) { $downloads[] = array('id' => $file_id, 'name' => $file['name'], 'file' => $file['file']); } } return $downloads; }
$productPrice = $variation->get_price(); } // If user has required ammount of credits then continue if ($getUserCredit >= $productPrice) { get_currentuserinfo(); // Save the purchase to the database and update credits balance of the user $sql = $wpdb->query("UPDATE `" . $wpdb->prefix . "woocredit_users` SET credit = '" . ($getUserCredit - $productPrice) . "' where user_id=" . get_current_user_id()); $sql = $wpdb->query("INSERT INTO `" . $wpdb->prefix . "woocredit_products` (user_id, product_id, price) VALUES (" . get_current_user_id() . "," . $_POST['productid'] . "," . $productPrice . ")"); // If the product or variant are downloadable then send an email with a link to the files if ($product && $product->is_downloadable() || $variation && $variation->is_downloadable()) { $files = []; if ($product && $product->is_downloadable()) { $files = $product->get_files(); } if ($variation && $variation->is_downloadable()) { $files = $variation->get_files(); } $headers = "MIME-Version: 1.0" . "\r\n"; $headers .= "Content-type:text/html;charset=UTF-8" . "\r\n"; $codingKey = $translate->getCodingKey(); $downloadHtml = ""; foreach ($files as $file) { $downloadHtml .= '<a href="'; $downloadHtml .= get_site_url() . "/wp-content/plugins/simple-credits/download.php?action=email"; $downloadHtml .= "&time=" . $translate->encode(time(), $codingKey); $downloadHtml .= "&filename=" . $translate->encode($file['file'], $codingKey); $downloadHtml .= '">' . $file['name'] . '</a><br/>'; } $email_text = str_replace("[filedownload]", $downloadHtml, $translate->wooTranslate('email', get_bloginfo('language'))); $message = ' <html>