check please: http://www.baroniarialb.cat/finalitza-la-compra/
I have AVADA and Woocommerce theme installed, but I need to change the "Have A Promotional Code?" and I can't find the correct code to do it.
I have already tried different ways that appear on the internet without success from funtions.php.
Could you guide me?
Try this code. I've tested from the my side and it's working fine
function woocommerce_rename_coupon_field_on_cart( $translated_text, $text, $text_domain ) {
if ( is_admin() || 'woocommerce' !== $text_domain ) {
return $translated_text;
}
if ( 'Apply Coupon' === $text ) {
$translated_text = 'Put your text here'; //Here add your text which you want to replace
}
return $translated_text;
}
add_filter( 'changetext', 'woocommerce_rename_coupon_field_on_cart', 10, 3 );
You can change via jQuery also. Add the script in the footer.php file
<script>
jQuery("h2.promo-code-heading").text("Hello world!");
</script>
For strings translations on plugins, we use the locotranslate plugin, simple, fast and can use translated files for more wordpress instances.
Related
In WooCommerce, The "No products were found matching your selection." text appears when no products are found in the loop.
However, I want to add HTML in the text, so I use the gettext filter hook. Via str_ireplace I can easily overwrite the text:
function change_empty_category_text($translated) {
$translated = str_ireplace ('No products were found matching your selection.', 'sorry! we are not delivering products from this category to you pin code at the moment.', $translated);
return $translated;
}
add_filter( 'gettext', 'change_empty_category_text' );
However, when I want to add HTML in this text:
function change_empty_category_text($translated) {
$translated = str_ireplace ('No products were found matching your selection.', 'sorry! we are not delivering products from this category to you pin code at the moment.\r\nplease visit the following categories instead\r\n<a href = 'www.example.com/category1'>category 1</a>\r\n<a href = 'www.example.com/category2'>category 2</a>\r\n<a href = 'www.example.com/category3'>category 3</a>', $translated);
return $translated;
}
add_filter( 'gettext', 'change_empty_category_text' );
It has no result. Instead, I am getting the same exact text as written in the replacement.
Any advice?
The text you want to adjust can be found in templates/loop/no-products-found.php, so you could overwrite the template file
versus using the gettext filter hook, since this hook is executed multiple times on every page load.
However, there is another option. Since wc_no_products_found uses function_exits, see: /includes/wc-template-functions.php on line 3254-3262 #version 2.5.0
if ( ! function_exists( 'wc_no_products_found' ) ) {
/**
* Handles the loop when no products were found/no product exist.
*/
function wc_no_products_found() {
wc_get_template( 'loop/no-products-found.php' );
}
}
More info: What's "function_exists" in Wordpress
So instead of using the existing template file, which is called via wc_get_template() in the function, we are going to rewrite the function with our own function.
So you get:
function wc_no_products_found() {
echo '<p class="woocommerce-info" style="display:block;">' .
__( 'Sorry! we are not delivering products from this category to you pin code at the moment.<br>Please visit the following categories instead', 'woocommerce' )
. '<br>category 2<br>category 3</p>';
}
As you can see the output is fully customizable to your needs. CSS adjustments may be required, since this is theme dependent.
Code goes in functions.php file of your active child theme (or active theme).
I am using the plugin force login: https://en-gb.wordpress.org/plugins/wp-force-login/ and need to allow guests to get to the order received page after purchasing.
After checking out, a user which is logged in would be forwarded to this page: [mydomain]/checkout/order-received/[order_id]/?key=[order_key]. I have tried this: Show customer details on WooCommerce Thankyou page even if not registered but could not figure out what to do after I added it.
I currently have this code which allows certain pages to be whitelisted so users that are not logged in can bypass the "force-login" plugin and pay for the relevant product:
add_filter('v_forcelogin_whitelist', 'my_forcelogin_whitelist', 10, 1);
function my_forcelogin_whitelist() {
return array(
home_url( '/cart/' ),
home_url( '/checkout/' ),
home_url( '/cart/?add-to-cart=1465' ),
);
}
I want none logged in users to be forwarded to a page which looks like this after checkout:
[mydomain]/checkout/order-received/5304/?key=wc_order_5cffcfbc96028
For anyone that has this problem this is how I got it working. Since some of the URL's generated are dynamic I needed a work around for those. Using the following code in function.php works for ALL URL's assiciated with woocommerce:
function my_forcelogin_bypass( $bypass ) {
if ( class_exists( 'WooCommerce' ) ) {
if ( is_woocommerce() || is_wc_endpoint_url() ) {
$bypass = true;
}
}
return $bypass;
}
add_filter( 'v_forcelogin_bypass', 'my_forcelogin_bypass' );
WooCommerce Checkout/order-received issue
For the problem of [mydomain]/checkout/order-received/[order_id]/?key=[order_key] it is not loading right or is not showing something or 500 Internal Server Error ?
For Temporary purpose because whenever the plugin will be updated the file will be updated in a woo-commerce plugin?
Open File Zilla
The Visit : /var/www/html/wp-content/plugins/woocommerce/includes directory
Then in the directory open : class-wc-order.php
Find this with ctrl+F : get_checkout_order_received_url()
There Will be two lines of code(Earlier) :
$order_received_url = wc_get_endpoint_url( 'order-received', $this->get_id(), wc_get_checkout_url() );
$order_received_url = add_query_arg( 'key', $this->get_order_key(), $order_received_url );
Change to(Updated) Add a comment in the second line :
$order_received_url = wc_get_endpoint_url( 'order-received', $this->get_id(), wc_get_checkout_url() );
//$order_received_url = add_query_arg( 'key', $this->get_order_key(), $order_received_url );
Save it and update it to the server.
You issue will be resolved, but it's for temporary it will be changes whenever the woocommerce plugin will be updated, so you have to update it again.
Thanks!
Need some help understanding why the code below isn't working. Copied from the woocommerce docs page https://docs.woocommerce.com/document/conditional-tags/
and inserted into the theme (avada child theme) functions.php
I've modified the original code only in the category names - changing 'shirts' to 'merch' etc - to suit the categories descriptors I have used, and added the action and function lines.
add_action('woocommerce_before_add_to_cart_form', 'print_below_desc');
function print_below_desc()
{
if ( is_product_category() )
{
if ( is_product_category( 'merch' ) )
{
echo 'Hi! Take a look at our sweet tshirts below.';
}
elseif ( is_product_category( 'parts' ) )
{
echo 'Hi! Hungry for some gaming?';
}
else
{
echo 'Check out our products below.';
}
}
When used as shown above, I get no text added to the product, however if I remove the if statements and just echo a text string it shows up. i.e. this works:
add_action('woocommerce_before_add_to_cart_form', 'print_below_desc');
function print_below_desc() {
echo 'Text string.';
}
Given I have just copy/pasted the woo code, I'm not sure why it wont work for me. It's possible that there is something with avada that interferes, but I don't know what to look for.
Thanks
I am running a wholesale shop on Woocommerce. Login is required to see the prices. This is set up and working properly. Now I wish to add a logon form on every product page to only show to visitors (not logged on users).
I am using the WooCommerce Catalog Visibility plugin. This plugin offers the functionality I described above, but my theme is somehow messing it up. The plugin author says to talk to the theme developer and the theme developer says to talk to the plugin author. So now I am trying to find a workaround.
First issue: The plugin comes with a shortcode [woocommerce_logon_form] that will display a logon form. I don't want to manually add this to every existing product since I have thousands of products on my site. I am looking for a way to get it in through the code for the product page layout.
I found this code (to be added to the functions.php) to work well:
// adds notice at single product page above add to cart
add_action( 'woocommerce_single_product_summary', 'return_policy', 20 );
function return_policy() {
echo '<p id="rtrn">30-day return policy offered. See Terms and Conditions for details.</p>';
}
However, it will only show text. The short code won't work when added instead of the sample text.
Second issue: The short code shows the form even when the customer is already logged in.
I am currently using this nice code that shows or hides content depending on whether the user is logged in or not:
add_shortcode( 'access', 'access_check_shortcode' );
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( 'visitor', 'visitor_check_shortcode' );
function visitor_check_shortcode( $atts, $content = null ) {
if ( ( !is_user_logged_in() && !is_null( $content ) ) || is_feed() )
return $content;
return '';
}
That shortcode works perfectly for text, but not with other shortcodes.
So the combination of these short codes: [visitor][woocommerce_logon_form][/visitor] will not show the logon form to visitors. Instead it will only show them this as text [woocommerce_logon_form].
Please help! I am sure this is probably easily fixed by someone with coding skills.
I appreciate your effort to answer to this question. Keep in mind that my understanding of code is very limited and it would be great if you can also point out in which file to add or modify code.
To make your shortcode working in php code or in php/html code you need to use a native WordPress function do_shortcode() … You can use it with your shortcode for example in your 1st function this way:
add_action( 'woocommerce_single_product_summary', 'return_policy', 20 );
function return_policy() {
echo do_shortcode('[woocommerce_logon_form]');
}
And this will work…
To see all the different hooks you can use instead of woocommerce_single_product_summary, please see this 2 templates code to chose in case a more convenient hook:
WooCommerce single-product.php template
WooCommerce content-single-product.php template
You can also add it the same way in one of your existing short codes, this way:
add_shortcode( 'visitor', 'visitor_check_shortcode' );
function visitor_check_shortcode( $atts, $content = null ) {
if ( ( !is_user_logged_in() && !is_null( $content ) ) || is_feed() )
return do_shortcode('[woocommerce_logon_form]');
return '';
}
And this will work too.
See as reference this answer: Change markup in WooCommerce shortcode output
So as you can see your problem is solved on both issues
Hellow there all I tried searching everywhere but I coudn't just find it - may be because its a wiered requirement all I want to do is remove my Comment Text area in wordpress comment - I sucessfully removed URL website and name in the comment field by using following code
<?php
function remove_comment_fields($fields) {
unset($fields['url']);
unset($fields['author']);
unset($fields['email']);
return $fields;
}
add_filter('comment_form_default_fields','remove_comment_fields');
?>
But not able to remove the Text area - Actually you all will thought what will I do removing all this I am using a plugin which allow you to post images in your comment and the only option I want to give to user is post images via comment. please guide me.
Two options, the comment_form_defaults filter:
add_filter( 'comment_form_defaults', 'so16856397_comment_form_defaults', 10, 1 );
function so16856397_comment_form_defaults( $defaults )
{
$defaults['comment_field'] = '';
return $defaults;
}
or the comment_form_field_comment filter:
add_filter( 'comment_form_field_comment', 'so16856397_comment_form_field_comment', 10, 1 );
function so16856397_comment_form_field_comment( $field )
{
return '';
}
Check the comment_form source code.
You can also hide the textarea comment box by taking its id set to display:none from CSS
Just simple, add this code in functions.php file
function disable_comments_everywhere( $open, $post_id ) {
return false;
}
add_filter( 'comments_open', 'disable_comments_everywhere', 10 , 2 );