Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added bundle product download link for bundle purchase for Woo and EDD #9

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions includes/Edd/SendRequests.php
Original file line number Diff line number Diff line change
Expand Up @@ -125,15 +125,19 @@ private function send_delete_order_and_license_request( $payment, $download_id )
private function save_license_response( $response, $payment_id, $download_id ) {
if ( isset( $response['data'] ) && isset( $response['data']['source_id'] ) ) {
$key = '_appsero_order_license_for_product_' . $download_id;

update_post_meta( $payment_id, $key, [
$data = [
'source_id' => $response['data']['source_id'],
'key' => $response['data']['key'],
'status' => $response['data']['status'],
'download_url' => $response['data']['download_url'],
'expire_date' => $response['data']['expire_date'],
'send_license' => isset( $response['data']['send_license'] ) ? $response['data']['send_license'] : true,
] );
];
if ( isset( $response['data']['bundleProducts'] ) ) {
$data['bundle_products'] = $response['data']['bundleProducts'];
}

update_post_meta( $payment_id, $key, $data );
}
}

Expand Down
31 changes: 31 additions & 0 deletions includes/Edd/ThankYouPage.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,10 @@ public function show_license_and_download( $payment_post, $receipt_args ) {
<?php
foreach ( $licenses as $license ) {
$this->license_and_download_item( $license );
if (! isset( $license['bundle_products'] )) {
continue;
}
$this->show_bundle_products( $license );
}
?>
</tbody>
Expand Down Expand Up @@ -88,4 +92,31 @@ private function license_and_download_item( $license ) {
<?php
}

/**
* Show bundle products
*/
private function show_bundle_products( $products ) {
?>
<tr>
<th colspan="3" style="text-align: center">
Products in <?php echo $products['item_name']?>
</th>
</tr>
<?php
foreach ($products['bundle_products'] as $product) {
?>
<tr>
<td colspan="2"><?php echo $product['name'] ; ?></td>
<td>
<?php if (! empty($product['download_url'])): ?>
<a href="<?php echo esc_url( $product['download_url'] ); ?>" class="button">
<?php echo esc_html( sanitize_title( $product['slug'] ) ); ?>.zip
</a>
<?php endif; ?>
</td>
</tr>
<?php
}
}

}
9 changes: 6 additions & 3 deletions includes/WooCommerce/SendRequests.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,15 +88,18 @@ public function delete_order( $order_id ) {
private function save_license_response( $response, $order_id, $product_id ) {
if ( isset( $response['data'] ) && isset( $response['data']['source_id'] ) ) {
$key = '_appsero_order_license_for_product_' . $product_id;

update_post_meta( $order_id, $key, [
$data = [
'source_id' => $response['data']['source_id'],
'key' => $response['data']['key'],
'status' => $response['data']['status'],
'download_url' => $response['data']['download_url'],
'expire_date' => $response['data']['expire_date'],
'send_license' => isset( $response['data']['send_license'] ) ? $response['data']['send_license'] : true,
] );
];
if ( isset( $response['data']['bundleProducts'] ) ) {
$data['bundle_products'] = $response['data']['bundleProducts'];
}
update_post_meta( $order_id, $key, $data );
}
}

Expand Down
35 changes: 34 additions & 1 deletion includes/WooCommerce/ThankYouPage.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,11 +73,44 @@ public function show_license_and_download( $order_id ) {
<?php endif; ?>
</td>
</tr>
<?php endforeach; ?>
<?php
if (! isset( $license['bundle_products'] ) ) {
continue;
}
$this->show_bundle_products( $license );
endforeach;
?>
</tbody>
</table>
</section>
<?php
}

/**
* Show bundle products for the bundle
*/
private function show_bundle_products( $products ) {
?>
<tr>
<th colspan="3" style="text-align: center">
Products in <?php echo $products['item_name']?>
</th>
</tr>
<?php
foreach ($products['bundle_products'] as $product) {
?>
<tr>
<td colspan="2"><?php echo $product['name'] ; ?></td>
<td>
<?php if (! empty($product['download_url'])): ?>
<a href="<?php echo esc_url( $product['download_url'] ); ?>" class="button">
<?php echo esc_html( sanitize_title( $product['slug'] ) ); ?>.zip
</a>
<?php endif; ?>
</td>
</tr>
<?php
}
}

}