provide a download link PDF TICKET on the order confirmation page - woocommerce

I work on a project with woocommmerce for a site that sells tickets online I use the fooevent plugin. I would like when a person buys a ticket that he can download it directly on the woocommerce confirmation page. I used the following code for downloading tickets but it does not work
<h1><?php esc_attr_e( 'Tickets', 'fooevents-pdf-tickets' ); ?></h1>
<table>
<?php foreach ( $tickets as $ticket ) : ?>
<?php $product_id = get_post_meta( $ticket->ID, 'WooCommerceEventsProductID', true ); ?>
<?php $woocommerce_events_ticket_id = get_post_meta( $ticket->ID, 'WooCommerceEventsTicketID', true ); ?>
<?php $woocommerce_events_ticket_hash = get_post_meta( $ticket->ID, 'WooCommerceEventsTicketHash', true ); ?>
<?php $ticket_path = ''; ?>
<?php if ( ! empty( $woocommerce_events_ticket_hash ) ) : ?>
<?php $ticket_path = $this->config->pdf_ticket_url . $woocommerce_events_ticket_hash . '-' . $woocommerce_events_ticket_id . '-' . $woocommerce_events_ticket_hash . '-' . $woocommerce_events_ticket_id . '.pdf'; ?>
<?php else : ?>
<?php $ticket_path = $this->config->pdf_ticket_url . $woocommerce_events_ticket_id . '-' . $woocommerce_events_ticket_id . '.pdf'; ?>
<?php endif; ?>
<tr>
<td><?php echo esc_attr( $ticket->post_title ); ?></td>
<td><?php echo esc_attr( get_the_title( $product_id ) ); ?></td>
<td><?php esc_attr_e( 'Download', 'fooevents-pdf-tickets' ); ?></td>
</tr> <?php endforeach; ?></table>

Related

Get ACF Taxonomy selection in Block and display fields

Figured this would be pretty easy but I am running into an issue.
The website I am building, the client has a list of taxonomies that have an ACF Image Field and ACF Description field.
What they want to do is have a block where they can select certain ingredients from the Taxonomy Block, then have it render out formatted (on a page)(At this time it doesnt need to link to the actual category) but they want to do it this way so they dont need to update page by page when an ingredient changes description or image they can just change it in the taxonomy list.
Below is the code i am using to try and get it going from the docs, it wont render the name or original description it will render the slug but skips over the name but the slug is correct
I've been trying this with no luck, it just returns 3 li's which is correct but i can get a name or custom field to come through.
If i just the the_field('ingredients_selector'); I get the ID's just fine But for the life of me i can not get a term name or the ACF field attached to it/
$terms = get_field('ingredients_selector');
if ( ! empty( $terms ) && ! is_wp_error( $terms ) ){
echo '<ul class="ingredients-list">';
foreach ( $terms as $term ) {
echo '<li class="ingredients-list__item">' . $term->name . '</li>'; ?>
<p>Description: <?php the_field('description', $term); ?></p>
<p>Image: <?php the_field('image', $term); ?></p>
<?php }
echo '</ul>';
}
?>
I've also tried this way, this gives me same reuslt but the slug with work, it will skip term name again but "view all" will link at least
<?php
$terms = get_field('ingredients_selector');
if( $terms ): ?>
<ul>
<?php foreach( $terms as $term ): ?>
<li>
<h2><?php echo esc_html( $term->name ); ?></h2>
<p>Term description: <?php the_field('description', $term); ?></p>
<p>Term Image: <?php the_field('image', $term); ?></p>
<p><?php echo esc_html( $term->description ); ?></p>
View all '<?php echo esc_html( $term->name ); ?>' posts
</li>
<?php endforeach; ?>
</ul>
<?php endif; ?>
Attached is my set up of the ACF fields
EDIT****
This was my solution
<?php
$tax = 'ingredients';
$terms = get_terms( $tax, $args = array(
'hide_empty' => false, // do not hide empty terms
));
foreach( $terms as $term ) {
$term_link = get_term_link( $term );
$image = get_field('image', 'ingredients_' . $term->term_id );
$description = get_field('description', 'ingredients_' . $term->term_id );
if( $term->count > 0 ) {
echo '<a href="' . esc_url( $term_link ) . '">';
echo '<img src="' . $image['url'] . '" alt="' . $image['alt'] .'">';
echo $term->name .'</a>';
echo $description;
} elseif( $term->count !== 0 ) {
echo '' . $term->name .'';
}
}
?>
Try this and replace term_name_ with your actual term slug:
<?php
$terms = get_field('ingredients_selector');
if( $terms ): ?>
<ul>
<?php foreach( $terms as $term ): ?>
<li>
<h2><?php echo esc_html( $term->name ); ?></h2>
<p>Term description: <?php the_field('description', 'term_name_'.$term->term_id); ?></p>
<p>Term Image: <?php the_field('image', 'term_name_'.$term->term_id); ?></p>
<p><?php echo esc_html( $term->description ); ?></p>
View all '<?php echo esc_html( $term->name ); ?>' posts
</li>
<?php endforeach; ?>
</ul>
<?php endif; ?>
You can find more about this here.

