mycred_sell_content_new_purchase

Description

This function will attempt to charge a given user for a piece of content that has been set for sale using the Sell Content add-on. If profit sharing is enabled, the function will also payout the post author their share if the user was successfully charged.

This function will not check if the post is set for sale. This should be done before using this function!

This function is only available if the Sell Content add-on is enabled.

Available since version 1.7

Returns

(bool) TRUE if the purchase completed successfully else FALSE.

Parameters

Param Type Required Description
function mycred_sell_content_new_purchase(
$post obj Yes

The post object being purchased.

$user_id int Yes

The users numeric ID.

$point_type string Yes

The point type used as payment.

) { ... }

Examples

Example 1: Attempt to charge the current user for purchasing a post.

$post_id = 1;
$post    = get_post( $post_id );
$user_id = get_current_user_id();

// Make sure the post is for sale and we have not paid for it
if ( mycred_post_is_for_sale( $post ) && ! mycred_user_paid_for_content( $user_id, $post->ID ) ) {

	// Now charge
	$result = mycred_sell_content_new_purchase( $post, $user_id, 'mycred_default' );

	// Payment successfull!
	if ( $result ) {

	}

	// Payment declined for some reason
	else {

	}

}