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.
(bool) TRUE
if the purchase completed successfully else FALSE
.
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. |
|
) { ... } |
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 { } }