Customizing product variations message on single product pages - php

I got a WooCommerce website, which hides the prices for not logged in users, and apparently it works fine, except with product variations, that even if it does what it should, is not properly done, or at least not the way I would do it.
I hides the price of the variable product, but allows you to choose options (which is fine, that way you might encourage users to register) the problem is that when you finish choosing the variables, it shows the following message "Sorry, this product is unavailable. Please choose a different combination." Which is incorrect, is not a combination problem, but a login issue. So I wouls like to ask for some help on changing this message. Just as a quick tip, There is anoter message which i have changed already in WooCommerce with a function in the child functions.php, check the code bellow, do you think I will be able to do something similar?
function my_woocommerce_membership_notice( $message ) {
if (strpos($message,'has been removed from your cart because it can no longer be purchased') !== false) {
$message = 'An item has been removed from your cart as you have been logged out for inactivity. Please login again to add products to your cart.';
}
return $message;
}
add_filter( 'woocommerce_add_error', 'my_woocommerce_membership_notice' );
You can see the actual behaviour of the website in here: http://nataliayandres.com/oxynergy/shop/my-personalized-cream/

You should try to use the WordPress gettex() function that will replace the concerned message by your custom one:
add_filter( 'gettext', 'customizing_product_variation_message', 10, 3 );
function customizing_product_variation_message( $translated_text, $untranslated_text, $domain )
{
if ($untranslated_text == 'Sorry, this product is unavailable. Please choose a different combination.') {
$translated_text = __( 'Here goes your custom text', $domain );
}
return $translated_text;
}
This code goes in function.php file of your active child theme (or theme) or also in any plugin file.

Related

Change column name in Downloads section from email notifications in Woocommerce

I'm creating a website with downloadable products with WooCommerce. When users buy a product and receive an email, I want to customize the table of downloadable products in the email. More specific I only want to change the following:
Only thing I want to do is change 'Downloads' and 'download' to something else…
With some research, I thought I had the answer. I changed some things in order/order-details.php and order/order-downloads.php. But I think I didn't do it correctly.
Can someone tell me what I have to change exactly?
To change the title "Downloads", the right template involved is emails/email-downloads.php line 22
?><h2 class="woocommerce-order-downloads__title"><?php esc_html_e( 'Downloads', 'woocommerce' ); ?></h2>
To change the column label name "Download", you will use the following code:
add_filter('woocommerce_email_downloads_columns', 'custom_email_downloads_columns', 10, 1);
function custom_email_downloads_columns( $columns ){
$columns['download-file'] = __("New name", "woocommerce");
return $columns;
}
Code goes in function.php file of your active child theme (or active theme). Tested and work.

change WooCommerce to a none commercial wish list

I designed a WooCommerce template for a customer. Now he wants to remove prices and visitors only add what they want to the list. So there will be no payment method. s:
- I can't change plugin or database. All data must remain how they are.
- I need to remove prices from all over the site. where ever they are. Cart, wishlist, single page & etc.
- I need to change payment method to something like submit list.
- at the end after submit list page there must be a contact info page.
please help.
You can hook into wc_price and remove the prices there
function my_filter_wc_price( $price ){
return '';
}
add_filter( 'wc_price', 'my_filter_wc_price' );
Then you can hook into parse_query and redirect the checkout page to the contact page.
function my_parse_query(){
if( is_page( wc_get_page_id( 'checkout' ) ) ){
wp_redirect( '/contact' );
exit;
}
}
add_action( 'parse_query', 'my_parse_query' );
That will stop people from being able purchasing things. Just hiding the price with CSS will not. They will still be able to craft URL's to add to cart, and find the cart / checkout pages.
since I found no other way I decided to do it width CSS and translation.
I removed all prices by display:none;
and I translated all the strings which are about shop and price.

Non logged in users Woocommerce, redirection