Can't show the product name on table using get_name();

I can't echo the product name on my order page. I'm using ultimate member plugin with WooCommerce. "get_id();" is working just fine. I used "$order->get_name()" to echo the ordered product name. but it shows me error when tried to load the page.
<tbody>
<?php
foreach( $customer_orders as $customer_order ) {
$order = wc_get_order( $customer_order->ID );
$order_id = $customer_order->ID;
$order_data = $order->get_data();
$order_date = strtotime( $order->get_date_created() );
?>
<tr class="order" data-order_id="<?php echo esc_attr( $order_id ); ?>">
<?php do_action( 'um_woocommerce_orders_tab_before_table_row', $order, $customer_orders ); ?>
<td class="order-total" data-title="<?php _e( 'Item', 'um-woocommerce' ); ?>">
<?php echo $order->get_name() ?></td>
<td class="order-date" data-title="<?php _e( 'Date', 'um-woocommerce' ); ?>">
<time
datetime="<?php echo wp_date( 'Y-m-d', $order_date ); ?>"><?php echo wp_date( $date_time_format, $order_date ); ?></time>
</td>
<td class="order-status" data-title="<?php _e( 'Status', 'um-woocommerce' ); ?>">
<span
class="um-woo-status <?php echo $order->get_status(); ?>"><?php echo wc_get_order_status_name( $order->get_status() ); ?></span>
</td>
<td class="order-total" data-title="<?php _e( 'Total', 'um-woocommerce' ); ?>">
<?php echo $order->get_formatted_order_total() ?></td>
<td class="order-detail">
<a href="<?php echo esc_url( "$url#$order_id" ); ?>" class="um-woo-view-order um-tip-n"
title="<?php esc_attr_e( 'View order', 'um-woocommerce' ); ?>"><i class="um-icon-eye"></i></a>
<?php do_action( 'um_woocommerce_orders_tab_actions', $order, $customer_orders ); ?>
</td>
<?php
if ( UM()->options()->get('woo_account_order_ations') ) {
$actions = wc_get_account_orders_actions( $order );
echo '<td class="order-actions">';
if ( !empty( $actions ) ) {
foreach ( $actions as $key => $action ) {
echo '' . esc_html( $action['name'] ) . '';
}
}
echo '</td>';
}
?>
<?php do_action( 'um_woocommerce_orders_tab_after_table_row', $order, $customer_orders ); ?>
</tr>
<?php } ?>
</tbody>
There is no get_name() function for order object. You need loop through the order items to get the product object and use the $product->get_name() function
<?php foreach ($order->get_items() as $item_key => $item) {
$product = $item->get_product();
?>
<td class="order-total" data-title="<?php _e( 'Item', 'um-woocommerce' ); ?>">
<?php echo $product->get_name() ?>
</td>
<?php } ?>

Display shipping for each products on invoice - Woocommerce

