Sell Content
-
Hi thanks for this great plugin
I use “Sell Content” for sales. This is a great part.
I need your help. I want the amount of coins that the user spends to be returned as a gift to the user’s account. This amount can be a percentage or a number
Is there a solution?
-
Hi @hamidsna,
Thank you for contacting us,
Please add the below-shared code in your theme’s functions.php file.
$reward_percentage Variable is for the percentage you want to share with the user.
Also if you want to reward in the custom point type please replace it with the mycred_default with your custom point type key.add_filter( 'mycred_add_finished', 'content_purchase_reward', 10, 3 ); function content_purchase_reward( $reply, $request, $mycred ) { if ( $reply === false || $request['ref'] != 'buy_content' ) return $reply; $reward_percentage = 10; $reward = ( floatval( $request['amount'] ) / 100 ) * $reward_percentage; mycred_add( 'content_purchase_reward', $request['user_id'], $reward, 'Reward for Purchasing %link_with_title%', $request['ref_id'], $request['data'], 'mycred_default'//point type key ); return $reply; }thank you @wpexpertssupportteam
Only I did not understand how to set mycred_default.
Is there a problem with mycred_default code remaining the default?Hi @hamidsna,
‘mycred_default’ is the Point type key, this value is assigned by default to the main point type.
If you are using just 1 point type then let the value remain as is.
If you are using more than 1 point type and want to give points from some other point type (instead of main), then you should use the key of that point type.
You can get the value of keys by following this screenshot https://prnt.sc/tuf4u2Hi @wpexpertssupportteam
This is great code. But it has a drawback, it reduces instead of adding points
I tested but it dropped 10% more points than the userHi @hamidsna,
Please use the updated code shared below.add_filter( 'mycred_add_finished', 'content_purchase_reward', 10, 3 ); function content_purchase_reward( $reply, $request, $mycred ) { if ( $reply === false || $request['ref'] != 'buy_content' ) return $reply; $reward_percentage = 10; $reward = abs( ( floatval( $request['amount'] ) / 100 ) * $reward_percentage ); mycred_add( 'content_purchase_reward', $request['user_id'], $reward, 'Reward for Purchasing %link_with_title%', $request['ref_id'], $request['data'], 'mycred_default'//point type key ); return $reply; }Thanks this code is great and it works.
Is there a solution to send a percentage of gift to old customers who have bought from Sell Content?Hi @hamidsna,
Please add the below-shared code in your themes functions.php file.add_action( 'mycred_init', 'issue_content_purchased_reward' ); function issue_content_purchased_reward() { $log = new myCRED_Query_Log( 'ref=buy_content' ); foreach ( $log->results as $key => $entry ) { $mycred = mycred( 'mycred_default' ); $reference = 'content_purchase_reward'; if ( ! $mycred->has_entry( $reference, $entry->ref_id, $entry->user_id ) ) { $reward_percentage = 10; $reward = abs( ( floatval( $entry->creds ) / 100 ) * $reward_percentage ); $mycred->add_creds( 'content_purchase_reward', $entry->user_id, $reward, 'Reward for Purchasing %link_with_title%', $entry->ref_id, $entry->data, $entry->ctype//point type key ); } } }After visiting your website one or two times please make sure to remove this code.
Thanks!
-
This reply was modified 5 years, 8 months ago by
wpexpertssupportteam.
@wpexpertssupportteam
Thank you for helping me
I did not understand how this code works
Do these two codes work together?
How does this second code work?
Does the user who bought with Sell Content have to go back to the site to get points?Hi @hamidsna,
After adding this code only you (Site admin) needs to login to the website and when it loads this code will execute itself and after that, you can just remove this code. This code just needs to be executed one time only.Thanks!
-
This reply was modified 5 years, 8 months ago by
The topic ‘Sell Content’ is closed to new replies.