Is there a filter or hook t change the WC_Tax::get_rate_label( $key ) in woocommerce? - email

I am trying to change the Tax label on the cart, checkout order-review and email.
I have tried to create a function with 'woocommerce_get_order_item_totals' and also with 'woocommerce_get_formatted_order_total' No luck. It either remove all or adds a new line but changing the $tax_totals[ $code ]->label
I have a checkbox which gives customers to possibility to apply Tax-exempt for the order. This is all working very good.
If selected it will set TAX Amount to 0.00 but the label keeps on VAT or TAX or BTW (Dutch label)
I added zero-rates in the backend,
Phrase matches used to identify VAT (VAT, V.A.T, IVA, I.V.A., Value Added Tax, TVA, T.V.A., BTW, B.T.W., Tax Exempt, vrijgesteld van BTW)
I added zero-rate by country code
GB Tax Exempt (0%)
NL vrijgesteld van BTW (0%)
And still it shows on the cart, checkout, order-review and email as VAT or(BTW) whatever the country is.
This is what I want to change

I have been looking already for days to find a working solution with no luck.
But I found a solution just now, not sure if it is a hack or good coding but it works for me.
I have this code inside my function.
add_action( woocommerce_checkout_update_order_review','taxexempt_checkout_based_on_checkbox');
function taxexempt_checkout_based_on_checkbox( $post_data) {
global $woocommerce;
$woocommerce->customer->set_is_vat_exempt( false );
parse_str($post_data);
if ( $billing_taxexempt === '1' && $billing_confirmed === '1' &&
!empty($billing_signature) && ! empty($billing_declaration)){
$woocommerce->customer->set_is_vat_exempt( true );
}
}
This will apply the tax-exempt to the order.
I added a filter to this just below ....set_is_vat_exempt( true )..
add_filter( 'woocommerce_countries_tax_or_vat', function () { return __( 'Tax Exempt', 'woocommerce' ); });
And I added a function I found //Change "Billing Details" text to "Shipping Details" on Woocommerce checkout page
I changed it a little bit but it works for me.
function wc_change_field_strings( $translated_text, $text, $domain ) {
$language = get_locale();
$domain = 'woocommerce';
if($language == 'en_GB' ){
switch ( $translated_text ) {
case 'Tax Exempt' :
$translated_text = __( 'Tax Exempt', $domain );
break;
}
return $translated_text;
}
if($language == 'nl_NL' ){
switch ( $translated_text ) {
case 'Tax Exempt' :
$translated_text = __( 'vrijgesteld van BTW', $domain);
break;
}
return $translated_text;
}
}
add_filter( 'gettext', 'wc_change_field_strings', 20, 3 );
Have to add the default case, will do later but it works for, this solution.
Maybe it will work for somebody else or if you have a better solution, let me know.
And the result looks like this.

Related

WooCommerce pdf attachment to custom email is not working

I am using WooCommerce order status manager plugin for custom order statuses and emails notifications. I have created custom status for paid orders via card pay - card-on-hold.
I have also created custom email which will be triggered when statuses will change from receivet to card-on-hold.
my code is:
add_filter( 'woocommerce_email_attachments', 'attach_manual_pdf_to_email', 10, 3);
function attach_manual_pdf_to_email ( $attachments, $status , $order ) {
$allowed_statuses = array( 'customer_processing_order', 'customer_on_hold_order', 'customer_order_status_email' );
if( isset( $status ) && in_array ( $status, $allowed_statuses ) ) {
$dokument = get_template_directory() . '/woocommerce/emails/attach.pdf';
$attachments = $dokument;
}
return $attachments;
}
Email Ids customer_processing_order and customer_on_hold_order works like a charm.
But customer_order_status_email which is php template for order status manager is not working. It is located in betheme/woocommerce/emails/customer-order-status-email.php and I did also try to move it to same locations where other templates are but that did not help.
Any idea how to make this working please?
okay i did find a solution:
i did use echo '<pre>'; print_r($email->id); echo '</pre>' in template of an email which printed me an email ID. i used this id in my allowed statuses and it is working now.

Gravity Forms Multi Page Losing POST value

I have a complex Gravity Form built, it has 10 pages. I am using fields to build a "string" that I then match to a CPT name to get meta data from to display a selection, based on user choices in the form.
One field I have is not holding its value in POST. I can see it when I select the value on the page, then when I click to next page the value is still there. However, after two pages the value ( and field ) disappear from POST.
This is the function I have put together that builds my product string.
add_filter( 'gform_pre_render_12', 'display_choice_result' );
function display_choice_result( $form ) {
$current_page = GFFormDisplay::get_current_page( $form['id'] );
$html_content = "";
$prod_string = "";
if ( $current_page >= 10 ) {
foreach ( $form['fields'] as &$field ) {
// Check for a class of "product-builder-item" on the field
// I use this as another way to denote what fields to add to string
if ( strpos( $field->cssClass, 'product-builder-item' ) === false ) {
continue;
}
//gather form data to save into html field (Field ID 14 on Form ID 12)
//exclude page break and any hidden fields
if ( $field->id != 14 && $field->type != 'page' ) {
$is_hidden = RGFormsModel::is_field_hidden( $form, $field, array() );
$populated = rgpost( 'input_' . $field->id );
// Make sure the field we are getting the value from is not hidden and has a value
if ( !$is_hidden && $populated !='' ) {
$html_content .= '<li>' . $field->label . ': ' . rgpost( 'input_' . $field->id ) . '</li>';
$prod_string .= rgpost( 'input_' . $field->id );
}
}
}
// Do a bunch of stuff here with the $prod_string variable
// ...
// ...
// ...
}
return $form;
}
Screenshots showing the POST disappearing..The POST field in question is input_22 with a value of 18000
This is one page after I choose from the field
This is two pages after,
Anyone run into this before or have any idea why it would be disappearing?
Thank you.
I was having the same exact issue as you described. I realized that a jQuery function was interfering with Gravity Form process. The jQuery function was set to change a zip code field from type text to tel so the number pad would open up on mobile devices. This is what was causing my issue.

Is it possible to hide form from non-registered users?

I need to hide form with some shortcode [contact-form-7 id="3080"] from non-registered users in WordPress.
So i've tried to use inserted tags like this '[client][contact-form-7 id="3080"][/client]' and it doesn't work.
with this php code
function access_check_shortcode( $attr, $content = null ) {
extract( shortcode_atts( array( 'capability' => 'read' ), $attr ) );
if ( current_user_can( $capability ) && !is_null( $content ) && !is_feed() )
return $content;
return '';
}
add_shortcode( 'access', 'access_check_shortcode' );
This one isn't interesting, cause i need to show it inside the template
<?php
if ( is_user_logged_in() )
echo do_shortcode( '[contact-form-7 id="1234" title="Contact form 1"]' );
?>
Are you willing/able to install third party plugins? If so, you might want to check out either or both of these:
Hide This (https://wordpress.org/plugins/hide-this/)
Eyes Only (https://bs.wordpress.org/plugins/eyes-only-user-access-shortcode/)
Both of these work by enabling shortcode that can be wrapped around specific content. I believe both have options to how only to logged-in users.

Woocommerce - Change order received text after redirecting from PayPal with IPN

I like to change the thank you page text in case the customer already paid via paypal.
Redirecting via PayPal works fine. Order status is "processing", ok.
But how can I change the thank you text on the redirecting page (https://www.example.com/checkout/order-received/)
I tried the following, with no success:
function my_update_order_status() {
$order = new WC_Order($order_id);
if ($order_status == 'processing')
echo 'NEW MESSAGE';
else
echo 'NOT PAID TEXT';
}
add_filter('woocommerce_thankyou_order_received_text', 'my_update_order_status', 10, 2);
There is an explanation on how to change the thank you page here:
https://wordpress.org/support/topic/how-to-edit-the-thank-youorder-received-page
If you don't wish to do any template modifying then you can include the order received function to adjust it. For example:
function isa_order_received_text( $text, $order ) {
$new = $text . ' All received and an email is on its way to you!.';
return $new;
}
add_filter('woocommerce_thankyou_order_received_text', 'isa_order_received_text', 10, 2 );
The above with add text to the current text output.

Gravity Forms - Compare value against another field

Hoping someone can shed some light on this. I have a registration form setup in Gravity Forms for the registration of students. According to law a students guardian/parent needs to give consent for students under the age of 18. I have setup a conditional "Guardian/Parent" email field that only shows if the student is under the age of 18.
So X2 email fields are present in the form, one for the student and one for the guardian/parent. Once the forms is submitted, the activation mail is sent only to the guardian email address.
My problem is that at the moment the same email address can be pout in both the guardian/parent and student email. I would like to validate the 2 email fields and ensure that they are not the same.
I tried the following, but it has no effect at all.
add_filter( 'gform_field_validation_12_3', function ( $result, $value, $form, $field ) {
$master = rgpost( 'input_11' );
if ( $result['is_valid'] && $value == $master ) {
$result['is_valid'] = false;
$result['message'] = 'Please enter a different email.';
}
return $result;
}, 10, 4 );
The "12" in "gform_field_validation_12_3" represent my form_id and the "3" represents the guardian/parent field_id
The "11" in "$master = rgpost( 'input_11' );" represents my student email field_id
It simple does not validate the fields and submits the form even though I have the same email in both fields....
If email confirmation is enabled, you'll want to change this line:
if ( $result['is_valid'] && $value == $master ) {
to this:
if ( $result['is_valid'] && $value[0] == $master ) {
The issue is that when email confirmation is enabled, the $value is an array not a string. You can just get the first value from the array and it should work as expected.
If you don't want to fuss with having to know all of this, feel free to use this snippet I just wrote. It will also handle multiple fields and multiple groups of "unique" fields.
http://gravitywiz.com/gravity-forms-require-unique-values-for-different-fields/