Skip Navigation

[Resolved] Display newly created post in the Cart and Checkout pages.

This support ticket is created 3 years, 11 months ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 - - 9:00 – 13:00
14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 - - 14:00 – 18:00

Supporter timezone: Africa/Casablanca (GMT+01:00)

Author
Posts
#1976041

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).

#1976815

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.