Don't miss the chance! Get Variation Price Display Range Plugin at 🎯$49 $39 onlyBuy Now!
Public Ticket #1216

Refresh page on add to cart from table

Ben

Hey there, I’d like to know if it is possible to refresh the page on add to cart from the variation table (similar to the single product add to cart functionality) as currently the table does not update my mini-cart total until the page is refreshed. 

wpxteam

wpxteam

Hi Ben,

We are sorry for the inconvenience.

Did you try enabling this option from WooCommerce settings?

Let us know if this works for you.

Thank you

Ben

Ben

Hi yes I have tried that, and it works except that I don't want to force the user to the checkout.

What would work really well is that if the user clicks the add to cart button it just forces a refresh of the page. That is what happens on single products on WooCommerce however when using the table this does not happen.

Is there a way to add this as option in functions.php?

wpxteam

wpxteam

Hi Ben, Please try adding the following snippet to your child theme's functions.php: add_filter('pvtfw_cart_redirect_url', function($url){ if( is_product() ){ $product = wc_get_product( get_the_ID() ); $url = $product->get_permalink(); return $url; } }, 10); Let us know if this works for you. Thank you
Ben

Ben

Hi all,

Sorry for the slow response to this. Thank you for sending over the snippet above, that didn't work unfortunately. When the item is added to the cart from the table the page doesn't refresh and so the minicart etc does not show the updated total.

Ben

Ben

Hi again, I have an update to this. It seems at though the snipped works when I have the 'Redirect to the basket page after successful addition' setting enables in woocommerce. It refreshes the page rather than sending the customer to the basket is adding the items from the variation table. The only issue with this is that on other stock items where the variations table isn't used the customer is now being sent to cart after adding their item which is not the outcome that im after. Is it possible to have the snippet work when the 'Redirect to the basket page after successful addition' is disabled? Is there another trigger when adding the item to the cart that can be inserted into the filter instead of 'pvtfw_cart_redirect_url' perhaps?

wpxteam

wpxteam

Hi Ben,

Thanks a lot for your feedback. Currently, this is how it works.

Our development team will further investigate the issue for you.

We will get back to you with our findings.

Thanks a lot

wpx

wpx

Hi Ben,

Please try the following snippet and let me know if it helps:

add_filter('pvtfw_added_cart_filter', function( $script ){
$product = wc_get_product( get_the_ID() );
$url = $product->get_permalink();
$script = sprintf('window.location.href = "%s"; return;', $url);
return $script;
}, 10, 1);

Hope to hear from you soon!

Ben

Ben

Hey there, thanks for the above, unforutnaly this didn't work and I couldn't save the updates to functions.php with the above code.

I got the following error message..

 

Your PHP code changes were rolled back due to an error on line 495 of file wp-content/themes/mercurybrands/functions.php. Please fix and try saving again.

Uncaught Error: Call to a member function get_permalink() on bool in w-content/themes/mercurybrands/functions.php:495

Stack trace:

#0 wp-includes/class-wp-hook.php(308):{closure}()

#1 wp-includes/plugin.php(205): W_Hook->apply_filters ()

#2 wp-content/plugins/product-variant-table-for-woocommerce/inc/frontend/class_pvtfw_cart.php(240):apply_filters()

#3 wp-content/plugins/product-variant-table-for-woocommerce/inc/frontend/class_pvtfw_cart.php(96):PVTFW_CART->added_to_cart_trigger()

#4 w-includes/class-wp-hook.php(308):PVTFW_CART->ajax_wc_button_script()

#5 wp-includes/class-wp-hook.php(332):WP_Hook->apply_filters()

#6 wp-includes/plugin.php(517): WP_Hook->do_action ()

#7 wp-includes/general-template.php(3059): do_action ()

#8 vp-content/themes/mercurybrands/footer.php(126): w_footer ()

#9 wp-includes/template.php(783): require_once ('/home/owc3e8fvc...')

#10 wp-includes/template.php(718): load template ()

#11 wp-includes/general-template.php(92): locate_template ()

#12 w-content/themes/mercurybrands/page-homepage.php(248):get_footer()

#13 w-includes/template-loader.php(106): include ('/home/owc3e8fvc..

#14 wp-blog-header-php(19): require_once ('/home/owc3e8fvc...')

#15 index.php(17): require('/home/owc3e8fvc.... ')

#16 {main} thrown

wpx

wpx

Hi Ben,

Can you please give us temporary admin access to your site? So, I can run some tests for you.

You can follow this and this to give admin access. That area can only be accessed by our support members and you. So, please don't worry about your site security.

Looking forward to hearing from you soon!

Thanks