I want to show a shipping row on invoice because I use the plugin "Multiple Packages for WooCommerce". Indeed for each product the customer can choose "livraison express (25€)" or "Livraison Franco de port" (0€).
Currently my invoice looks like this
So I wish it looked like this :
The shipping method above each products and only the amount of delivery in the row of total.
In the file "invoice.php", I Have this :
<tbody>
<?php $items = $this->get_order_items(); if( sizeof( $items ) > 0 ) : foreach( $items as $item_id => $item ) : ?>
<tr class="<?php echo apply_filters( 'wpo_wcpdf_item_row_class', $item_id, $this->type, $this->order, $item_id ); ?>">
<td class="product">
<?php $description_label = __( 'Description', 'woocommerce-pdf-invoices-packing-slips' ); // registering alternate label translation ?>
<span class="item-name"><?php echo $item['name']; ?></span>
<?php do_action( 'wpo_wcpdf_before_item_meta', $this->type, $item, $this->order ); ?>
<span class="item-meta"><?php echo $item['meta']; ?></span>
<dl class="meta">
<?php $description_label = __( 'SKU', 'woocommerce-pdf-invoices-packing-slips' ); // registering alternate label translation ?>
<?php if( !empty( $item['sku'] ) ) : ?><dt class="sku"><?php _e( 'Référence :', 'woocommerce-pdf-invoices-packing-slips' ); ?></dt><dd class="sku"><?php echo $item['sku']; ?></dd><?php endif; ?></dl>
<?php do_action( 'wpo_wcpdf_after_item_meta', $this->type, $item, $this->order ); ?>
</td>
<td class="quantity"><?php echo $item['quantity']; ?></td>
<td class="price"><?php echo $item['order_price']; ?></td>
</tr>
<?php endforeach; endif; ?>
</tbody>
So I try to add this code
<?php echo $order->get_shipping_to_display(); ?>
Like this
<dl class="meta">
<?php $description_label = __( 'SKU', 'woocommerce-pdf-invoices-packing-slips' ); // registering alternate label translation ?>
<?php if( !empty( $item['sku'] ) ) : ?><dt class="sku"><?php _e( 'Référence :', 'woocommerce-pdf-invoices-packing-slips' ); ?></dt><dd class="sku"><?php echo $item['sku']; ?></dd><?php endif; ?>
<?php /*if( !empty( $item['weight'] ) ) : ?><dt class="weight"><?php _e( 'Weight:', 'woocommerce-pdf-invoices-packing-slips' ); ?></dt><dd class="weight"><?php echo $item['weight']; ?><?php echo get_option('woocommerce_weight_unit'); ?></dd><?php endif;*/ ?>
<dt class="sku"><?php_e( 'Livraison :', 'woocommerce-pdf-invoices-packing-slips' ); ?></dt><dd class="sku">
<?php echo $order->get_shipping_to_display(); ?></dd></dl>
but i get this :
So I understand that this code call the shipping for the order and not for the item but if I try <?php echo $item->get_shipping_to_display(); ?> I have an error.
Is someone can help me?

Displaying product category names in the WordPress order table (Woocommerce) [duplicate]

