Remove Downloads section from Woocommerce order refunded email - php

I have seen this snippet which removes from all customer emails, however I'm wondering how to remove the downloads section from the Woocommerce email: Order Refunded.
add_action( 'woocommerce_email', 'remove_order_downloads_from_emails', 10, 1 );
function remove_order_downloads_from_emails( $emails ){
remove_action( 'woocommerce_email_order_details', array( $emails, 'order_downloads' ), 10 );
}
Any help much appreciated.

The following code will remove the downloads table section from Refunded order email notification:
add_action( 'woocommerce_email_order_details', 'remove_downloads_section_from_refunded_order_emails', 1, 4 );
function remove_downloads_section_from_refunded_order_emails( $order, $sent_to_admin, $plain_text, $email ){
if( $email->id === 'customer_refunded_order' )
remove_action( 'woocommerce_email_order_details', array( WC()->mailer(), 'order_downloads' ), 10 );
}
Code goes in function.php file of your active child theme (or active theme). Tested and works.

Related

Remove WooCommerce messages from account content

I'm currently trying to remove all messages from the WooCommerce account with the following code line:
remove_action( 'woocommerce_account_content', 'woocommerce_output_all_notices', 10 );
Sadly, the wrapper for messages is still there:
<div class="woocommerce-notices-wrapper">lol</div>
I've added a lol to the function that displays the wrapper and it's the correct function I'm trying to remove. No idea why it's not working...
If your active theme uses the default woocommerce templates and hooks for myaccount pages, then add the follows code snippet to achieve the above -
function modify_wc_hooks() {
// remove all wc my account's notices wrapper
remove_action( 'woocommerce_account_content', 'woocommerce_output_all_notices', 5 );
remove_action( 'woocommerce_before_customer_login_form', 'woocommerce_output_all_notices', 10 );
remove_action( 'woocommerce_before_lost_password_form', 'woocommerce_output_all_notices', 10 );
remove_action( 'before_woocommerce_pay', 'woocommerce_output_all_notices', 10 );
remove_action( 'woocommerce_before_reset_password_form', 'woocommerce_output_all_notices', 10 );
}
add_action( 'init', 'modify_wc_hooks', 99 );
Codes goes to your active theme's functions.php

Move additional information from product tab under add to cart button in WooCommerce

In single product pages, I would like to change the location of "additional information" from tabs, under add to cart button using Woocommerce hooks (removing the "additional information" tab).
I have:
add_action( 'woocommerce_product_additional_information', 'wc_display_product_attributes', 10 );
and: woocommerce_after_add_to_cart_button
I'm trying:
remove_action( 'woocommerce_product_additional_information', 'wc_display_product_attributes', 10 );
add_action( 'woocommerce_after_add_to_cart_button', 'woocommerce_product_additional_information' );
and
remove_action( 'woocommerce_product_additional_information', 'wc_display_product_attributes', 10 );
add_action( 'woocommerce_single_product_summary', 'woocommerce_product_additional_information', 60 );
But it doesn't work.
How can I move properly "additional information" below add to cart button?
The following code will remove additional information tab and add additional information below add to cart:
// Remove additional information tab
add_filter( 'woocommerce_product_tabs', 'remove_additional_information_tab', 100, 1 );
function remove_additional_information_tab( $tabs ) {
unset($tabs['additional_information']);
return $tabs;
}
// Add "additional information" after add to cart
add_action( 'woocommerce_single_product_summary', 'additional_info_under_add_to_cart', 35 );
function additional_info_under_add_to_cart() {
global $product;
if ( $product && ( $product->has_attributes() || apply_filters( 'wc_product_enable_dimensions_display', $product->has_weight() || $product->has_dimensions() ) ) ) {
wc_display_product_attributes( $product );
}
}
Code goes in function.php file of your active child theme (or active theme). Tested and works.

Remove single product tabs and add the related content instead In Woocommerce

I have a client who wants to pull the information that defaults into tabs on single product pages in WooCommerce into a different location on the page and remove the tabs entirely.
There are three default product tabs:
product Description,
Additional Information
and Reviews.
Removing the tabs and setting up the Description to display was easy enough to set up in
/wp-content/plugins/woocommerce/includes/wc-template-hooks.php:
remove_action( 'woocommerce_after_single_product_summary', 'woocommerce_output_product_data_tabs', 10 );
function woocommerce_template_product_description() {
woocommerce_get_template( 'single-product/tabs/description.php' );
}
add_action( 'woocommerce_after_single_product_summary', 'woocommerce_template_product_description', 10 );
That works fine.
I tried to repeat the process by building out new functions that access the template files for Additional Info and Reviews like so:
function woocommerce_template_product_addinfo() {
woocommerce_get_template( 'single-product/tabs/additional-information.php' );
}
add_action( 'woocommerce_after_single_product_summary', 'woocommerce_template_product_addinfo', 20 );
function woocommerce_template_product_reviews() {
woocommerce_get_template( 'single-product/review-rating.php' );
}
add_action( 'woocommerce_after_single_product_summary', 'woocommerce_template_product_reviews', 30 );
But neither is displaying. What am I doing wrong here?
First woocommerce_get_template() is deprecated and replaced by wc_get_template() instead. After some searching and testing (mainly to get the reviews displayed), I have found the way:
add_action( 'woocommerce_after_single_product_summary', 'removing_product_tabs', 2 );
function removing_product_tabs(){
remove_action( 'woocommerce_after_single_product_summary', 'woocommerce_output_product_data_tabs', 10 );
add_action( 'woocommerce_after_single_product_summary', 'get_product_tab_templates_displayed', 10 );
}
function get_product_tab_templates_displayed() {
wc_get_template( 'single-product/tabs/description.php' );
wc_get_template( 'single-product/tabs/additional-information.php' );
comments_template();
}
Code goes in function.php file of your active child theme (or theme). Tested and work (WC 3+).

