Editing the invoice template in Woocommerce - wordpress

I need to edit the Woocommerce invoice template with coding. I Copied all the files from wp-content/plugins/woocommerce-pdf-invoices-packing-slips/templates/Simple to to my child them in wp-content/themes/church-event-child/woocommerce/pdf/yourtemplate and customized them there. I need the template like this:
Subtotal: € 0
IVA: € 0
Order total: € 0
But woocommerce simple template only shows it like this
Subtotal: € 0
Order total: € 0
So it is about adding the IVA with the amount inside. Here you can see the code I am trying to change, but I dont know how to find where the label of the tax_amount is kept and how to display it right.
<table class="totals">
<tfoot>
<?php foreach( $this->get_woocommerce_totals() as $key => $total ) : ?>
<tr class="<?php echo $key; ?>">
<td class="no-borders"></td>
<th class="description"><?php echo $total['label']; ?></th>
<td class="price"><span class="totals-price"><?php echo $total['value']; ?></span></td>
</tr>
<?php endforeach; ?>
</tfoot>
</table>
Thanks in Advance

Related

Customize WooCommerce My Account>Downloads table to display downloadable file links in a single row

I'm attempting to override WooCommerce>Templates>downloads.php to display a custom table that shows the links for multiple downloadable file types in a single row.
My current code is as follows:
'''
<?php
$downloads = WC()->customer->get_downloadable_products();
$has_downloads = (bool) $downloads;
<?php do_action( 'woocommerce_before_account_downloads', $has_downloads ); ?>
<table>
<thead>
<tr>
<th>Title</th>
<th>Version</th>
</tr>
</thead>
<tbody>
<?php while ( $loop->have_posts() ) : $loop->the_post(); ?>
<tr>
<td>
<a class="productLink" href="<?php echo get_permalink( $loop->post->ID ) ?>">
<?php the_title(); ?>
</a>
</td>
<td>
/*This is the bit that doesn't work*/
<?php
$files = $product->get_downloads();
foreach( $files as $key => $each_download ) {
echo 'File Name | ';
}
?>
</td>
</tr>
<?php endwhile; wp_reset_query(); // Remember to reset ?>
</tbody>
</table>
'''
I'm struggling with how to show the downloadable file links with the filenames visible and separated by a vertical line | .

Wordpress add user number field in contact information part

I am wondering how to achieve the following.
I try to create a number field input in the wordpress user profile under contact information.
So far if i use show_user_profile & edit_user_profile hooks, the field will appear on the bottom of the profile page.
Is it possible to create a number field under the contact information part (standard in wordpress?)
I tried to add different priorities to the actions, but that didnt solve it.
So far i have the following:
function addurenuser(){
$userid = get_current_user_id();
if ( current_user_can('update_plugins',$userid)){ ?>
<table class="form-table">
<tr>
<th>
<label>Uren</label>
</th>
<td>
<input type="number" name="uren" id="uren" value="<?php echo esc_attr( get_the_author_meta( 'uren', $user->ID ) ); ?>">
</td>
</tr>
</table> <?php
}
}
add_action( 'show_user_profile', 'addurenuser' );
add_action( 'edit_user_profile', 'addurenuser' );
Use this code
function addurenuser()
{
echo '<script>
jQuery(document).ready(function($){
$(".your-custom-field").insertAfter($(".user-email-wrap").closest("table"));
});
</script>';
$userid = get_current_user_id();
if (current_user_can('update_plugins', $userid)) { ?>
<table class="form-table your-custom-field">
<tr>
<th>
<label>Uren</label>
</th>
<td>
<input type="number" name="uren" id="uren" value="<?php echo esc_attr(get_the_author_meta('uren', $userid->ID)); ?>">
</td>
</tr>
</table> <?php
}
}
add_action('show_user_profile', 'addurenuser');
add_action('edit_user_profile', 'addurenuser');

Retrieving data from customer area wordpress

