The MemberOrder class holds information about PMPro orders and can be used to create, update, delete, or get information about membership orders.

Example of the MemberOrder Class

To instantiate this class, use:

$order = new MemberOrder();

Constructor Parameters

  • string $id  = null
    The order code or order ID that should be used to retrieve this object. If null, a blank MemberOrder object is created.

For example, this code would retrieve a MemberOrder object for order ID 1:

$membership_level = new MemberOrder( '1' );

For example, this code would retrieve a MemberOrder object for an order with the code of ‘FF453F9B1A’:

$membership_level = new MemberOrder( 'FF453F9B1A' );

Properties

string code
Unique identifier for this membership order.
int user_id
The WordPress user ID that the order belongs to.
int membership_id
The membership ID that the order belongs to.
string subtotal
The amount excluding tax for the membership order.
string tax
The amount of tax that was charged.
string total
The total amount of the order (subtotal + tax).
string payment_type
The type of payment that was used (i.e. PayPal Express, Check, etc).
string cardtype
The type of card used for the order (i.e. Visa, Mastercard etc) . Only available for certain gateways.
string account_number
The last four digits of card charged. For reference purposes only and gateway dependent.
string expiration_month
The month the card will expire. For reference purposes only and gateway dependent.
string expiration_year
The year the card will expire. For reference purposes only and gateway dependent.
string status
The status of the order. Default statuses: success, cancelled, pending, refunded, error, token and review.
string gateway
The gateway used for the order (i.e. paypal, stripe, check).
string gateway_environment
The mode in which the gateway was used. (i.e. sandbox, live)
string payment_transaction_id
The unique identifying string from the payment gateway for the initial checkout payment.
string subscription_transaction_id
The unique identifying string from the payment gateway for the recurring payment.
string affiliate_id
The affiliate ID that is linked to this order.
string affiliate_sub_id
The affiliate subscription ID that was used for this order.
string notes
The order’s notes.
int checkout_id
A unique identifier for the checkout. (Autoincrements)
stdClass billing
An object for billing information to add to the order if billing details are captured during checkout.
string billing->name
The name of the member.
string billing->street
The street address of the member.
string billing->street2
The second line of the street address of the member.
string billing->city
The city of the member.
string billing->state
The state/province of the member.
string billing->zip
The zip code for the member’s address.
string billing->country
The country code, usually ISO 3166 code.
string billing->phone
The phone number of the member.

Public Methods


get_order()

Get a specific order by ID, code, or an array of arguments.

Return

The specific MemberOrder object from the query or null if none found.

Examples

Get the last order for a specific user (by user_id).

$order_args = array(
    'user_id' => 1,
);
$order = MemberOrder::get_order( $order_args );

get_orders()

Get all orders or specific orders based on the array of arguments.

Return

An array MemberOrder objects from the query or an empty array if none found.

Examples

Get all orders for a specific user (by user_id).

$order_args = array(
    'user_id' => 1,
);
$order = MemberOrder::get_orders( $order_args );

getEmptyMemberOrder()

The method to get an empty order object.

Return

Object, the default order object template.

Examples

$member_order = new MemberOrder();
$member_order->getEmptyMemberOrder();

Note: Instantiating the MemberOrder() class without any parameter will call the getEmptyMemberOrder method.

getMemberOrderByID( int $id )

Retrieve the member’s order by the order ID.

Parameters

  • int $id – The order’s ID.

Return

MemberOrder object which was populated based by ID, or false if invalid $id passed.

Examples

$order = new MemberOrder();
$order = $order->getMemberOrderByID( 1 );

Note: Instantiating the MemberOrder( 1 ) class with a numeric parameter will call the getMemberOrderByID method.

get_original_subscription_order( string $subscription_id )

Get the first order for this subscription. Useful to find the original order from a recurring order.

Parameters

  • string $subscription_id – The subscription ID of an order to use as a reference.

Returns

The order object if a previous order is available. Returns false if no order is found.

Examples

$order = new MemberOrder();
$first_order = $order->get_original_subscription_order( 'sub_123' );



getMemberOrderByCode( string $code )

Retrieve the MemberOrder object based on the order’s code.

Parameters

  • string $code – The order code of desired order.

Returns

The MemberOrder Object for specified order code.

Examples

$order = new MemberOrder();
$order = $order->getMemberOrderByCode( 'FF453F9B1A' );

