Home › Forums › Ticket Products › Event Tickets Plus › WC_Product::get_post_data is deprecated since version 3.0! Use get_post instead.
- This topic has 4 replies, 3 voices, and was last updated 8 years, 6 months ago by
Cliff.
-
AuthorPosts
-
October 21, 2017 at 10:30 am #1367201
Christian Thomson
ParticipantHi 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!
CintiaOctober 23, 2017 at 8:32 pm #1367851Cliff
MemberHi, 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.
October 25, 2017 at 10:43 am #1368798Christian Thomson
ParticipantHi 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!
CintiaOctober 25, 2017 at 11:19 am #1368825Cliff
MemberExcellent! I’m glad you found and were satisfied with that resource.
Have a great rest of your week.
-
AuthorPosts
- The topic ‘WC_Product::get_post_data is deprecated since version 3.0! Use get_post instead.’ is closed to new replies.
