Hi.
The easiest way to do this would be to hook into WordPress when a post gets Published. Once it gets published, you could set the required sales preference for myCRED to take over and start selling.
In order for this to work, you must make sure that the post type is listed on the myCRED > Settings page under “Sell Content”.
Next the hook:
add_action( 'transition_post_status', 'mycred_set_content_for_sale', 10, 3 );
function mycred_set_content_for_sale( $new_status, $old_status, $post ) {
// Make sure this is a post type we want to sell
// in this example we use "page" as our post type
if ( $post->post_type == 'page' ) {
$cost = 1;
$button_label = '';
// If you want sales to expire set the number of hours
// else leave at zero
$expire = 0;
// Enable sales on publishing
if ( $old_status != 'publish' && $new_status == 'publish' ) {
update_post_meta( $post->ID, 'myCRED_sell_content', array(
'status' => 'enabled',
'price' => $cost,
'button_label' => $button_label,
'expire' => $expire
) );
}
// Else if we are un-publishing, disable sales
elseif ( $old_status == 'publish' && $new_status != 'publish' ) {
update_post_meta( $post->ID, 'myCRED_sell_content', array(
'status' => 'disabled',
'price' => $cost,
'button_label' => $button_label,
'expire' => $expire
) );
}
}
}
The above code goes into your themes functions.php file.