I'm trying to put on bold the title from some post on wordpress, I have this piece of code for it:
<?php
$title_popup = sprintf(__('Uploaded on %s', 'cuar'), get_the_date());
$file_count = cuar_get_the_attached_file_count($post->ID);
if(strpos(get_the_title(get_the_ID()),'Garajes Gran')!==false){
?>
<tr>
<td class="cuar-title">
<strong><?php the_title(); ?></strong>
</td>
<td class="text-right cuar-file-count">
<span class="label label-rounded label-default"><?php echo sprintf(_n('%1$s file', '%1$s files', $file_count, 'cuar'), $file_count); ?> </span>
</td>
</tr>
<?php
}
And I don't get what I want because all titles appears on black.So what is wrong?. The titles which I have are:
Presupuestos (Garajes Gran Via) 0 files
Presupuestos (Viviendas) 0 files
Contratos (Garajes Gran Via) 5 files
Contratos (Viviendas Gran Vía) 6 files
Contadores de Agua 0 files
Estatutos (Viviendas) 1 file
Estatutos (Garajes Gran Vía)
Thanks so much.
Instead of using the_title(); use get_the_title();
<td class="cuar-title">
<strong><?php echo get_the_title(); ?></strong>
</td>

Add custom cart field to woocommerce

This may be a noob question, but I've googled a lot and haven't found the answer. I've already replaced the woocommerce cart to my child theme subfolder.
I'm trying to add a field to the woocommerce cart, so it will just display the cart subtotal multiplied by a number defined by me. I.e., the cart subtotal is 3,000.00, I want to define the multiplier number 3, so the field I want to show must display 9.000,00.
I've already added the field header to the cart:
<thead>
<tr>
<th class="product-remove"> </th>
<th class="product-quantity"><?php _e( 'Quantity', 'thefoxwp' ); ?></th>
<th class="product-subtotal"><?php _e( 'Total', 'thefoxwp' ); ?></th>
<th class="product-result"><?php _e( 'Total to be Received', 'thefoxwp' ); ?></th>
</tr>
</thead>
The field I want to configure is the class="product-result".
It's not a input field, it will just show the subtotal multiplied by a number defined by me.
I need this information to be sent with the woocommerce email to the client and saved in my order details.
Does anybody know how to do it?
Thanks
Could figure it out.
I added two classes to the header
<thead>
<tr>
<th class="product-remove"> </th>
<th class="product-quantity"><?php _e( 'Quantity', 'thefoxwp' ); ?></th>
<th class="product-subtotal"><?php _e( 'Total', 'thefoxwp' ); ?></th>
<th class="product-tax"><?php _e( 'Exchange Tax', 'thefoxwp' ); ?></th>
<th class="product-result"><?php _e( 'Total to be Received', 'thefoxwp' ); ?></th>
</tr>
</thead>
And then added this code
<!-- Exchange Tax -->
<td class="product-tax">
<?php
$tax = 4.05;
echo "R$ $tax";
?>
</td>
<!-- Product Result -->
<td class="product-result">
<?php
$resultado = WC()->cart->subtotal;
$mostrar = $resultado * $tax;
echo "R$ "; echo number_format("$mostrar",2);
?>
</td>
So it's now echo the result of the cart subtotal * the exchange tax.
But now, how can I get this variable to echo on the email sent by woocommerce and on the checkout page?

$wpdb not work in another page

i create simple plugin , it work in main page , but when i create a link to user go to the another page for see informaation , it show me Fatal error: Uncaught Error: Call to a member function get_results()
my code is :
<?php
global $wpdb;
$results = $wpdb->get_results("SELECT * FROM wp_customers");
?>
<body>
<table>
<tr>
<th>‌ID</th>
<th>Name</th>
<th>Family</th>
<th>Numbers</th>
<th>Tell</th>
</tr>
<?php foreach($results as $results){
?>
<tr>
<td>
<?php echo $results->id; ?>
</td>
<td>
<?php echo $results->name; ?>
</td>
<td>
<?php echo $results->family; ?>
</td>
<td>
<?php echo $results->numbers; ?>
</td>
<td>
<?php echo $results->tell; ?>
</td>
<?php }?>
</tr>
</table>
You need to check you have not set up the database prefix to something other than 'wp_'.
And if you have wp_ prefix in the database then you have to included wp-load file on the custom page.
require( '/path/to/wp-load.php' );
If it's a plugin then you should encapsulate your code in a function and hook this funtion to the wordpress "init" action, so in your plugin file you should have somthing like this :
function your_function_name_here($some_params){
return "some results";
}
add_action('init', 'your_function_name_here');

Resources