There is a line of code that I cannot change within the WooCommerce Template files. This line of code is displayed at the top of the view order page within my account / orders / view order
This is the code displayed in the inspector;
<p>Order #<mark class="order-number">58</mark> was placed on <mark class="order-date">3rd July 2018</mark> and is currently <mark class="order-status">Cancelled</mark>.</p>
And the only code I can find which is similar is in the tracking.php template file;
<p class="order-info"><?php
/* translators: 1: order number 2: order date 3: order status */
echo wp_kses_post( apply_filters( 'woocommerce_order_tracking_status', sprintf(
__( 'Order #%1$s was placed on %2$s and is currently %3$s.', 'woocommerce' ),
'<mark class="order-number">' . $order->get_order_number() . '</mark>',
'<mark class="order-date">' . wc_format_datetime( $order->get_date_created() ) . '</mark>',
'<mark class="order-status">' . wc_get_order_status_name( $order->get_status() ) . '</mark>'
) ) );
?></p>
The problem is that this code has a class on the p tag the one in the inspector doesn't. And if I edit this code there are no changes on the front end. But the code looks the same so I'm not sure if this is the correct template file for this code?
Where can I find this code in the template files or is this the correct file and something is going wrong?
There is another instance here: wp-content\plugins\woocommerce\templates\myaccount\view-order.php on line 30. Is that the what you are looking for?
If you completely comment this section on the WooCommerce plugin file, does it still echos? if yes, it might coming from a template file override, or it's not that file.
If this is the code, you should be able to add filter with the highest priority to change the content.
Related
I am working on a website on WordPress and I’m getting an undefined variable in image url. WordPress automatically links to a random previous post with a picture from that previous link if there is a previous post but this notice keeps popping up on the bottom of my latest post. This does not show up on any other post. It says there is something wrong with the previous post image url. Since it is undefined should I try to define it in the code and include a url and image url from one of my previous posts to see if that works? This is where it says the error is on. And if I do define it myself, what is the code that I should input to create a variable for image url?
previous_post_link( '%link', '<div class="post-navigation-image"><img src="' . $previous_post_image_url . '" /></div><div class="post-navigation-content"><div class="post-navigation-title"><span class="next-post">Next Post ></span><h3>%title</h3></div></div>' );
echo '</div>';
You should add validation to check if the variable exists before trying to use it. If the variable does not exist, then you can assign a default value to that variable which will be used to avoid error.
$previous_post_image_url = !empty($previous_post_image_url) ? $previous_post_image_url : '';
previous_post_link( '%link', '<div class="post-navigation-image"><img src="' . $previous_post_image_url . '" /></div><div class="post-navigation-content"><div class="post-navigation-title"><span class="next-post">Next Post ></span><h3>%title</h3></div></div>' );
echo '</div>';
I'm hoping someone can clue me in on how I can extract a plugin value and display it on my page using a short code. Specifically, when a user reaches the max allowable limit, I would like a notification message to appear on the page (in addition to its placement in a popup) Many tests and I have not been able to get this to work. MANY thanks in advance.
public function add_error_limit_message() {
if ( ! $this->limit_reached ) {
return;
}
$message = apply_filters( 'woocompare_limit_reached_message', __( 'You have reached the maximum number of products for compare table.', 'woocommerce-compare' ) );
echo '<div class="woocompare-error"><p>' . wp_kses_post( $message ) . '</p></div>';
}
add_shortcode( 'limit-reached-message', 'add_error_limit_message' );
Your shortcode function should return the text string you want to insert in place of the shortcode, not echo it.
To track down "critical errors" (php errors) turn on WP_DEBUG and WP_DEBUG_DISPLAY in your wp-config.php file. And try installing and activating the Query Monitor plugin. These will tell you enough about your php errors to track them down and fix them.
I want to be able to add an "li" tag within my product title. To achieve this in a user friendly way I wrote a code which changes the character "-" to an "li" tag. But currently the html does not have an effect on the "order-details-table" (which for example appears when you finished ordering). Is there another filter to add the html globaly so it changes "-" to "li" every time the title occures? --> I updated my code and the html now appeares everywhere, only the following problem is remaining:
In the backend however the html gets added, but gets shown as plain text, so it does not have an effect. Is there also a solution to this problem?
What the product title looks like at the moment --> the html gets interpreted as normal text
add_filter( 'the_title', 'custom_the_title', 10, 2 );
add_filter( 'woocommerce_cart_item_name', 'custom_the_title', 20, 3);
add_filter( 'woocommerce_order_item_name', 'custom_the_title' );
function custom_the_title( $title){
$title = str_replace( '-', '<li>', $title );
$title = str_replace( '.', '</li>', $title );
return $title;
}
Thanks a lot for your help, and greetings from Austria!
Samuel
Are you trying to get something like this? If not, please give more information, what do you expect to see? Any visual example? Where do you want to see those changes?
add_filter( 'the_title', 'custom_the_title', 10, 2 );
add_filter( 'woocommerce_cart_item_name', 'custom_the_title', 20, 3);
function custom_the_title( $title){
$title = '<li>'.$title.'</li>';
return $title;
}
The problem is still presisting even on Wordpress version 5.2.4 and not only on Wordpress 5.5; I have tried the suggested function but it won't work as the html code will always be shown as part of the title text. For instance if I want to add a line break of change a word in the title to red the html tags will just show and the html is not rendered by the browser.
Even with php function html_entity_decode() applied to the title no luck!
So here is the fix:
After checking the code on Woocommerce latest update I found the culprit on the titile.php woocommerce plugin code:
echo esc_html( get_the_title() );
you will need to edit that and remove the esc_html(). But this is temporary as any update on the woocommrce plugin will perhaps return the issue. So I will leave it to experts here to suggest a better solution.
I found the same issue where I'd added some spans to my titles that were suddenly being rendered as text instead of HTML. It was indeed thanks to the addition of an esc_html() around the title in woocommerce/templates/single-product/title.php.
I've fixed it by copying the file to my theme folder under woocommerce/single-product/title.php and simply removing the esc_html(). This is the 'update-proof' solution as it will not be overwritten when WooCommerce next updates.
<h1 class="product_title entry-title">
<?php echo get_the_title(); ?>
</h1>
I'd like to add a tooltip like this in order status, on mouse over:
I tried to use wc_help_tip as follows:
$help_tip = 'Ti do un suggerimento: studia!';
echo wc_help_tip(__($help_tip, 'mypluginname'));
As a result I get a similar behaviour: I display a question mark icon and on mouse over my custom text. I'd like to display my text in the same style as in WooCommerce order status column. Any suggestions?
I solved by myself using data-tip property as follows:
echo '<mark style="margin-bottom:2px;" class="order-status status-on-hold tips" data-tip="' . __('Document not created in MyPluginName', 'mypluginname') . '"><span>'. __('Not saved ', 'mypluginname') . '</span></mark><br />';
I need to display the item price in emails sent to admin and to customers using WooCommerce.
The default templates display Item, Quantity, and Price (item price X quantity). I can add the columns to the tables, but don't know how to get the data from the product.
(It is interesting that this has not been included in the default. I dont think i've ever placed an order online that did not include the single item price.)
This post was helpful, but didn't give me quite all needed:
display tax in woocommerce invoice
It has been a while but this may come handy to someone else.
As far as I am aware, there is no method that returns the unit price, but you can just calculate it by dividing the total price of the item by its quantity like so:
$item->get_total() / $item->get_quantity()
Since this will return just a number, you would probably want to add a currency symbol, so, you would end up with something like this:
<?php echo wc_price($item->get_total() / $item->get_quantity()); ?>
I edited plugins/woocommerce/templates/emails/email-order-items.php
After product name I inserted the price:
<br/>
<strong><?php _e( 'Price', 'woocommerce' ); ?>:</strong>
<?php echo apply_filters( 'woocommerce_cart_item_price', WC()->cart->get_product_price( $_product ), $cart_item, $cart_item_key ); ?>
NB! I put my custom files in directory mytheme/woocommerce/emails/ - without "templates" folder (!). Strange but it's the only way to force them working.
Looks like #Anunja's code up above may no longer work - instead just add the following line underneath Product Name in a copied version of templates/emails/email-order-items.php
echo '<br/>Individual Price $' . $_product->get_price();