Advertisement
nshelper

Untitled

Mar 23rd, 2023 (edited)
185
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.33 KB | None | 0 0
  1.     public function process_order( $order_id ){
  2.        
  3.         // donโ€™t process the ads if they were already created
  4.         /*if( get_post_meta( $order_id, 'advanced_ads_selling_processed_order', true )){
  5.             return;
  6.         }*/
  7.        
  8.         $order = new WC_Order( $order_id );
  9.         $items = $order->get_items();
  10.        
  11.         $_item_key = 1;
  12.         $has_ad_item = false; // flag if at least one item is an ad product
  13.         foreach ($items as $_item_id => $_item) {
  14.             do_action( 'woocommerce/cart_loop/start', $_item );
  15.             $product = wc_get_product( $_item['product_id'] );
  16.             if ( $product->is_type( 'advanced_ad' ) ) {
  17.                 // create import xml
  18.                 $xml = $this->create_import_xml( $_item, $order, $_item_id, $_item_key );
  19.                 // create the ad
  20.                 Advanced_Ads_Import::get_instance()->import( $xml );
  21.                 $has_ad_item = true;
  22.             }
  23.             $_item_key++;
  24.             do_action( 'woocommerce/cart_loop/end', $_item );
  25.         }
  26.        
  27.         // save hash for ad setup page
  28.         if( $has_ad_item) {
  29.             update_post_meta( $order_id, "advanced_ads_selling_setup_hash", wp_generate_password( 48, false ) ); // Ad Setup Hash
  30.         }
  31.        
  32.         // notify client after the purchase
  33.         Advanced_Ads_Selling_Notifications::notify_client_after_purchase( $order_id );
  34.        
  35.         // mark this order as processed with a custom value
  36.         // update_post_meta( $order_id, 'advanced_ads_selling_processed_order', 1 );
  37.        
  38.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement