Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * Sends order data to CRM's ecommerce system
- *
- * @access public
- * @return void
- */
- public function transaction_created( $txn, $old_txn ) {
- // Maybe remove Confirmed, waiting on Kay
- if ( 'complete' != $txn->status && 'confirmed' != $txn->status ) {
- return;
- }
- $complete = $txn->get_meta( 'wpf_ec_complete', true );
- if ( $complete ) {
- return;
- }
- // Don't run on free transactions
- if ( 0 == $txn->total || 0 == $txn->amount ) {
- return;
- }
- $products = array(
- array(
- 'id' => $txn->product_id,
- 'name' => get_the_title( $txn->product_id ),
- 'price' => $txn->total,
- 'qty' => 1,
- 'image' => get_the_post_thumbnail_url( $txn->product_id, 'medium' ),
- 'crm_product_id' => get_post_meta( $txn->product_id, wp_fusion()->crm->slug . '_product_id', true ),
- ),
- );
- $mepr_options = MeprOptions::fetch();
- $userdata = get_userdata( $txn->user_id );
- $order_args = array(
- 'order_label' => 'MemberPress transaction #' . $txn->id,
- 'order_number' => $txn->id,
- 'order_edit_link' => admin_url( 'admin.php?page=memberpress-trans&action=edit&id=' . $txn->id ),
- 'payment_method' => $txn->payment_method()->name,
- 'user_email' => $userdata->user_email,
- 'products' => $products,
- 'line_items' => array(),
- 'total' => $txn->total,
- 'currency' => $mepr_options->currency_code,
- 'currency_symbol' => $mepr_options->currency_symbol,
- 'order_date' => strtotime( $txn->created_at ),
- 'provider' => 'memberpress',
- 'user_id' => $txn->user_id,
- );
- $contact_id = wp_fusion()->user->get_contact_id( $txn->user_id );
- // Add order
- $result = wp_fusion_ecommerce()->crm->add_order( $txn->id, $contact_id, $order_args );
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement