Problem:
The user would like to order the WooCommercearchive template in several fields, including the price.
Solution:
Make sure that the default WooCommerce order is disabled in Toolset->WooCommerce Views->Frontend Sorting. Check this screenshot http://prntscr.com/uizqgf
Problem: I would like to create a design for Product single post pages but my template does not appear when I visit the Product post on the front-end of the site.
Solution: Be sure the Content Template you created for Products has been assigned to this Product post. Use the "change usage" feature to bind unbound Products in bulk if necessary.
Problem: I have designed a custom WordPress Archive for the Product Archive (Shop Page), but I would like to use the same design for Product Category and Product Tag Archives.
Solution: Edit the WordPress Archive for the Product Archive (Shop Page). In the Block Editor, select the top-level WordPress Archive Block. Then in the Loop Selection configurations, select the two Product Taxonomy archives as well as the Product Archive (Shop Page) to reuse the Shop Page design on the two Product Taxonomy archives.
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 );
}