Startseite › Toolset Professional Support › [Gelöst] [wpv-add-to-cart-message] doesn't always display messages immediately
This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.
Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.
Heute stehen keine Supporter zur Arbeit im Werkzeugsatz-Forum zur Verfügung. Sie können gern Tickets erstellen, die wir bearbeiten werden, sobald wir online sind. Vielen Dank für Ihr Verständnis.
Sun | Mon | Tue | Wed | Thu | Fri | Sat |
---|---|---|---|---|---|---|
- | - | 14:00 – 20:00 | 14:00 – 20:00 | 14:00 – 20:00 | 14:00 – 20:00 | 14:00 – 20:00 |
- | - | - | - | - | - | - |
Supporter timezone: Asia/Ho_Chi_Minh (GMT+07:00)
Tags: Views plugin
Dieses Thema enthält 4 Antworten, hat 2 Stimmen.
Zuletzt aktualisiert von Beda vor 6 Jahren, 9 Monaten.
Assistiert von: Beda.
Link to a page where the issue can be seen:
versteckter Link
I hope you can help with this problem as it concerns the [wpv-add-to-cart-message] shortcode.
In the page above I have a list of seminars (made with the woocommerce Product Post type. Each product has an add to cart button (SELECT) - this works as it should - the add to cart message is displayed correctly.
Once a product is in the cart, the button changes to show that it's"Selected" and the link on the button changes to be a remove from cart button.
When I click this the product is removed from the cart, but the "Product removed" message does not display immediately.
If I then go ahead and add another product to the cart by clicking the SELECT button I get 2 messages - one showing the expected "added to cart" message and one showing the "removed from cart" message from the previous product removal.
Any idea why the remove message is not triggered immediately?
This code shows how I change the button dependent on whether the item is in the cart:
// Seminar Add to car button shortcode function seminar_addtocart() { foreach( WC()->cart->get_cart() as $cart_item_key => $values ) { $_product = $values['data']; if( get_the_ID() == $_product->id ) { return __('<a class="et_pb_button et_pb_module et_pb_bg_layout_light btf_selected" href="' . get_remove_url_btf( $cart_item_key ) . '">Selected<br /><span class="tiny">Click to remove</span></a>', 'woocommerce'); } } return __('<a class="et_pb_button et_pb_module et_pb_bg_layout_light" href="<em><u>versteckter Link</u></em>'.get_the_ID().'">Select</a>', 'woocommerce'); } add_shortcode( 'seminar_addtocart', 'seminar_addtocart' );
This code generates the remove from cart URL.
function get_remove_url_btf( $cart_item_key ) { $cart_page_url = wc_get_page_permalink( 'cart' ); return apply_filters( 'woocommerce_get_remove_url', $cart_page_url ? wp_nonce_url( add_query_arg( 'remove_item', $cart_item_key, $cart_page_url ), 'woocommerce-cart' ) : '' ); }
I see in your code you add_query_arg() 'remove_item'.
But the URL you have on the site, when I click the "remove" button, is 'removed_item'.
Is the code a copy paste from the real code?
I think the issue here is how the message is displayed, the condition around it.
May I see how you set this up?
Please link me with all relevant Custom Code and Views/Pages/Content Templates you use so I can see this and eventually correct, or replicate and report it.
Thank you
I'm not sure if you've changed something but it seems to be working as expected now. If you did change something can you let me know what.
If not, it's a miracle!
And now it's stopped working as expected. I just changed something in my functions.php and uploaded so may I've overwritten any changes you made?
I have not touched this thread since https://toolset.com/forums/topic/wpv-add-to-cart-message-doesnt-always-display-messages-immediately/#post-612376.
Hence whatever made it work, cannot be from me.
However, I see our shortcode bottom line relies on WooCommerce Core.
The Function here is wc_print_notices.
WooCommerce is scarce on Documentation about that function.
https://docs.woocommerce.com/wc-apidocs/function-wc_print_notices.html
I do not know wether it should show removed items or not, and it should be a question for the WooCommerce Supporters.
What I can tell from our end is that the shortcode wpv-add-to-cart-message is described as to use so to display a success message when a product is added to the cart. It can also show exception messages if, for example – there is insufficient stock.
Nothing mentioned thou about when you remove the item.
https://toolset.com/documentation/user-guides/views-shortcodes/#wpv-add-to-cart-message
And our code also seems not to feature anything in regard - it just calls the WooCommerce core.
So, what I suggest is to approach this with the Custom Code you already use.
Or, you might consult WooCommerce to know what it is supposed to return, but as far I know WooCommerce support does not help on custom code, not sure about this thou.
My suggestion is to use our ShortCode only as suggested in the DOC, which is to add the message when you do not use Custom Code on it.