WooCommerce visible/hidden price switch with PHP - php

First off: Iam only familiar with HTML and CSS. My PHP is reduced to max. "understand" it.
For my workplace Iam working on a WordPress with a WooCommerce ajax based b2b shop.
For our merchants, the prices of the products needs to be visible all the time. But if they choose to show the product to their customer, they don't want to show them the merchant prices, so they need a switch (button-like) to hide all prices. Basically a catalogue mode on a frontend button in the header e.g.
As soon as you press it, all prices should hide, even after you click on a product and you go to the detail page.
So I tried to use my basic php understandings and found this on google:
remove_action( 'woocommerce_after_shop_loop_item_title', 'woocommerce_template_loop_price', 10 );
I tied it to a button and it worked. The page reloads and after it, all prices are hidden. But it's just for that page. As soon as you go to the next page, reload it, or want to see the details, they're there again.
So I need a solution, to make this permanent till you press the button again. Ideally, the page doesn't even have to reload to hide the prices.
I'd be very happy if someone could help me here!

Related

WooCommerce Meta-key for products in cart

First post here so I'll try to make it as good as possible.
For a WooCommerce / WordPress project, I'm trying to achieve the following. When the cart is empty, there should be a button displayed with the text "Return to store".
Now the button isn't the problem, I've added this with Elementor, now usually I use the JetEngine Dynamic Visibility option to show/hide things.
I've also done this with stock status. There I used the _stock option to only display when there are 5 or more in stock left.
So I'm trying something similar with the cart, whenever there are 1 or more items in the cart, this button needs to be hidden because whenever someone has 1 item in their cart we want them to proceed to the checkout and not return to the shop, because the average product bought per order is 1 for this particular shop.
But the one thing I can figure out is, what key do I need to use to check items in the cart?
I've been trying several options I found online but none seem to work.
Does anyone know how to do this?
Thanks!

Woocommerce Storefront Theme; Show "available on backorder" on checkout page, on the individual product

Hello i'm on my first webshop project, and mostly been doing normal wordpress websites in the past. I am making the shop with woocommerce and the storefront theme.
On the website the owner want the customers to be able to see the "available on backorder" message that i linked in the first image to where the red line is on the second image.
The first image is from the shopping cart page, and the second is on the checkout page.
Picture one of the shopping cart page and Picture of the checkout page
So the problem is i dont really know how to add the code for showing it on the individual product on the checkout page.
Since im still pretty new to the add_filter or function coding, i dont really have anything to show other than the two related pictures I hope the question makes sense, since english isnt my first language.

Woocommerce - Cart page - when cart gets renewed with new quantities, I want to be able to pass total

Ok - trying to slowly work my way through this - bear with me! Will try to describe what I'm doing here.
Using Woocommerce with theme called Flatsome - but this problem seems to relate to how Woocommerce updates the cart on the cart page.
So I am trying to bend Woocommerce to suit - so when client gets to Cart page - they do not move onto Checkout - instead I am giving them a Button to Request a Quotation - button when click opens a modal with a GravityForm in it.
I've been able to get the product list, quantities, price and SKU passed fine into the form ok using a 3rd party plugin ....
but boy oh boy - can I easily pass through the most recent TOTAL from woocommerce??
Not as easy as I'd hoped!
I had originally written this function into my functions.php
// Send the page url to parameter called 'gdcarttotal' for use in gravity forms
add_filter("gform_field_value_gdcarttotal", "populate_gd_carttotal");
function populate_gd_carttotal(){
global $woocommerce;
$totalamount = $woocommerce->cart->cart_contents_total;
return $totalamount;
}
And yes that seemed to pass through the Total of the Cart ok.
The problem arises if the quantities are updated whilst on that Cart page.
So if I update the quantity of a product - the totals etc all update fine on the Woocommerce cart page total BUT if I then click the launch Quotation form - the value for the Cart Total remains the value of the original total when user landed on that page. So it takes a full page refresh on the cart page to flush it and update it to the correct value.
Someone mentioned to me, Ajax which is beyond my capabilities.
Really just reaching out - and asking what is best way - or how could I write a function whilst on the cart page that will always give me the most updated TOTAL to pass through into a field on a form.
I've got a couple of screenshots but since my first time on here... I'm not sure if I can post or not. Hopefully this description tells the story.
Basically looking to know - whilst on the Woocommerce Cart page, how to pass the most recent TOTAL calculation to a form or page etc...
Thanks guys!!
Gareth
Your base issue is with the language you're using to solve the problem. You've written PHP, which is server-side (i.e., not real-time).
The WooCommerce cart is AJAX, a hybrid of JavaScript and XML, and it's processed client-side (i.e., in the browser) in real-time. That's how you are able to update the quantity and cart totals without a full page reload, and it's how the website is able to see how many items you have in the cart without reloading the page. Because of this, your solution needs to be client-side using JavaScript, I believe.
I'm not a pro developer, so I don't have the exact code to give you, but hopefully this gets you on the right track. You can also read more about AJAX here: https://www.w3schools.com/whatis/whatis_ajax.asp

Ajax request won't work on page load and then refresh, but will work after clicking link to the same page

I have a site.com/ and e-shop on site.com/b2b/ (site.com/b2b/index.php)
Products are listed on e-shop and if I click a button Add to Cart on any product, buttons text changes to Added and AJAX request sends data and updates Shopping Cart.
Now here is my problem.
If I close the browser, reopen it, start it in Incognito Mode (I can reproduce without IM, but just to be extra sure) and go directly to site.com/b2b/ in the URL bar, EVERYTHING works correctly.
But,
if I close the browser, reopen it, start it in Incognito Mode, go to site.com, and then click a link to site.com/b2b/, clicking the button Add to Cart on any product, changes the button text to Added and it visually updates the Shopping Cart to Amount of products is 1 and temporarily adds text Product Added to Cart, but the price is still 0.00.
Then if I add another product by clicking Add to Cart, it again visually updates Shopping Cart along with the temporary text, but the amount of products is still 1 and price is still 0.00.
Regardless of this last step, if I refresh the page, the Shopping Cart is empty and button texts on product are reseted to Add to Cart.
Now the horcrux of the whole story (sorry for being so verbose).
If I click the on-site link to the same URL (site.com/b2b/), which is visually the same as refreshing the page, but SOMETHING MUST HAPPEN in the back, then (of course Shopping Cart is still empty, but) EVERYTHING WORKS NORMALLY AGAIN.
I can add product and they are saved in Shopping Cart even after refresh or clicking any links the same site or any other site in the same site.com/b2b/ directory.
If anyone has ANY insight, I would be immensely grateful.

Refresh of Shopping cart on item added

i am currently building a custom shopping cart to my website, it has all the items on the left and a slim view of the basket on the right with a list of all the items added plus a total value price. What i want is for the price and list to update when a user clicks on add to basket, but i don't want the page to reload, i know that AJAX can be used for this, but i was wondering if anyone had any tutorials that could show me some examples of being able to do this.
I am just getting a bit confused at the moment.
Thanks
there are many ajax shopping cart examples on internet, you can find them on google... for now here are some links for you
http://tutorialzine.com/2009/09/shopping-cart-php-jquery/
http://www.99points.info/2010/12/ajax-shopping-cart-with-jquery-and-php/
more than two hyperlinks are not allowed for me to post so i am posting hyperlinks without http :
net.tutsplus.com/tutorials/php/how-to-build-a-shopping-cart-using-codeigniter-and-jquery/
webresourcesdepot.com/ajaxed-sliding-shopping-cart-with-jquery/

Categories