I have customized the backorder text on my woocommerce site and would also like to add the same text to the order confirmation emails.
For example, I have my cart and checkout that display "In Stock" or "Made To Order" under the (variation) meta for each product.
To get the result, I added the following code to the cart.php
template file and I added similar code the the review-order.php
template file to get it to show on the checkout page:
// Backorder notification.
if ( $_product->backorders_require_notification() && $_product->is_on_backorder( $cart_item['quantity'] ) ) {
echo wp_kses_post( apply_filters( 'woocommerce_cart_item_backorder_notification', '<p class="cart_stock_notification made-to-order">' . esc_html__( 'Made-To-Order', 'woocommerce' ) . '</p>', $product_id ) );
}
else if ( !$_product->backorders_require_notification() && !$_product->is_on_backorder( $cart_item['quantity'] ) ) {
echo wp_kses_post( apply_filters( 'woocommerce_cart_item_backorder_notification', '<p class="cart_stock_notification made-to-order">' . esc_html__( 'Made-To-Order', 'woocommerce' ) . '</p>', $product_id ) );
}
else {
echo wp_kses_post( apply_filters( 'woocommerce_cart_item_backorder_notification', '<p class="cart_stock_notification in-stock">' . esc_html__( 'In Stock', 'woocommerce' ) . '</p>', $product_id ) );
}
Now I want the same thing to show in my order confirmation emails. I especially want it on the customer emails, but admin emails are fine too.
Right now any back ordered product is coming across in the product meta as "Backordered: #" to denote the number of back ordered products.
I would like to remove that backordered meta and replace it with the same logic used on the cart and checkout pages, so that it will display the same stock status on the emails.
I know that the backordered meta is being applied from the set_backorder_meta
function in the class-wc-order-item-product.php
, but I dont want to edit the class file as it will be overwritten with updates.
I also don't want to just change the text, I need the logic changed. If I can disable set_backorder_meta from applying to the emails, I think I can hook into woocommerce_order_item_meta_end
or just edit the email-order-items.php
template file (either is fine with me).
My problem is that I cannot seem to check if the item "backorders_require_notification" and/or "is_on_backorder".
Is there a way to disable the default backorder meta on the email confirmation and add custom meta that checks if a product is on backorder (and requires backorder notification), then display a custom text?