I'm doing a shop online with Woocommerce, where my client ask me he don't want people to be able to register, he will create a user and password for each one of his clients. That way he can control who buys on his shop.
So I went into Woocommerce and disable the registration at checkout and everywhere, and the option to allow guests to place orders. Everything works fine, except that when someone tries to place an order, when logged out, when he tries to go to the checkout page, it just shows an unformatted message saying "You must be logged in to place an order". Is there a way where I can redirect not logged in customers to login page, when trying to access checkout?
May be this code could be more compact, simple and convenient:
add_action('template_redirect','check_if_logged_in');
function check_if_logged_in() {
if(!is_user_logged_in() && is_checkout())
wp_redirect( get_permalink( get_option('woocommerce_myaccount_page_id') ) );
}
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.
Reference: WooCommerce login redirect based on cart
Use the following code in functions.php
add_action( 'template_redirect', 'redirect_user_to_login_page' );
function redirect_user_to_login_page(){
// Make sure your checkout page slug is correct
if( is_page('checkout') ) {
if( !is_user_logged_in() ) {
// Make sure your login page slug is correct in below line
wp_redirect('/my-account/');
}
}
}
I manage to do it my self! But still if someone has a cleaner code to do so, I'm open to suggestions.
What I did was to paste the following code on the functions.php file of the child theme:
add_action('template_redirect','check_if_logged_in');
function check_if_logged_in()
{
if(!is_user_logged_in() && is_checkout())
{
$url = add_query_arg(
'redirect_to',
get_permalink($pagid),
site_url('/my-account/')
);
wp_redirect($url);
exit;
}
}
Thanks
kind regards

WooCommerce - Skip cart page redirecting to checkout page

Our website is kohsamuitour.net. I have added custom code to skip the cart page on checkout, which works for all sales. This code:
function wc_empty_cart_redirect_url() {
return 'https://www.kohsamuitour.net/all-tours/';
}
add_filter( 'woocommerce_return_to_shop_redirect', 'wc_empty_cart_redirect_url' );
Now that does the job, but we also have a possibility to check booking availability. That can be found on the pages of private charters, i.e. this one: https://www.kohsamuitour.net/tours/kia-ora-catamaran/ .
Here the customer is being redirected to the cart, where I don't want that to happen as this is not a sale.
How can I make sure the 'Check booking availability' is also redirected to the checkout straight away?
You can skip cart definitively, redirecting customers to checkout page when cart url is called.
To achieve this use this code snippet, that should do the trick:
// Function that skip cart redirecting to checkout
function skip_cart_page_redirection_to_checkout() {
// If is cart page, redirect checkout.
if( is_cart() )
wp_redirect( WC()->cart->get_checkout_url() );
}
add_action('template_redirect', 'skip_cart_page_redirection_to_checkout');
This code goes in function.php file of your active child theme (or theme) or also in any plugin file.
The code is tested and fully functional.
Edit: Since WooCommerce 3 replace wp_redirect( WC()->cart->get_checkout_url() ); by:
wp_redirect( wc_get_checkout_url() );

Show Custom Data in Woocommerce Order Details Admin Area

When a User Buys a Product he can generate up to 3 Serial Keys for his Product. This works fine so far. The User can see his Serials always in "my account"
The Data gets stored in the Database: Table=Usermeta Meta=Product_Serial
So from a Users Perspective evrything works fine but from the Admin Perspective not because the admin can´t see how much Serials the Customer has created and also he cant see the Serials the User is using.
Now I have created a Custom Field in the Theme functions.php with this code:
add_action( 'add_meta_boxes', 'add_meta_boxes' );
function add_meta_boxes()
{
add_meta_box(
'woocommerce-order-my-custom',
__( 'Order Custom' ),
'order_my_custom',
'shop_order',
'side',
'default'
);
}
But from here I don't know how to read out the Serial Key so the admin can see it. :( Any ideas ?
May be i am displaying data in wrong place in your order detail page. But you can check there is multipe hook avilable for this woocommerce/inculdes/admin/meta-boxes-/view/html-order-items.php.
I just take one this hook. Please add this code in functions.php
function my_function_meta_deta() {
echo "I am here";
}
add_action( 'woocommerce_admin_order_totals_after_refunded','my_function_meta_deta', $order->id );
As coder said there is multiple hooks you can also try this out.
add_action('woocommerce_admin_order_data_after_order_details', 'my_custom_order_manipulation_function');
function my_custom_order_manipulation_function( $orderID ) {
//dynamic functionalities / static html to display
}
Credits : Add order metadata to WooCommerce admin order overview

Categories