How to display woocommerce sale price or regular price if there is no sale price

I’m using a woocommerce product addons plugin where I would like to display the price of a product in my dropdown section of the addons.
Currently the code I have is this

$loop = 0;
$current_value = isset( $_POST['addon-' . sanitize_title( $addon['field-name'] ) ] ) ? wc_clean( $_POST[ 'addon-' . sanitize_title( $addon['field-name'] ) ] ) : '';
global $product;
<p class="form-row form-row-wide addon-wrap-<?php echo sanitize_title( $addon['field-name'] ); ?>">
    <select class="addon addon-select" name="addon-<?php echo sanitize_title( $addon['field-name'] ); ?>">

        <?php if ( ! isset( $addon['required'] ) ) : ?>
            <option value=""><?php _e('None', 'woocommerce-product-addons'); ?></option>
        <?php else : ?>
            <!--<option value=""><?php _e('Select an option...', 'woocommerce-product-addons'); ?></option>-->
        <?php endif; ?>

        <?php foreach ( $addon['options'] as $i => $option ) :
            $loop ++;
            $price = apply_filters( 'woocommerce_product_addons_option_price',
                $option['price'] > 0 ? ' + ' . wc_price( get_product_addon_price_for_display( $option['price'] ) ) . '' : '',
            <option data-raw-price="<?php echo esc_attr( $option['price'] ); ?>" data-price="<?php echo get_product_addon_price_for_display( $option['price'] ); ?>" value="<?php echo sanitize_title( $option['label'] ) . '-' . $loop; ?>" <?php selected( $current_value, sanitize_title( $option['label'] ) . '-' . $loop ); ?>><?php echo wptexturize( $option['label'] . ' (' ); echo balanceTags($product->get_price_html()) . $price ?>)</option>
        <?php endforeach; ?>


I’m using this echo


what this does though is display the $”sale price” $”price” but I just want to display just the sale price or just the product price if there is no sale price. Looking at the code below, how would I accomplish this?


Source: stackoverflow-php

WooCommerce – Can’t attach more than 3 pdf files to email

I would like to attach a few pdfs to my custom welcome email. Each pdf has the exact same size of about 2Mb. The email is sent if I don’t attach more than 3 pdfs.

 function attach_coupons_pdf_to_email($attachments, $status, $order)
    the_log("n " . $status .  " n");
    if (isset($status) && strcmp($status, "wc_welcome") == 0)
        array_push($attachments, trailingslashit(ABSPATH) . "coupons/gutschein-1488685005124.pdf");
        array_push($attachments, trailingslashit(ABSPATH) . "coupons/gutschein-1488704520421.pdf");
        array_push($attachments, trailingslashit(ABSPATH) . "coupons/gutschein-1488704521893.pdf");
      //  array_push($attachments, trailingslashit(ABSPATH) . "coupons/gutschein-1488704520454.pdf"); Doesn't send anymore
    return $attachments;

add_filter('woocommerce_email_attachments', 'attach_coupons_pdf_to_email', 2, 3);

I can’t believe that I can’t attach more than about 6Mb to an email. The maximum upload size of my webhoster is 200Mb and the memory_limit is 256Mb.

Do you know of any other restrictions concerning file attachments?

Source: stackoverflow-php

Manipulate woocommerce_order_get_items name

I tried to figure out how to remove the () if the orderline’s name has those parentes.

Here is the code:

$order = wc_get_order($order_id)
foreach ( $order->get_items() as $order_item ){
   //...enter code here

But i want to use hooks/filters since i don’t have access to the foreach above. I tried to add to functions.php so when get_items() calls, the filter will prepare the data array.

add_filter( 'woocommerce_order_get_items', 'filter_woocommerce_order_get_items', 10, 2 ); 
function filter_woocommerce_order_get_items($items, $instance){
    foreach ($items as $item){
        $item['name'] = strtr($item['name'], "", "()");

    return $items;

So, TL;DR:
Can i prepare data when $order->get_items() calls?

Source: stackoverflow-php

Extract URL from order note and add it only to order completed email in Woocommerce

I’ve searched around here and some posts helped me almost nailing this problem:

My parcel company adds an order note to the order including text and an tracking url for the package. And after that they put the order on completed.

This URL needs to be added to the order completed mail to the customer.

This code is working but only if I send the order completed mail manually:

add_action( 'woocommerce_email_before_order_table', 'woo_add_order_notes_to_email' );
function woo_add_order_notes_to_email() {
    global $woocommerce, $post;
    $args = array(
        'post_id'   => $post->ID,
        'status'    => 'approve',
        'type'      => 'order_note'
    $notes = get_comments( $args );

    if ( $notes ) {
        foreach( $notes as $note ) {
            $notecontent = $note->comment_content;

            if( preg_match('/[a-zA-Z]+://[0-9a-zA-Z;./?:@=_#&%~,+$-]+/', $notecontent, $matches) != 0 ) {

                echo '<p>You can follow your order via this link: <a href = "' . $matches[0] . '">' . $matches[0] . '</a></p>';




I hope you guys can help me out.

Source: stackoverflow-php

Woocommerce caches cart (Combined with W3 Total Cache)

I’ve experienced a weird issue on a site using WordPress + Woocommerce recenty. The site uses W3 Total Cache for page cache and browser cache and although i’ve set the woocommerce_cart_items cookie in the rejected list for page cache, the front page is beeing cached .
As a result i’ve issues with the cart ,empty on front page as is served as static, in other shop pages are regenerated and everything is fine.
To my understanding, pages are supposed to be cached if the cookie woocommerce_cart_items is missing ( so we have a guest customer browsing ), and after a product is added in the cart, woocommerce created a session and the cookie is stored so next time the frontpage is called it’s beeing regenerated and not served as static, is that right?
Is there a way to ensure this functionality?

Is this affected depending on the caching option selected (disk, apcu …)? if i decide to use redis for page cache , which is the best way to exclude such things from beeing cached?

Source: stackoverflow-php