Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public function process_order( $order_id ){
- // donβt process the ads if they were already created
- /*if( get_post_meta( $order_id, 'advanced_ads_selling_processed_order', true )){
- return;
- }*/
- $order = new WC_Order( $order_id );
- $items = $order->get_items();
- $_item_key = 1;
- $has_ad_item = false; // flag if at least one item is an ad product
- foreach ($items as $_item_id => $_item) {
- do_action( 'woocommerce/cart_loop/start', $_item );
- $product = wc_get_product( $_item['product_id'] );
- if ( $product->is_type( 'advanced_ad' ) ) {
- // create import xml
- $xml = $this->create_import_xml( $_item, $order, $_item_id, $_item_key );
- // create the ad
- Advanced_Ads_Import::get_instance()->import( $xml );
- $has_ad_item = true;
- }
- $_item_key++;
- do_action( 'woocommerce/cart_loop/end', $_item );
- }
- // save hash for ad setup page
- if( $has_ad_item) {
- update_post_meta( $order_id, "advanced_ads_selling_setup_hash", wp_generate_password( 48, false ) ); // Ad Setup Hash
- }
- // notify client after the purchase
- Advanced_Ads_Selling_Notifications::notify_client_after_purchase( $order_id );
- // mark this order as processed with a custom value
- // update_post_meta( $order_id, 'advanced_ads_selling_processed_order', 1 );
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement