CRED plugin allows you to build front-end forms for creating and editing content. These forms can include all the fields that belong to the content and display them with your HTML styling. CRED forms also support input validation and automatic email notifications.
When you ask for help or report issues, make sure to tell us the structure and the settings of your form.
Viewing 15 topics - 766 through 780 (of 787 total)
Problem:
The user collects payment for user registration, he would like to automatically create a post from a custom post type when the user completes the payment. And he would like to pass some data(custom fields) in the user registration form.
Solution:
This requires:
Post custom fields.
User custom fields, similar to the post fields needed.
CRED commerce form for users registration.
Custom code to create the post automatically when the order completes.
The cred_commerce_after_order_completed hook passes a $data object to the hooked function. The order_id is the "transaction_id" in the $data object. The created user is saved in a custom field of the order, called "_cred_post_id". Then we can pull the user fields from the user, create the custom post, and save the custom field values for the post.
Check this sample code:
add_action( 'cred_commerce_after_order_completed', 'my_cred_commerce_after_order_completed', 10, 1 );
function my_cred_commerce_after_order_completed( $data ) {
// get the order id
$order_id = $data['transaction_id'];
// get the user id
$user_id = get_post_meta( $order_id, '_cred_post_id', true);
// get user data to have a title for the post.
$user = get_userdata( $user_id );
// prepare post object
$post = array(
'post_type' => 'user-profile', // <== CPT slug
'post_title' => $user->user_login, // <== post title
'post_status' => 'publish',
'post_author' => $user_id, // <== Author
);
// Insert the post into the database
$post_id = wp_insert_post( $post );
// get user field
$phone = get_user_meta( $user_id, 'wpcf-phone-number', true );
$agency = get_user_meta( $user_id, 'wpcf-agency1', true );
$speciality = get_user_meta( $user_id, 'wpcf-specialty', true );
// create post field
update_post_meta( $post_id, 'wpcf-agency1', $agency );
update_post_meta( $post_id, 'wpcf-phone-number', $phone );
update_post_meta( $post_id, 'wpcf-speciality', $speciality );
}