I need to change the link for the "Continue Shopping" button in Wordpress WooCommerce. I have tried 6 different solutions that I found online, all of which involved editing the functions.php file using the hook woocommerce_continue_shopping_redirect.
None work and I have seen a few unanswered posts around the web with the same issue, which leads me to suspect that something has changed in the latest version of WP or WC.
Any ideas would be appreciated. Thanks.
You may try add below code into your theme functions.php:
function custom_woocommerce_continue_shopping_redirect( $return_to ) {
return get_permalink( woocommerce_get_page_id( 'shop' ) );
}
add_filter( 'woocommerce_continue_shopping_redirect', 'my_woocommerce_continue_shopping_redirect', 20);
Related
I've tried all the solutions posted to StackOverflow and still no dice.
Woocommerce mentions that "archive-product" will not be able to be overwritten if you use woocommerce.php, so what is the correct way to loop woocommerce_content(); ? and still be able to edit archive-product? No matter what I do, I can't edit archive-product. I did have success with this, but this seems like bad practice;
if ( is_singular( 'product' ) ) {
woocommerce_content();
} else {
//For ANY product archive.
//Product taxonomy, product search or /shop landing
woocommerce_get_template( 'archive-product.php' );
}
Another solution most people find in function.php (which I already use)
function mytheme_add_woocommerce_support() {
add_theme_support( 'woocommerce' );
}
add_theme_support('woocommerce');
I haven't seen anyone asking about this in my hours of research and would love some help.
This is very vague and basically just tells you that you can't edit the archive-product (without any solution of how to do so)
https://docs.woocommerce.com/document/template-structure/
I'm trying to figure out how to load the cart.min.js scripts not only if IS_CART but also if SHORTCODE_EXISTS('woocommrece_cart'), I can see that all the fronted scripts enqueues are in class-wc-frontend-scripts.php file and I don't want to override it, is there any hook that I can use to add another IF statement to the same file?
THANKS :)
after some testing
I want to explain my problem again:
I have a 'woocommerce_cart' shortcode that doesn't loads the scripts that it needs to work via ajax (like when updating cart and etc...) on other pages than the cart page
I see that in the class-wc-frontend-scripts.php the enqueue of that script goes only when is_cart() statement.
I am figuring out that I need to add if(shortcode_exists('woccommerce_cart')) so it would enqueue also when it is a shortcode.
I am adding that IF and I see that everything works on front end.
I am thinking that it is not a good idea to put that in the original plugin file because it would be overwritten with the next update.
I am trying to enqueue the script in my functions.php file with the new IF.
Nothing works....
Going back to the original file
On line 247 (here: https://github.com/woothemes/woocommerce/blob/master/includes/class-wc-frontend-scripts.php) there is a function that adds more functionality to the ajax that without it it wont work...
Now I am wondering is there a way to add another IF to the same file using a hook? Or should I override all the file? (as I said before I think it is not a good practice because all the functions there wont get any updates).
So basically I know what I need to do, I just don't know what is the best way to do it and if it possible doing it with a hook or other function that maybe somebody knows and I'm not familiar with....
Thank you again for your help! :)
SHORT ANSWER
You need to define the WOOCOMMERCE_CART constant and make sure you're using a modern version of Woocommerce. I've tested this solution in Woocomerce 3.0.7.
if (!defined('WOOCOMMERCE_CART')) define( 'WOOCOMMERCE_CART', TRUE );
LONG ANSWER
I was having the same problem:
- I was calling the [woocommerce_cart] shortcode with the do_shortcode() function to display the cart in all the pages of my site.
- The cart was displaying well but the scripts (specifically cart.min.js) weren't loading in the pages. The effect of this is that the AJAX interactions weren't working.
The pages in my site were already running WC_Frontend_Scripts::init(). This function calls WC_Frontend_Scripts::load_scripts and that function loads our cart.min.js only if is_cart() (file wc-conditional-functions.php) is TRUE, as you already pointed.
Now, the current version of is_cart() evaluates TRUE when any of the following conditions is TRUE:
is_page( wc_get_page_id( 'cart' ) )
defined( 'WOOCOMMERCE_CART' )
wc_post_content_has_shortcode( 'woocommerce_cart' )
So, for me, the easiest way to fix the problem was to define the WOOCOMMERCE_CART constant.
Hope this helps. :-)
I had the exact same problem, combining cart and checkout pages broke the ajax auto cart
updates. I add the cart to the checkout page using:
function cart_on_checkout_page()
{
if ( is_wc_endpoint_url( 'order-received' ) ) return;
echo do_shortcode('[woocommerce_cart]');
}
add_action( 'woocommerce_before_checkout_form', 'cart_on_checkout_page', 5 );
My solution was to use the following code in functions.php to check if we are on the checkout page, and if so, enqueue/load the 'wc-cart' script. It's working with Woocommerce version 4.5.2.
function adjust_woocommerce_scripts()
{
if ( is_checkout() ) wp_enqueue_script( 'wc-cart' );
}
add_action( 'wp_enqueue_scripts', 'adjust_woocommerce_scripts', 11 );
You can adjust this function to perform whatever checks you need, such as if SHORTCODE_EXISTS('woocommrece_cart') - this means that the 'wc-cart' script is only loaded on the pages you need.
i'm hoping someone can point out whats going wrong with this WordPress theme. I didn't build the theme, though I know its using Genesis.
http://bloomfire.staging.wpengine.com/partners-new
The issue is on the Referral Partners option (if you click on it, it displays a different tab essentially. But if you scroll down you will see that the tab isn't displaying the shortcode, which is just a simple contact form from Gravity Forms.
I have tried adding in the following code to the functions.php file but it has just been ignored all over:
add_filter( 'comment_text', 'shortcode_unautop');
add_filter( 'comment_text', 'do_shortcode' );
global $post;
$content = get_post_meta( $post->ID, 'solution-tab-3', true );
echo do_shortcode( $content );
add_filter( 'get_post_meta', 'shortcode_unautop');
add_filter( 'get_post_meta', 'do_shortcode');
I don't understand how Genesis isn't allowing a shortcode to be used within the system.
Can anyone help?
I have a Wordpress site that utilizes multiple custom post types to achieve different goals. I also use the AddThis plugin to append social sharing buttons to the top of the posts. However, I have one type of custom post that I do not the plugin to append the AddThis sharing buttons to. Is there a way to hook into the AddThis plugin to get it to return false or something given a certain condition?
Maybe something like:
if($post_type === "no-addthis"){
addthis_plugin_hook(false);
}
I totally realize that's not a valid way to do it, but does anyone know of something similar?
Thanks in advance.
The following will remove all AddThis filters operating on the current post:
if( get_post_type( get_the_ID() ) == 'your-post-type' ) {
remove_filter('the_content', 'addthis_display_social_widget', 15);
remove_filter('the_content', 'addthis_script_to_content');
remove_filter('get_the_excerpt', 'addthis_display_social_widget_excerpt', 11);
remove_filter('get_the_excerpt', 'addthis_late_widget', 14);
remove_filter('wp_trim_excerpt', 'addthis_remove_tag', 11, 2);
}
I'd advise running this code right before any call to the_content() or the_excerpt() ( or similar function prefixed with get_ ) in your custom post type template.
Note: I haven't tested this and I've never used the AddThis plugin. I just peeked at the source code just now. :)
Newest version I do the following in functions.php
add_action( 'init', 'remove_addthis' );
function remove_addthis(){
remove_action( 'wp_head', 'addthis_add_content_filters');
}
I'm creating a theme designed specifically for usage with woocommerce. This theme's design does not utilize the "Product Short Description". Removing that description from displaying on the page was easy enough using:
remove_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_excerpt', 20);
However, I cannot seem to find any way to remove the field/panel itself from showing to the admin on the product editing pages. If anyone knows how to do that, it would be greatly appreciated. To be clear this is the newer woocommerce 2.0. Thanks!
You can remove the Short Description field from the WooCommerce admin area via PHP:
function remove_short_description() {
remove_meta_box( 'postexcerpt', 'product', 'normal');
}
add_action('add_meta_boxes', 'remove_short_description', 999);
As answered in different treads:
remove_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_excerpt', 20 );
function woocommerce_template_single_excerpt() {
return;
}
This is also what I am looking for. For me, to target the product description's css, use .single-product .entry-content.
Until now, I think Woocommerce doesn't provide any hook for product description only.