This question already has an answer here:
Show product categories in a new column on WooCommerce "My account" orders table
(1 answer)
Closed 1 year ago.
There are orders that have already been completed or not, and they contain goods, clothing, courses, etc. In WordPress, I have all the products subdivided into categories, but I don't know how to display the names of these categories. Suppose I have an order from a T-shirt and some course, and in the category I have to display "Clothes, Courses" (In the picture below, it is marked in red where it is necessary to display). I was able to display only the "Categories" tab, but the categories themselves cannot be displayed at all :( Here is the code from the orders.php file
<table class="woocommerce-orders-table woocommerce-MyAccount-orders shop_table shop_table_responsive my_account_orders account-orders-table">
<thead>
<tr>
<?php foreach ( wc_get_account_orders_columns() as $column_id => $column_name ) : ?>
<th class="woocommerce-orders-table__header woocommerce-orders-table__header-<?php echo esc_attr( $column_id ); ?>"><span class="nobr"><?php echo esc_html( $column_name ); ?></span></th>
<?php endforeach; ?>
</tr>
</thead>
<tbody>
<?php
foreach ( $customer_orders->orders as $customer_order ) {
$order = wc_get_order( $customer_order ); // phpcs:ignore WordPress.WP.GlobalVariablesOverride.Prohibited
$item_count = $order->get_item_count() - $order->get_item_count_refunded();
?>
<tr class="woocommerce-orders-table__row woocommerce-orders-table__row--status-<?php echo esc_attr( $order->get_status() ); ?> order">
<?php foreach ( wc_get_account_orders_columns() as $column_id => $column_name ) : ?>
<td class="woocommerce-orders-table__cell woocommerce-orders-table__cell-<?php echo esc_attr( $column_id ); ?>" data-title="<?php echo esc_attr( $column_name ); ?>">
<?php if ( has_action( 'woocommerce_my_account_my_orders_column_' . $column_id ) ) : ?>
<?php do_action( 'woocommerce_my_account_my_orders_column_' . $column_id, $order ); ?>
<?php elseif ( 'order-number' === $column_id ) : ?>
<a href="<?php echo esc_url( $order->get_view_order_url() ); ?>">
<?php echo esc_html( _x( '#', 'hash before order number', 'woocommerce' ) . $order->get_order_number() ); ?>
</a>
<?php elseif ( 'order-cat' === $column_id ) : ?>
<?php elseif ( 'order-date' === $column_id ) : ?>
<time datetime="<?php echo esc_attr( $order->get_date_created()->date( 'c' ) ); ?>"><?php echo esc_html( wc_format_datetime( $order->get_date_created() ) ); ?></time>
<?php elseif ( 'order-status' === $column_id ) : ?>
<?php echo esc_html( wc_get_order_status_name( $order->get_status() ) ); ?>
<?php elseif ( 'order-total' === $column_id ) : ?>
<?php
/* translators: 1: formatted order total 2: total order items */
echo wp_kses_post( sprintf( _n( '%1$s for %2$s item', '%1$s for %2$s items', $item_count, 'woocommerce' ), $order->get_formatted_order_total(), $item_count ) );
?>
<?php elseif ( 'order-actions' === $column_id ) : ?>
<?php
$actions = wc_get_account_orders_actions( $order );
if ( ! empty( $actions ) ) {
foreach ( $actions as $key => $action ) { // phpcs:ignore WordPress.WP.GlobalVariablesOverride.Prohibited
echo '' . esc_html( $action['name'] ) . '';
}
}
?>
<?php endif; ?>
</td>
<?php endforeach; ?>
</tr>
<?php
}
?>
</tbody>
</table>
And here is the picture:
enter image description here
$items = $order->get_items();
$cats = '';
foreach($items as $key => $item) {
$product_id = $item['product_id'];
$term_obj_list = get_the_terms($product_id, 'product_cat');
$terms_string = implode(', ', wp_list_pluck($term_obj_list, 'name'));
$cats .= $terms_string;
}
echo $cats;
Put this in correct elseif block of your given code.
Updated according to the comment with code comment:
//Getting all the items in the order
$items = $order->get_items();
$c_list = [];
/**
* Loop through all items and get their categories [a product can have multiple category]
*/
foreach($items as $key => $item) {
//We need the product id to retrieved the categories
$product_id = $item['product_id'];
//Retrieving all the categories that product has
$term_obj_list = get_the_terms($product_id, 'product_cat');
//Loop through all the categories the current product has and saving it in a array with category id as index
//so that if the save category is assigned to another product we do not get the duplicate category
foreach($term_obj_list as $term_obj) {
$c_list[$term_obj->term_id] = $term_obj->name;
}
}
//lastly we concatenating all the categories with ", "
$cats = implode(', ', $c_list);
//printing the final result
echo $cats;

Displayed all user orders on my-account order history, but it warn me 'invalid order'. Woocommerce

I am trying to display all the order on the admin order history page (including order customers's order). So that the admin can view the orders on the front end.
And I am trying to modify the template - my-order.php to show the orders on this page. However, I displayed a list of all orders, but when I clicked into the order, it said that Invalid order(Which is not admin own order).
/**my-order.php**/
$customer_orders = get_posts( apply_filters( 'wo<?php foreach ( $customer_orders as $k => $v) :
$order = wc_get_order( $customer_orders[ $k ]->ID );
$item_count = $order->get_item_count();
?>
<tr class="order">
<?php foreach ( wc_get_account_orders_columns() as $column_id => $column_name ) : ?>
<td class="<?php echo esc_attr( $column_id ); ?>" data-title="<?php echo esc_attr( $column_name ); ?>">
<?php if ( has_action( 'woocommerce_my_account_my_orders_column_' . $column_id ) ) : ?>
<?php do_action( 'woocommerce_my_account_my_orders_column_' . $column_id, $order ); ?>
<?php elseif ( 'order-number' === $column_id ) : ?>
<a href="<?php echo esc_url( $order->get_view_order_url() ); ?>">
<?php echo _x( '#', 'hash before order number', 'woocommerce' ) . $order->get_order_number(); ?>
</a>
How do I display all the orders the order history?
Thanks for helping.

Resources