Note: Instantiating the MemberOrder( 'FF453F9B1A' ) class with a numeric parameter will call the getMemberOrderByCode method.



setGateway( string $gateway )

Set the payment gateway for the order.

Parameters

  • string $gateway – The payment gateway name to be used for the order (i.e. paypal_express, check, stripe etc)

Returns

String the gateway name assigned to the order, or false if the gateway does not exist.

Examples

$order = new MemberOrder();
$order->setGateway( 'paypal_express');



getLastMemberOrder( int $user_id, string $status, int $membership_id, string $gateway, string $gateway_environment )

Retrieve the latest order for a specific member based on various parameters. If only user ID passed through, this will retrieve the latest order for the user ID with a status of ‘success’.

Parameters

  • int $user_id – The user’s ID.
  • string $status – The status which the order should belong to.
  • int $membership_id – The membership ID.
  • string $gateway – The gateway to query the order against.
  • string $gateway_environment – The gateway environment (mode) to query the order against.

The only required parameter is the $user_id. The rest of parameters are optional.

Returns

MemberOrder object which was populated based by the various parameters, or false if no order is found.

Examples

$order = new MemberOrder();
$order = $order->getLastMemberOrder( 1, 'refunded', 3, 'stripe', 'live' );



getMemberOrderByPaymentTransactionID( string $payment_transaction_id )

Retrieve the user’s latest order based on the payment_transaction_id.

Parameters

  • string $payment_transaction_id – The payment transaction ID usually provided by the gateway.

Returns

The latest MemberOrder object for specified payment transaction ID.

Examples

$order = new MemberOrder();
$order = $order->getMemberOrderByPaymentTransactionID( 'ch_123456' );



getLastMemberOrderBySubscriptionTransactionID( string $subscription_id )

Retrieve the user’s latest order based on the subscription_transaction_id

Parameters

  • string $subscription_transaction_id – The subscription transaction ID usually provided by the gateway (excluded PayPal gateways).

Returns

The latest MemberOrder object for specified subscription transaction ID.

Examples

$order = new MemberOrder();
$order = $order->getLastMemberOrderBySubscriptionTransactionID( 'sub_12345' );



getMemberOrderByPayPalToken( string $token )

Retrieve the user’s latest order based on the the PayPal token.

Parameters

  • string $token – The PayPal’s subscription token. (Only for PayPal gateways).

Returns

The latest MemberOrder object for specified PayPal token.

Examples

$order = new MemberOrder();
$order = $order->getMemberOrderByPayPalToken( 'I-XB17PYR1SS9E' );



getDiscountCode( bool $force )

Get the discount code object that is used for the order.

Parameters

  • bool $force – Force to run a SQL query to retrieve the discount code for the order. If set to false, this will retrieve the discount code from the order object.

Returns

The discount code object used for the order.

Examples

$order = new MemberOrder( 1 );
$discount_code = $order->getDiscountCode();



updateDiscountCode( int $discount_code_id )

Update the discount code associated with the order.

Parameters

  • int $discount_code_id – The discount code’s ID to assign to the order.

Returns

If updated successfully, it returns the discount code object of the newly updated discount code for the order.

Examples

$order = new MemberOrder( 1 );
$discount_code = $order->updateDiscountCode( 33 );



getUser()

Retrieve the user object associated with the order.

Returns

The user object associated to the order.

Examples

$order = new MemberOrder( 1 );
$member = $order->getUser();



getMembershipLevel( bool $force )

Retrieve the membership level object associated with the member’s order.

Parameters

  • bool $force – Force to run a SQL query to retrieve the membership level object for the order. If set to false, this will retrieve the membership level from the order object.

Returns

The membership level object associated with the order.

Examples

$order = new MemberOrder( 1 );
$membership_level = $order->getMembershipLevel();



getMembershipLevelAtCheckout( bool $force)

Retrieve the membership level object at checkout for the associated order.

Parameters

  • bool $force – Force to run a query to retrieve the membership level object at checkout. If set to false, this will retrieve the membership level from the order object.

Returns

The membership level object associated with the order.

Examples

$order = new MemberOrder();
$level = $order->getMembershipLevelAtCheckout( true );



getTaxForPrice( float $price )

Apply tax rules for the price given.

Parameters

  • float $price – The amount to calculate tax from.

