verygoodplugins

Untitled

Dec 2nd, 2020
622
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /**
  2.      * Sends order data to CRM's ecommerce system
  3.      *
  4.      * @access  public
  5.      * @return  void
  6.      */
  7.  
  8.     public function transaction_created( $txn, $old_txn ) {
  9.  
  10.         // Maybe remove Confirmed, waiting on Kay
  11.         if ( 'complete' != $txn->status && 'confirmed' != $txn->status ) {
  12.             return;
  13.         }
  14.  
  15.         $complete = $txn->get_meta( 'wpf_ec_complete', true );
  16.  
  17.         if ( $complete ) {
  18.             return;
  19.         }
  20.  
  21.         // Don't run on free transactions
  22.         if ( 0 == $txn->total || 0 == $txn->amount ) {
  23.             return;
  24.         }
  25.  
  26.         $products = array(
  27.             array(
  28.                 'id'             => $txn->product_id,
  29.                 'name'           => get_the_title( $txn->product_id ),
  30.                 'price'          => $txn->total,
  31.                 'qty'            => 1,
  32.                 'image'          => get_the_post_thumbnail_url( $txn->product_id, 'medium' ),
  33.                 'crm_product_id' => get_post_meta( $txn->product_id, wp_fusion()->crm->slug . '_product_id', true ),
  34.             ),
  35.         );
  36.  
  37.         $mepr_options = MeprOptions::fetch();
  38.  
  39.         $userdata = get_userdata( $txn->user_id );
  40.  
  41.         $order_args = array(
  42.             'order_label'     => 'MemberPress transaction #' . $txn->id,
  43.             'order_number'    => $txn->id,
  44.             'order_edit_link' => admin_url( 'admin.php?page=memberpress-trans&action=edit&id=' . $txn->id ),
  45.             'payment_method'  => $txn->payment_method()->name,
  46.             'user_email'      => $userdata->user_email,
  47.             'products'        => $products,
  48.             'line_items'      => array(),
  49.             'total'           => $txn->total,
  50.             'currency'        => $mepr_options->currency_code,
  51.             'currency_symbol' => $mepr_options->currency_symbol,
  52.             'order_date'      => strtotime( $txn->created_at ),
  53.             'provider'        => 'memberpress',
  54.             'user_id'         => $txn->user_id,
  55.         );
  56.  
  57.         $contact_id = wp_fusion()->user->get_contact_id( $txn->user_id );
  58.  
  59.         // Add order
  60.         $result = wp_fusion_ecommerce()->crm->add_order( $txn->id, $contact_id, $order_args );
  61.  
  62.     }
RAW Paste Data

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing Pastebin.com from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add Pastebin.com to your ad blocker whitelist or disable your adblocking software.

×