remove shipping and billing from woocommerce email

I want to remove the billing address and shipping address from the admin-new-order.php. I already have a duplicate of it in my theme. I was able to remove the email and phone number, but I just cant remove the billing and shipping.
To remove the email and phone I did this
add_filter( 'woocommerce_email_customer_details_fields', 'custom_woocommerce_email_customer_details_fields' );
function custom_woocommerce_email_customer_details_fields( $totals ) {
unset(
$totals['billing_email'],
$totals['billing_phone']
);
return $totals;
}
I know that if I completely removed:
do_action( 'woocommerce_email_customer_details', $order, $sent_to_admin, $plain_text, $email );
it would remove everything, but I can't do that because I need the notes, and delivery times (from a plugin) that displays there. If I delete the whole thing then it deletes everything.
I've tried
unset($totals['billing_first_name']);
And so many variations of this but it doesn't work.
enter image description here
In all email templates you have below do action hook. WC_Emails::email_address() this function code is used for add billing and shipping details in mails.
/**
* #hooked WC_Emails::customer_details() Shows customer details
* #hooked WC_Emails::email_address() Shows email address
*/
do_action( 'woocommerce_email_customer_details', $order, $sent_to_admin, $plain_text, $email );
For remove the billing and shipping detail from mail put bellow function in your function.php file
function removing_customer_details_in_emails( $order, $sent_to_admin, $plain_text, $email ){
$wmail = WC()->mailer();
remove_action( 'woocommerce_email_customer_details', array( $wmail, 'email_addresses' ), 20, 3 );
}
add_action( 'woocommerce_email_customer_details', 'removing_customer_details_in_emails', 5, 4 );

Removing customer details and addresses from email notification templates

I am working on a theme created for woocommerce, built by some other German developer. I have created my child theme and using child theme's functions.php to make changes to functionality of the website.
When a customer orders a product, he receives an email with order table, customer information and billing address and customer shipping.
I want to remove everything below the table and add my own text (customer info + billing, shipping and pick up address as well).
I have added my own text right below the order table in email that goes to customer, however I am unable to delete the information that shows by default below my custom added text. I found the hook responsible for fetching and showing that data is woocommerce_email_order_meta, but I don't know how to remove it or prevent it from executing. I don't want to make changes in the template files, I want to do it all by hooks.
So far I have tried doing it like this:
remove_action( 'woocommerce_email_order_meta', $order, $sent_to_admin, $plain_text, $email );
I followed the link: Delete order info section from email template in woocommerce and tried the following code as well, but didn't work.
function so_39251827_remove_order_details( $order, $sent_to_admin, $plain_text, $email ){
$mailer = WC()->mailer(); // get the instance of the WC_Emails class
remove_action( 'woocommerce_email_order_details', array( $mailer, 'order_details' ), 10, 4 );
}
add_action( 'woocommerce_email_order_details', 'so_39251827_remove_order_details', 5, 4 );
How can I achieve this?
Explanations - In all email notification templates you have this:
/**
* #hooked WC_Emails::customer_details() Shows customer details
* #hooked WC_Emails::email_address() Shows email address
*/
do_action( 'woocommerce_email_customer_details', $order, $sent_to_admin, $plain_text, $email );
After some research in WooCommerce core files and some test, I have removed successfully the customer details, the billing and shipping address from notification emails as you wished.
Here is the code:
add_action( 'woocommerce_email_customer_details', 'removing_customer_details_in_emails', 5, 4 );
function removing_customer_details_in_emails( $order, $sent_to_admin, $plain_text, $email ){
$mailer = WC()->mailer();
remove_action( 'woocommerce_email_customer_details', array( $mailer, 'customer_details' ), 10 );
remove_action( 'woocommerce_email_customer_details', array( $mailer, 'email_addresses' ), 20 );
}
This code goes in function.php file of your active child theme (or theme) or also in any plugin file.
This code is tested and fully functional.
References :
Class WC_Emails customer_details() method
Class WC_Emails email_addresses() method

Categories