Woocommerce 3.8 changed price not showing change in frontend - php

I have a price update on all products to sync the shop prices with a web service XML. This is the part that updates the price. It's run with a server cronjob every hour. The problem is that, although I can see the prices updated, in wp-admin edit product pages, in the admin product list, and in the front end it still shows the old prices.
$product = new WC_Product( $pid );
update_post_meta($pid, '_regular_price', $set_price);
update_post_meta($pid, '_price', $set_price);
$product->set_regular_price($set_price);
$product->set_price($set_price);
$product->save();
What am I doing wrong here?
Just an update something i just notice, for example on products that have the the sale_price set, on the admin edit page its all ok but on admin list product page and frontend the sale price shows the regular_price.
After more digging it seems that the issue maybe related to the save instruction. All the fields are populated correctly with the changes, so if i go to edit product page and add a change, i.e. add a 0 in regular price and then save it assumes the changes made.
Is there a way that i can see the query executed by wordpress/woocomerce when pressing the save button on a edit product page?

Yes, it is a cache problem for WooCommerce when you programmatically changed the product prices.
Not sure you have solved it or not, I have the same issue as your one, I update the price programmatically with WC hooks but the price was not updated in the related products slider.
I solve the issue by adding following code to my theme:
// Handling price caching
add_filter( 'woocommerce_get_variation_prices_hash', 'add_price_multiplier_to_variation_prices_hash', 99, 3 );
function add_price_multiplier_to_variation_prices_hash( $price_hash, $product, $for_display ) {
$price_hash[] = get_price_multiplier();
return $price_hash;
}
all credits belong to this post, you can get more information on why use that.
Hope it helps anyone who runs into the same issue. Have a good day!

Yeah, sounds like a Cache problem…
Clear Cache in Your WordPress Caching Plugin
If you are using a WordPress caching plugin on your site, then you need to clear your plugin cache. Most caching plugins allow you to easily do that from the plugin’s Settings page.
Clear Cache in WP Rocket
WP Rocket is the best WordPress caching plugin on the market. The best part about using WP Rocket is that it proactively builds your WordPress cache in the background, so your users are always served a cached version.
It also makes it very easy to clear caches files with a single click.
Simply go to the Settings » WP Rocket page and click on the ‘Clear Cache’ button under the dashboard tab.
WP Rocket will now clear all cached files for you.

Related

Woocommerce hook that fires after a product stock quantity is updated via REST API (clean cache)

I hope you can help me with this question I have.
I have Woocommerce that updates the stock quantity via REST API, however I use the caching plugin WP Fastest Cahe, and it only clears the product cache if it is manually updated by WP Admin (backend) when the API updates the amount of stock the plugin does not trigger the product cache clearing. They do however provide a hook for that purpose which is //it clears the post with ID 1923
wpfc_clear_post_cache_by_id(1923); the link that explains it all is this https://www.wpfastestcache.com/tutorial/delete-the-cache-by-calling-the-function/
I am not a programmer but does the code below work? What can I do to trigger the hook when there is the API update ?
Any tips?
I would be very grateful for some help :)
add_action( 'woocommerce_update_product', 'remover_cache_produto', 10, 1 );
function remover_cache_produto($product_id) {
$product = wc_get_product($product_id);
wpfc_clear_post_cache_by_id($product_id); //clean cache
}
You are using the woocommerce_update_product action hook, which fires when you are updating products from backend of wordpress as well from rest api.
So your function with the name remover_cache_produto executes when you are updating products via rest api. You are using the right action hook.
In your function you create a variable $product, which you are not using. So you can get rid of that line.
Put the code into the functions.php file of your theme or create a little wordpress plugin to make it work.

Strange WooCommerce database related issue

