My users are paying for posting Classified Ads on my website.
I have a Classified Ad CPT and a CRED form that is connected to a WooCommerce product. All good and I am able to process payments.
But no CPT data is displayed in the Cart, Checkout, and Invoice. So how can I add the CPT title to the product and order details?
The problem I am trying to solve is that users only see that they have paid for a Featured Ad (product) and get no reference of the actual ad (title).
Hello again. I did some digging and I found out that the cart item that has been added from a Toolset form holds a property that has information about the form, the product, and the post that has been created like this:
$cart_item[cred_meta] => Array
(
[cred_product_id] => 10
[cred_form_id] => 11
[cred_post_id] => 21
So I come up with this custom code that will add the following below the product "Post title: {the new post title}":
add_filter( 'woocommerce_get_item_data', 'wc_add_cooking_to_cart', 10, 2 );
function wc_add_cooking_to_cart( $cart_data, $cart_item )
{
$custom_items = array();
if( !empty( $cart_data ) )
$custom_items = $cart_data;
$cred_meta = isset( $cart_item['cred_meta'] ) ? $cart_item['cred_meta'] : false;
$post_id = isset( $cred_meta['cred_post_id'] ) ? $cred_meta['cred_post_id'] : false;
if ( $post_id ) {
$title = get_the_title( $post_id );
$custom_items[] = array(
'name' => 'Post title',
'value' => $title,
'display' => $title
);
}
return $custom_items;
}
add_shortcode('metadata', function(){
global $post;
// echo '<pre>metadata</pre>';
return "<pre>" . print_r( get_post_meta( $post->ID ), true ) . "</pre>";
});
If you don't want to have the string "Post title" before the actual post title, remove line 15.
Check the results in both the cart and the checkout page hidden link
I hope this helps. Let me know if you have any questions.