Returns

The tax amount charged for the price given.

Examples

$order = new MemberOrder();
$tax = $order->getTaxForPrice( 20.50 );



getTax( bool $force)

Get the amount of tax for a given order.

Parameters

  • bool $force – Force to calculate the tax amount or retrieve it from the order’s object.

Returns

The tax amount charged for the order.

Examples

$order = new MemberOrder( 1 );
$tax = $order->getTax();



getTimeStamp( bool $gmt )

Retrieve the timestamp of the order.

Parameters

  • bool $gmt – Set this parameter to true if you want to get the GMT timestamp of the order.

Returns

The timestamp in ‘Y-m-d’ format of the order if $gmt is set to true. Returns the default timestamp if set to false.

Examples

$order = new MemberOrder();
$order_date = $order->getTimeStamp( true );



updateTimeStamp( int $year, int $month, int $day, string $time)

Update the order’s date/timestamp.

Parameters

  • string $year – Set the year value.
  • string $month – Set the month value. Supports 1-12
  • int $day – Set the day value. Supports 1-31.
  • string $time – Set the time of the order. Supports hours, minutes and seconds (“H:i:s”). This should be adjusted for local timezone.

Returns

Returns the order object with updated date value.

Examples

$order = new MemberOrder();
$order->updateTimeStamp( 2020, 12, 31, '12:55:03' );



saveOrder()

Method used to save the member order when creating/updating an order.

Returns

The recently saved order object.

Examples

$order = new MemberOrder();
$order->user_id = 5;
$order->membership_id = 1;
$order->subtotal = 100;
$order->tax = 10;
$order->total = 110;
$order->saveOrder();



updateStatus( string $newstatus)

Update the order’s status.

Parameters

  • string $newstatus – The new status to set the order to.

Returns

The boolean value if the order was updated successfully or not.

Examples

$order = new MemberOrder( 1 );
$order->updateStatus( 'failed' );



process()

Call the process step of the gateway class.

Returns

The gateways process method results.

Examples

$order = new MemberOrder( 4 );
$order->process();

cancel()

Cancel an order and call the cancel step of the gateway class if needed.

Returns

The cancel method of the gateway class results.

Examples

$order = new MemberOrder( 123 );
$order->cancel();



updateBilling()

Call the update method of the gateway class.

Returns

The gateway class updateBilling method results.

Examples

$order = new MemberOrder();
$order->updateBilling();

get_tos_consent_log_entry()

Get the terms of service consent log for the order.

Returns

The terms of service consent history of the user.

Examples

$order = new MemberOrder( 14 );
$tos_log = $order->get_tos_consent_log_entry();



deleteMe()

Delete an order and associated data.

Returns

Boolean value if the order was deleted or not.

Examples

$order = new MemberOrder( 11 );
$order->deleteMe();

get_subscription()

Get the PMPro_Subscription object for this order. If the subscription doesn’t exist but should, it will be created.

Returns

The subscription object or null if the order is not a subscription.

Examples

$subscription = $order->get_subscription();

Deprecated Methods

The following methods were formerly part of the MemberOrder class but are now deprecated.

  • getGatewaySubscriptionStatus()
  • getGatewayTransactionStatus()
  • confirm()

Action and Filter Hooks

do_action($before_action, $this);

Run code before a specified action on the order class. Consists of pmpro_updated_order and pmpro_added_order

Arguments

  • $this: The order object.

do_action($after_action, $this);

Run code after a specified action on the order class. Consists of pmpro_updated_order and pmpro_added_order

Arguments

  • $this: The order object.

do_action("pmpro_delete_order", $this->id, $this);

Run code after an order is deleted.

Arguments

  • $this->id: The order’s ID that was deleted.
  • $this: The order object.

apply_filters("pmpro_order_discount_code", $this->discount_code, $this);

Adjust the discount code used for the order.

Arguments

  • $this->discount_code: The discount code that is associated with the order.
  • $this: The order object.

apply_filters("pmpro_tax", $tax, $values, $this);

Adjust the tax amount charged for an order.

Arguments

  • $tax: the tax amount.
  • $this: The order object.

apply_filters( 'pmpro_random_code', $code, $this );

Adjust the order code that is randomly generated.

Arguments

  • $code: The order’s code.
  • $this: The order object.
Was this article helpful?
YesNo