WC_Product::get_post_data is deprecated since version 3.0! Use get_post instead.

Home Forums Ticket Products Event Tickets Plus WC_Product::get_post_data is deprecated since version 3.0! Use get_post instead.

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #1367201
    Christian Thomson
    Participant

    Hi there,

    I have a function in functions.php that used to display the tickets description in the email notifications, but now I get the following error:

    WC_Product::get_post_data is deprecated since version 3.0! Use get_post instead.

    The function is:

    function add_ticket_description( $order ) {
    
      	 	foreach($order->get_items() as $item) {
      	 		$ticket_id = $item['product_id'];
    			$product = new WC_Product( $ticket_id );
      	 		$product_data = $product->get_post_data();
      	 		$ticket_description = $product_data->post_excerpt;
      	 		$product_id = $product_data->id;
      	 		 
      	 		$main_post_id = get_post_meta($ticket_id, '_tribe_wooticket_for_event', true );
      	 		$venue_id = get_post_meta($main_post_id, '_EventVenueID', true );
      			$venue_address = get_post_meta($venue_id, '_VenueAddress', true );
    			$venue_city = get_post_meta($venue_id, '_VenueCity', true );
    			$venue_phone = get_post_meta($venue_id, '_VenuePhone', true );
    
    			if ($ticket_description != ''){
    				echo "<br><h2>Course Details: </h2>".$ticket_description;
    				echo $venue_address.", ".$venue_city;
    				echo"<br>".$venue_phone;
    			}
      	 	}
    		
    }

    I’ve updated the WooCommerce and Woo Tickets plugins to the latest version on my test site. Is it possible to fix this function so it works? By simply replacing

    $product = new WC_Product( $ticket_id );
    $product_data = $product->get_post_data();

    with

    $product = new WC_Product( $ticket_id );
    $product_data = $product->post_data();

    I get a fatal error, and the page loses the CSS styling:

    Fatal error: Call to undefined method WC_Product::post_data() in /public_html/test_site/wp-content/themes/theme-name/functions.php on line 229

    By the way, I’m using the plugin WooCommerce Email Test to test how the email notifications look.

    Thanks in advance!
    Cintia

    #1367851
    Cliff
    Keymaster

    Hi, Christian.

    We no longer have the WooTickets plugin, but I think you mean Event Tickets Plus (its successor).

    The error you’re seeing comes from this code: https://github.com/woocommerce/woocommerce/blob/3.2.1/includes/legacy/abstract-wc-legacy-product.php#L398

    I’m unsure when this code is running, since I didn’t see an action or filter hook used.

    However, you might want to see what $product is. You may be able to just drop the $product_data = $product->post_data(); line and then update the rest of your code to be compatible with WooCommerce version 3. For example, you’d do $product->get_id()

    You should familiarize yourself with https://github.com/woocommerce/woocommerce/blob/3.2.1/includes/abstracts/abstract-wc-product.php and with https://github.com/woocommerce/woocommerce/blob/3.2.1/includes/abstracts/abstract-wc-data.php

    Please let me know how this goes for you.

    #1368798
    Christian Thomson
    Participant

    Hi Cliff,

    I wasn’t able to figure that out… however I found a code snippet that adds the date to the event in the order details, and that does the trick for me. I got it from here:
    https://theeventscalendar.com/knowledgebase/adding-the-event-date-to-ticket-emails/

    Thanks!
    Cintia

    #1368825
    Cliff
    Keymaster

    Excellent! I’m glad you found and were satisfied with that resource.

    Have a great rest of your week.

Viewing 4 posts - 1 through 4 (of 4 total)
  • The topic ‘WC_Product::get_post_data is deprecated since version 3.0! Use get_post instead.’ is closed to new replies.