In Woocommerce I am using a plugin called YITH WooCommerce PDF Invoice and Shipping List and I would like to add customer note to the PDF invoice.
I would like to add it after the first span line in the code below:
<span class="notes-title"><?php _e( "Notes", "yith-woocommerce-pdf-invoice" ); ?></span>
<div class="notes">
<span><?php echo nl2br( $notes ); ?></span>
<?php do_action( 'yith_ywpi_after_document_notes', $document );?>
</div>
</div>
<?php
But i can't figure out how to get the customer note from $document variable.
I have tried to use this answer thread: "Display Customer order comments (customer note) in Woocommerce" which looks pretty much like the same problem but still could'nt figure it out as $document->order->customer_message; doesn't work.
Any help is appreciated.
Since Woocommerce 3 you can't access anymore properties From the WC_Order object. You need to use the WC_Order method [get_customer_note()][1].
So from the $document (YITH global object) you will use:
$document->order->get_customer_note();
To add customer notes to YITH invoice you can choose between 2 ways:
1) Using the available yith_ywpi_after_document_notes action hook:
add_action( 'yith_ywpi_invoice_template_products_list', 'add_customer_notes_after_document_notes', 5 );
function add_customer_notes_after_document_notes( $document ) {
?><span><?php echo $document->order->get_customer_note(); ?></span><?php
}
Code goes in function.php file of your active child theme (or active theme). Untested (as I dont have the premium version of the plugin) but it should work normally (depending on the plugin settings).
2) Overriding templates (in your provided code):
<span class="notes-title"><?php _e( "Notes", "yith-woocommerce-pdf-invoice" ); ?></span>
<div class="notes">
<span><?php echo nl2br( $notes ); ?></span>
<span><?php echo $document->order->get_customer_note(); ?></span>
<?php do_action( 'yith_ywpi_after_document_notes', $document );?>
</div>
</div>
<?php
It should work.
For the free plugin version
There is no available hooks (like in the provided code)…
The YITH PDF global object need to be called and it's not $document.
So you will be able to use the following code in templates/invoice/invoice-footer.php template:
<?php global $ywpi_document; echo $ywpi_document->order->get_customer_note(); ?>
Related
I'm trying to check if the user is on a specific product page, then if the product is out of stock. If the product is not in stock, I want to display an optional promo image that adds another product to cart.
With the current code I get an error and the page stops rendering when it reaches this snippet.
Right now my code is as follows:
<?php if (! $product->is_in_stock() && is_single('12005') ) { ?>
<div id="oos-promo">
<a href="https://example.com/?add-to-cart=11820&quantity=1">
<img src="https://example.com/wp-content/uploads/2017/07/product.jpg" alt="Promo" class="img-responsive">
</a>
</div>
<?php } ?>
I'm putting this code in the content-single-product.php file nested immediately inside the "entry-summary" element on this template file.
Thoughts?
Figured it out! My mistake was not pulling in the global $product variable prior to the if statement, see final code below:
<?php global $product; if (! $product->is_in_stock() && is_single('12005') ) { ?>
<div id="oos-promo">
<a href="https://example.com/?add-to-cart=11820&quantity=1">
<img src="https://example.com/wp-content/uploads/2017/07/product.jpg" alt="Promo" class="img-responsive">
</a>
</div>
<?php } ?>
Instead of overriding WooCommerce templates you should embed your code in a function hooked in woocommerce_single_product_summary action hook, this way:
add_action( 'woocommerce_single_product_summary', 'out_of_stock_custom_code', 3 );
function out_of_stock_custom_code() {
// Including the WC_Product object
global $product;
if ( ! $product->is_in_stock() && $product->get_id() == 12005 ) {
?>
<div id="oos-promo">
<a href="?add-to-cart=11820&quantity=1">
<img src="https://example.com/wp-content/uploads/2017/07/product.jpg" alt="Promo" class="img-responsive">
</a>
</div>
<?php
}
}
Code goes in any php file of your active child theme (or theme) or also in any plugin php file.
This code Is tested and works.
On my WooCommerce checkout page, I am selling only one product. The checkout page is showing this product and there is ckeckbox next to it, to show the shipping details, when clicked. This is on the default form-checkout.php WooCommerce template.
I would like to have this ckeckbox always selected, to show billing details by default.
I have tried to set:
$checkout = 1;
With no luck so far. The radio button is displayed by the following hook:
<?php do_action( 'woocommerce_checkout_before_customer_details'); ?>
Any help letting me know how I can achieve this will be very helpful.
Thanks.
If you look to the code of checkout/form-shipping.php WooCommerce template, inside the <h3> tag, where the checkbox code is located, there is woocommerce_ship_to_different_address_checked hook that you can use to achieve that. Here is an extract of this code template, that shows it:
?>
<div class="woocommerce-shipping-fields">
<?php if ( true === WC()->cart->needs_shipping_address() ) : ?>
<h3 id="ship-to-different-address">
<label for="ship-to-different-address-checkbox" class="checkbox"><?php _e( 'Ship to a different address?', 'woocommerce' ); ?></label>
<input id="ship-to-different-address-checkbox" class="input-checkbox" <?php checked( apply_filters( 'woocommerce_ship_to_different_address_checked', 'shipping' === get_option( 'woocommerce_ship_to_destination' ) ? 1 : 0 ), 1 ); ?> type="checkbox" name="ship_to_different_address" value="1" />
</h3>
<div class="shipping_address">
So you can use this hook this way, to get this checkbox always selected and displays billing details:
add_filter( 'woocommerce_ship_to_different_address_checked', '__return_true');
This code goes in function.php file of your active child theme (or theme) or also in any plugin file.
The code is tested and fully functional.
I am using magento 1.8.1 and i am trying to display discount percent with sell price on frontend.
with the help of this site discount
i am putting these code:
<?php // Discount percents output start ?>
<?php if($_finalPrice < $_price): ?>
<?php $_savePercent = 100 - round(($_finalPrice / $_price)*100); ?>
<p class="special-price yousave">
<span class="label"><?php echo $this->__('You Save:') ?></span>
<span class="price">
<?php echo $_savePercent; ?>%
</span>
</p>
<?php endif; ?>
in this page: app/design/frontend/yourpackage/yourtheme/template/catalog/product/price.phtml
but after that the result is showing as like this:
Now i am not able to find why "undefined" is showing here and how to remove this.
Please tell me how to remove this.
I seen in your question image you need this effect on product detail page so have to edit media.phtml
app\design\frontend\YOUR_PACKAGE\YOUR_THEME\default\template\catalog\product\view\media.phtml
And in that you have to do same coding to get this value. you can make wrapper class which is override to product image with some dynamic text over product image like as you want.
You can use css like in this page
I think its work...try in this way
hy,
i'm trying to add a link to the new order email that the customer is getting when he is placeing a new order in magento (my version 1.6.2.0 )
i have edited /public_html/app/design/frontend/base/default/template/email/order/items/order/default.phtml
with the following:
<?php $_item = $this->getItem() ?>
<?php $_order = $this->getItem()->getOrder() ?>
----
<!-- Start of edit file -->
<a href="<?php echo $this->getProductUrl($_item) ?>">
<?php echo $this->htmlEscape($this->getSku($_item)) ?></a>
When i receive the confirmation email in the sku column the color changes form black ( default css ) to light blue link like, but it does not have any link property as shown below:
email_photo
I have also tried :
<a href="<?php echo $this->getUrlPath($_item) ?>">
<?php echo $this->htmlEscape($this->getSku($_item)) ?></a>
and i end up with the same thing.
Can anyone tell me what i'm doing wrong ?
Thanks.
In line
<a href="<?php echo $this->getUrlPath($_item) ?>">
$this is an instance of block *Mage_Sales_Block_Order_Email_Items_Order_Default*. It does not have a function getUrlPath() or getProductUrl.
You should use your $_item variable to get a product object and then it to get its URL
$_item->getProduct()->getProductUrl()
I earlier tried this code:
<?php echo $this->htmlEscape($this->getSku($_item)) ?>
Magento 2
To link a product name with its product page in your order emails, edit following files:
Magento_Sales/templates/email/items/order/default.phtml
Magento_Sales/templates/email/items/invoice/default.phtml
Magento_Sales/templates/email/items/shipment/default.phtml
To get the product URL, use the following snippet of code and insert it into a href attribute of the link.
<?= $_item->getProduct()->getProductUrl(); ?>
For example,
<p class="product-name"> <?= $block->escapeHtml($_item->getName()); ?> </p>
The result of the snippet of code will be a clickable product name in Magento Emails.
Tutorial from: https://themes.email/magento/product-links-in-magento-order-emails.html
I have a layout that requires the product description on the reviews page. How can I accomplish this?
Magento version is 1.6
It appears as though the Review page is loading the Product View template just without some of the information; from product/view.phtml:
<div id="product-details">
<?php foreach ($this->getChildGroup('detailed_info', 'getChildHtml') as $alias => $html):?>
<div class="box-collateral <?php echo "box-{$alias}"?>">
<?php echo $html; ?>
</div>
<?php endforeach;?>
</div>
and on the main product view it shows the details here, but on the review view it does not.
What version of Magento? How is the product collection loaded?
You will need to customize one of the templates location in the below, make sure to move into your template and do not edit the base files.
/var/www/vhosts/site.com/www/app/design/frontend/base/default/template/review/
<?php echo $_helper->productAttribute($_product, $_product->getDescription(), 'description') ?>
Is how this is loaded on a standard product view.
You may have to set the $_product variable via <?php $_product = $this->getProduct(); ?> and <?php $_helper = $this->helper('catalog/output'); ?>