I have a strange WooCommerce issue on one of my sites. It's a popular webshop with thousands of products. Most likely the issue is there for a long time but we just noticed it.
The problem: A lot of products are not showing up on the frontend. All of those are visible in the backend, all of them are live, all of those are in stock. So they should show up. Some of the store products are visible, some of them are not. There's no logic in this. BUT... if I just edit a missing product and just simply re-save it in the backend it shows up in the frontend right away.
Most likely the issue is related to the 2.x to 3.x database upgrade: "3.0.0 instroduces a new product visibility taxonomy; catalog, search, hidden, featured, outofstock are terms. These are set on upgrade and help filter products in the catalog during frontend queries."
My theory is that this database upgrade didn't finish at that time for some reason.
So the solution would be to run it again or to find an automatic way to emulate the "save" feature that I do manually if I edit and save a missing product in the backend. But the manual way is simply not an option when I have thousands of products.
I just want all available products to appear in the frontend too. Do you have any idea how can I solve this?
P.s: I have already tried switching back to a default theme and disabling every other plugin except WooCommerce. It's clearly a database related WooCommerce issue. And yes, I have the latest WP and the latest 3.x Woo. The PHP version is 7.2.
Thank you in advance!

WordPress + WooCommerce - disabling cart AJAX (fragments) in 3.4.0?

WooCommerce has a script that runs on every page, upon every page reload, that adds 1-3 seconds to loading time. It's the "wc-ajax get_refreshed_fragments" function.
All this does is check whether the shopping cart totals have changed. Which is nice to have on the product page - but completely unnecessary on the home page or category page or any of the text-content pages.
There are manual methods (dequeue script commands to be added to functions.php) and plugins (PerfMatters, LittleBizzy's Disable Cart Fragments, etc) to remove this, which worked... right up until the latest WooCommerce update.
Is there a solution for disabling this script, in the latest version of WooCommerce?
Unfortunately your information is wrong:
PerfMatters (Brian Jackson) took their code from our GPL plugin without credit, which was originally shared by Jeff Matson on his blog back in 2016 (credited in our readme).
wp_dequeue_script('wc-cart-fragments');
Disable Cart Fragments still works fine in WC 3.4+
If it's not working on your site, most likely your theme is to blame... confirm by activating a different theme and disabling all other plugins that may be enqueuing the cart, etc.
Update: since so many people are now referring to this thread, I'd like to once again confirm that Kinsta (web host) is now promoting the stolen code from LittleBizzy plugins, and have contacted me to state they have nothing to do with PerfMatters. When I asked them when they'd be removing all the links and promotional material on their website for PerfMatters, they went silent...
P.S. Thanks to WP Engine and WP Rocket for crediting us! :)

Display Custom Options from Simple Product into Magento 1.9.0.1

I am creating a simple test product in magento and trying to add some custom attributes for variants. Unfortunatly these are not showing up in the front end.
So I'm pretty sure it's a theme issue here...
When I add a custom product option such as a drop down, the Add to Cart button vanished and can no longer be purchased... as well as now showing the dropdown.
Any thoughts would be greatly appreciated. Is there a directory to look this stuff up in?
I've added some photos in case my description wasn't clear enough
Thanks
Try clearing your caches
Check the inventory tab, if product is saleable on frontend (in stock and has qty)
check /var/log/ and /var/report for errors
calling isSaleable() on the product object can direct you as well (this check is also in product actions template where the add to cart button is rendered)
Just a note but if you have product variants (say size) you probably want to use configurable products instead of custom options
I have had same issue in my new magento 1.9
I just clean all caches from var/cache
Also clean your cache from magento admin.

Magento - Programatically added bundle product isn't available for the basket/frontend

I followed this answer which works fine: Magento - Programatically added bundle product isn't showing up in frontend
I'm able to generate a bundle product on the fly. Everything works fine.
Only one problem: My bundle product is correctly saved and I can see it through the admin area. But, after this generation on the fly, I have to add directly this product into the basket. The system returns "product not found". Basically, I have to go into the admin area, just save it and then I'm able to add it to the basket.
I really suspect a problem with the indexer but I can't really figure out what's going on.
I tried many solutions like:
Mage::getSingleton('index/indexer')->processEntityAction(
$product,
Mage_Catalog_Model_Product::ENTITY,
Mage_Index_Model_Event::TYPE_SAVE
);
But it still doesn't work.
Any Idea about which code I should trigger after the save method to index only this new added bundle product.
Thank you in advance.
Sounds like you are not creating a stock-item with your product. Therefore there is no stock and you can't add it to your basket?
Have a look into
/app/code/core/Mage/Adminhtml/controllers/Catalog/ProductController.php:672
/app/code/core/Mage/Adminhtml/controllers/Catalog/ProductController.php:571
where a product is generated and the stock data are cleand up / set with default data

Categories