Problem with parentheses in Woocommerce cart page - wordpress

I have a problem with Woocommerce + "Yith deposits and down payments" plugin.
The page shows:
$26.997
(of
$93.980
)
And I need the site shows this:
$26.997
(of)
$93.980
This is the code from this part:
if( $grand_total ) {
$total_html .= apply_filters( 'yith_wcdp_show_cart_total_html', sprintf( ' (%s <strong>%s</strong>)', __( 'of', 'yith-woocommerce-deposits-and-down-payments' ), wc_price( $grand_total ) ), WC()->cart );
}
Any idea how to fix this problem?
Thank you.

Update this part sprintf( ' (%s) <strong>%s</strong>'
Try this code
if( $grand_total ) {
$total_html .= apply_filters( 'yith_wcdp_show_cart_total_html', sprintf( ' (%s) <strong>%s</strong>', __( 'of', 'yith-woocommerce-deposits-and-down-payments' ), wc_price( $grand_total ) ), WC()->cart );
}

Related

Woocommerce product counts in single product page

I am currently struggling with woo-commerce and the availability status on product pages. I am trying to display various texts (translated) on the product pages, whether the product is available and how many we have, then whether it is unavailable, whether it is available to backorder, and what I can't do is display the message that the product is in stock with disabled managing stock. There are unlimited products. But it still shows me only "available places".
There is my function.
add_filter( 'woocommerce_get_availability', 'product_stock_quantity_single', 1, 2);
function product_stock_quantity_single( $availability, $_product ) {
global $product;
$stock = $product->get_stock_quantity();
if ( $_product->is_in_stock() ) $availability['availability'] = __('Text front ' . $stock . ' text behind', 'woocommerce');
if ( !$_product->is_in_stock() ) $availability['availability'] = __('Out of stock text', 'woocommerce');
if ( $_product->is_on_backorder() ) $availability['availability'] = __( 'On backorder text', 'woocommerce' );
return $availability;
}
I've tried many different combinations and frankly, it doesn't work for me. Thanks for all the advice and help. I tried what was in the topic which was merged with mine. It's a different topic about different things I want to achieve. I need a product with disabled managing stock but still available (something like infinite stock)
You're currently returning $availability outside of the function. Give this a try:
add_filter( 'woocommerce_get_availability', 'product_stock_quantity_single', 1, 2);
function product_stock_quantity_single( $availability, $_product ) {
global $product;
$stock = $product->get_stock_quantity();
if ( $_product->is_in_stock() ) $availability['availability'] = __('Text front ' . $stock . ' text behind', 'woocommerce');
if ( !$_product->is_in_stock() ) $availability['availability'] = __('Out of stock text', 'woocommerce');
if ( $_product->is_on_backorder() ) $availability['availability'] = __( 'On backorder text', 'woocommerce' );
return $availability;
}
Check out this answer and add the fourth condition I added. Hope this helps you want to achieve.
add_filter( 'woocommerce_get_availability', 'product_stock_quantity_single', 1, 2);
function product_stock_quantity_single( $availability, $_product ) {
global $product;
$stock = $product->get_stock_quantity();
if ( $_product->is_in_stock() ) $availability['availability'] = __('Text front ' . $stock . ' text behind', 'woocommerce');
if ( !$_product->is_in_stock() ) $availability['availability'] = __('Out of stock text', 'woocommerce');
if ( $_product->is_on_backorder() ) $availability['availability'] = __( 'On backorder text', 'woocommerce' );
if ( $_product->is_in_stock() && !$stock ) $availability['availability'] = __('Stock disabled text', 'woocommerce');
return $availability;
}

Display free shipping threshold based on Woocommerce min amount order from shipping settings

I want to display shipping notice based on free shipping settings for min amount order. I have more then one shipping zone based on different country and currency. Tried to use the following code, it works when you add product to cart, the shipping notice is display but as if you update quantity the shipping notice is removed, maybe duo to Ajax load? Can I add something to this code to make it work with qty update on product?
add_action( 'woocommerce_before_mini_cart_contents', 'display_free_shipping_cart_notice_zones' );
function display_free_shipping_cart_notice_zones() {
// Get Shipping Methods for Current Zone
global $woocommerce;
$shipping_methods = $woocommerce->shipping->get_shipping_methods();
// Loop through the array to find min_amount value/s
foreach($shipping_methods as $key => $value) {
if ( $shipping_methods[$key]->min_amount > 0 ) {
$min_amounts[$key] = $shipping_methods[$key]->min_amount;
}
}
if ( is_array($min_amounts) ) {
// Find lowest min_amount
$min_amount = min($min_amounts);
// Get Cart Subtotal inc. Tax excl. Shipping
$current = WC()->cart->subtotal;
// If Subtotal < Min Amount Echo Notice
// and add "Continue Shopping" button
if ( $current < $min_amounts ) {
$added_text = 'Get free shipping if you order ' . wc_price( $min_amount - $current ) . ' more!';
$return_to = wc_get_page_permalink( 'shop' );
$notice = sprintf( '%s %s', esc_url( $return_to ), 'Continue Shopping', $added_text );
wc_print_notice( $notice, 'notice' );
}
else if ( $current = $min_amounts ) {
$added_text = 'Congratulations - Your shipping is now on us and absolutely free :)';
$return_to = wc_get_page_permalink( 'shop' );
//$notice = sprintf( '%s %s', esc_url( $return_to ), 'Continue Shopping', $added_text );
$notice = sprintf( '%s', $added_text );
wc_print_notice( $notice, 'notice' );
}
}
}

How to make Customer Billing Phone Number Unique in Wordpress

Actually I want customers to add unique-phone numbers in the billing address of woo-commerce. if any tries to add / update already existed phone numbers then it should throw an error.
I tried the below code but it is not working. Can anyone give me the correct solution for unique phone numbers in the Woocommerce billing address?
add_filter( 'update_user_meta', 'ts_unique_wc_phone_field');
function ts_unique_wc_phone_field( $errors ) {
if ( isset( $_POST['billing_phone'] ) ) {
$hasPhoneNumber= get_users('meta_value='.$_POST['billing_phone']);
if ( !empty($hasPhoneNumber)) {
$errors->add( 'billing_phone_error', __( '<strong>Error</strong>: Mobile number is already used!.', 'woocommerce' ) );
}
}
return $errors;
}
Your get_users call is wrong. Use
$hasPhoneNumber = get_users(array(
'meta_key' => 'billing_phone',
'meta_value' => $_POST['billing_phone'],
)
);
Careful: you did not mention your meta key in your post. This might be something else than 'billing_phone'. Adapt it as necessary.
This will however allow users to do shenanigans like adding a space/-/+ or something like that to the phone number, reusing it. This might need a function to filter out redundant characters upon meta value insertion, and apply the same function to $_POST['billing_phone'] before the meta query for get_users.
I have setup on one of my sites the same code within two (2) functions - one for woocommerce -> my account, and one at the checkout which checks for validity of the phone number provided specific to my country, and the other to check if the phone number already exists.
add_action( 'woocommerce_save_account_details_errors', 'wc_myaccount_validate_billing_phone', 20, 1); // My Account
function wc_myaccount_validate_billing_phone( $args ){
if ( isset ( $_POST['billing_phone'] ) && !empty ( $_POST['billing_phone'] ) ) {
if ( !preg_match( '/^04[0-9]{8}$/D', str_replace( ' ', '', $_POST['billing_phone'] ) ) ) {
wc_add_notice( __( '<strong>Billing Mobile Phone</strong> is invalid (Example: 0412 345 678).' ), 'error' );
}
$existing_billing_phone = get_users( 'meta_value=' . str_replace( ' ', '', $_POST['billing_phone'] ) );
$current_user = wp_get_current_user();
if ( !empty ( $existing_billing_phone ) ) {
if ( $current_user->billing_phone != str_replace( ' ', '', $_POST['billing_phone'] ) ) {
wc_add_notice( __( '<strong>Billing Mobile Phone</strong> already exists.' ), 'error' );
}
else {
return;
}
}
}
}
add_action('woocommerce_checkout_process', 'wc_checkout_validate_billing_phone'); // Checkout
function wc_checkout_validate_billing_phone() {
if ( isset( $_POST['billing_phone'] ) && !empty( $_POST['billing_phone'] ) ) {
if ( !preg_match('/^04[0-9]{8}$/D', str_replace(' ', '', $_POST['billing_phone'] ) ) ) {
wc_add_notice( __( '<strong>Billing Mobile Phone</strong> is invalid (Example: 0412 345 678).' ), 'error' );
}
$existing_billing_phone = get_users( 'meta_value=' . str_replace(' ', '', $_POST['billing_phone'] ) );
$current_user = wp_get_current_user();
if ( !empty( $existing_billing_phone ) ) {
if ( $current_user->billing_phone != str_replace(' ', '', $_POST['billing_phone'] ) ) {
wc_add_notice( __( '<strong>Billing Mobile Phone</strong> already exists.' ), 'error' );
}
else {
return;
}
}
}
}
As I want to save all phone numbers as 0412345678 (no spaces) and some people enter phone numbers as 0412 345 678, the str_replace() removes this prior to saving.
add_action( 'woocommerce_checkout_update_user_meta', 'wc_checkout_save_billing_phone' );
function wc_checkout_save_billing_phone( $user_id ) {
if ( $user_id && $_POST['billing_phone'] ) {
update_user_meta( $user_id, 'billing_phone', str_replace(' ', '', $_POST['billing_phone'] ) );
}
}
While I have not tested this next part yet, and this example is referenced from this link, if you are wanting to update the admin user area you may want to use something like this.
add_action( 'show_user_profile', 'wc_checkout_validate_billing_phone', 10 );
add_action( 'edit_user_profile', 'wc_checkout_validate_billing_phone', 10 );
Below is a screenshot of the results of trying to change my phone number to one that already exists while in the woocommerce->my account section.

How to show Product Price + Shipping VAT in "Total" Merged

I have one little isusue that dont know how to resolve myself. I have set in my shop to show separated Price and shipping costs but in total showed me bad price.
For example my products cost 24.99€ + SHIPPING FEE : 3,95€ = 28.94€ but in calculation in cart page is calculating: 24.99€ + 3.95€ - 0.26€ what is wrong.
i found that Total price is calculated via this function:
<td data-title="<?php esc_attr_e( 'Total', 'woocommerce' ); ?>"><?php wc_cart_totals_order_total_html(); ?></td>
and this is function that control that part:
from cart-totals.php in templates, and bellow is function from wc-cart-functions.php
function wc_cart_totals_order_total_html() {
$value = '<strong>' . WC()->cart->get_total() . '</strong> ';
// If prices are tax inclusive, show taxes here.
if ( wc_tax_enabled() && WC()->cart->display_prices_including_tax() ) {
$tax_string_array = array();
$cart_tax_totals = WC()->cart->get_tax_totals();
if ( get_option( 'woocommerce_tax_total_display' ) == 'itemized' ) {
foreach ( $cart_tax_totals as $code => $tax ) {
$tax_string_array[] = sprintf( '%s %s', $tax->formatted_amount, $tax->label );
}
} elseif ( ! empty( $cart_tax_totals ) ) {
$tax_string_array[] = sprintf( '%s %s', wc_price( WC()->cart->get_taxes_total( true, true ) ), WC()->countries->tax_or_vat() );
}
if ( ! empty( $tax_string_array ) ) {
$taxable_address = WC()->customer->get_taxable_address();
$estimated_text = WC()->customer->is_customer_outside_base() && ! WC()->customer->has_calculated_shipping()
? sprintf( ' ' . __( 'estimated for %s', 'woocommerce' ), WC()->countries->estimated_for_prefix( $taxable_address[0] ) . WC()->countries->countries[ $taxable_address[0] ] )
: '';
$value .= '<small class="includes_tax">' . sprintf( __( '(includes %s)', 'woocommerce' ), implode( ', ', $tax_string_array ) . $estimated_text ) . '</small>';
}
}
echo apply_filters( 'woocommerce_cart_totals_order_total_html', $value );
}
So my question is how to add that 1.63E at Total Price, so will get correct price. Thanks
EDIT: Found the same problem like mine here but answers dont seems to make changes.
First, thanks for your Post, I was almost thinking I'm the only one with this need.
So far, this worked for my shop. I'm shure my code is not very versatile for different shop settings. Maybe someone could make a more general usable version.
Edit: I've added a picture showing the two rates. Image of the result and I've found a minor mistake calculating the shipping tax, corrected now.
/**
* Change Tax Amount including Shipping Taxes
* Referencing to wc-cart-functions.php starting from Line 296
*
*/
add_filter( 'woocommerce_cart_totals_order_total_html', 'woo_rename_tax_inc_cart', 10, 1 );
function woo_rename_tax_inc_cart( $value ) {
/* Get all infos needed */
$shipping_total = WC()->cart->shipping_total;
$taxes = WC()->cart->get_taxes_total( true, true );
$taxrate = 7.7;
$newtaxes = ($shipping_total/(100+$taxrate)*$taxrate) + $taxes; // Shipping is 100% + taxrate %, so we deduct both percentages.
/* Check if Shipment total is active */
if ( ! empty($shipping_total) && $shipping_total != 0 ) {
if ( ! empty( $value ) ) {
// Show Price /wc-cart-functions.php Line 297
$value = '<strong>' . WC()->cart->get_total() . '</strong> ';
$value .= '<small class="includes_tax">' . '(inkl. ' . wc_price( $newtaxes ) . ' MWST)' . '</small>';
}
}
// Attach Tax Info to Price (single line)
$value = str_ireplace( 'Tax', 'GST', $value );
return $value;
}

Customize no result page

I have a problem with no result page. I have a search box, if you find something then u can see "Search result : ", but if u didnt find then u can see "No Search result : ". I want to remove this NO before search result, but I dont find any solution for this. I tried already many different functions and css, but nothing .. I want to remove this NO, or whole this line (No search result : ).
This is what I have atm in functions.php
add_filter( 'tc_search_results_title' , 'my_search_results_title');
function my_search_results_title(){
$my_search_results_title = __('Search result :', 'customizr-child');
return $my_search_results_title;
}
add_filter('tc_breadcrumb_trail_items', 'search_results_breadcrumb');
function search_results_breadcrumb( $trail ){
if ( ! is_search() )
return $trail;
$_last = sizeof($trail) - 1;
$_search_string = __('Search result: ', 'customizr-child');
/* or you an use the function used for that other snippet to have the same title, in this case remove the comment of the line below */
// $_search_string = my_search_results_title();
if ( is_paged() )
$trail[$_last] = '' . sprintf( '%2$s "%1$s"' , esc_attr( get_search_query() ), $_search_string ) . '';
else
$trail[$_last] = sprintf( '%2$s "%1$s"', esc_attr( get_search_query() ), $_search_string );
return $trail;
}
add_filter( 'tc_no_result_content', 'my_no_result_content');
function my_no_result_content() {
return '<div class="tc-content span12"><h1>Didnt find anything, try again</h1></div>';
}
I use Customizr child theme in Wordpress
Maybe somebody can help me with this.
Thanks !
You're using the wrong filter. You'll have to use tc_search_results_header_content instead and replace the No string. You can also use to original part of code and remove the unwanted part, something like:
function my_search_results_header_content ($content) {
return sprintf( '<div class="row-fluid"><div class="%1$s"><h1 class="%2$s">%3$s%4$s %5$s </h1></div><div class="%6$s">%7$s</div></div>',
apply_filters( 'tc_search_result_header_title_class', 'span8' ),
apply_filters( 'tc_archive_icon', 'format-icon' ),
'', // Original uses: have_posts() ? '' : __( 'No' , 'customizr' ).' ' ,
apply_filters( 'tc_search_results_title' , __( 'Search Results for :' , 'customizr' ) ),
'<span>' . get_search_query() . '</span>',
apply_filters( 'tc_search_result_header_form_class', 'span4' ),
have_posts() ? get_search_form(false) : ''
);
}
add_filter('tc_search_results_header_content', 'my_search_results_header_content');
Hope it helps.

Resources