| 1 |
<?php |
| 2 |
/** |
| 3 |
* Disco |
| 4 |
* |
| 5 |
* @package Disco |
| 6 |
* @author Ohidul Islam <wahid0003@gmail.com> |
| 7 |
* @link http://domain.tld |
| 8 |
* @license GPL 2.0+ |
| 9 |
* @copyright 2022 WebAppick |
| 10 |
*/ |
| 11 |
|
| 12 |
// Ensure the file is not accessed directly. |
| 13 |
if ( ! defined( 'ABSPATH' ) ) { |
| 14 |
exit; |
| 15 |
} |
| 16 |
|
| 17 |
if ( ! function_exists( 'disco_add_order_meta' ) ) { |
| 18 |
|
| 19 |
/** |
| 20 |
* Get a campaign id from WC session and set into post meta after place order. |
| 21 |
* Unset WC session after update post-meta. |
| 22 |
* |
| 23 |
* @param int $order_id Order ID. |
| 24 |
* @return void |
| 25 |
*/ |
| 26 |
function disco_add_order_meta( $order_id ) { |
| 27 |
$campaigns = ( WC()->session->get( 'disco_campaign' ) ); |
| 28 |
|
| 29 |
if ( empty( $campaigns ) ) { |
| 30 |
return; |
| 31 |
} |
| 32 |
|
| 33 |
/** |
| 34 |
* This foreach use for multiple campaigns. |
| 35 |
* If multiple campaigns apply for an order, then it will update meta for multiple times. |
| 36 |
*/ |
| 37 |
foreach ( $campaigns as $campaign_id ) { |
| 38 |
update_post_meta( $order_id, 'disco_campaign', $campaign_id ); |
| 39 |
} |
| 40 |
|
| 41 |
WC()->session->__unset( 'disco_campaign' ); |
| 42 |
} |
| 43 |
|
| 44 |
add_action( 'woocommerce_thankyou', 'disco_add_order_meta', PHP_INT_MAX ); |
| 45 |
} |
| 46 |
|