Stripping out fields from Variation in Woocommerce - woocommerce

I'm going to go ahead with what i'm suggesting here, but i thought i'd try and get someones thoughts at the same time
Cutting off the fat
I've got several products with 700+ variations. This becomes an issue with wordpress saving that product because it panics when it tries to save 8000+ fields and causes intermittent saving and ends up losing data.
However, looking at the variations in the backend, there are several fields that i'm not using in each variation:
weight
dimensions
virtual
downloadable
stock qty
sale price (and schedule)
etc.
If i remove these, thats at least 6 x 700 field = 4200 less fields that wordpress has to deal with, which would make saving an actual possibility.
I'm going to just defy the gods for this one and edit the woo commerce template directly to test it out.
I'm not 100% sure how to create a function that would remove these fields without harming woocommerce at this moment in time, if anyone know how, that'd be fantastic
I'll let you know my results.

I just dug around in the class-wc-meta-box-product-data.php file and there does not seem to be any easy way to remove built-in input fields. You would probably have to re-write the entire metabox.
What might be possible is a JS solution whereby you remove the fields you don't want. I am not sure at all, but if WooCommerce has proper isset() checks on all the variables its save routine then it shouldn't crash.
Or you could remove Woo's save routine and replace it with your own?
Woo's save action:
add_action( 'woocommerce_process_product_meta', 'WC_Meta_Box_Product_Data::save', 10, 2 );
This, like re-writing the entire metabox, puts you at risk of things breaking whenever WC is updated.
Just out of curiosity, how does one get 700+ variations?

Related

Is it possible (error?) that woocommerce automatically deletes a product from an old order?

I deleted products from the shop and emptied the trash (not me, but the automatic function in woocommerce). Then products DISAPPEARED from some orders! Not all products, only 1-1 products were deleted by the system from some orders.
These are old orders, but the time between the order and execution is long, so the order data is needed for a long time. These are not yet fulfilled orders, they are in custom status.
Fortunately, I have regular backups, so I was able to view the original state and put the product back again.
BUT I have a lot of orders and now I'm afraid that the phenomenon will happen again.
Have you ever heard of this? Is there such a built-in feature in woocommerce?
I looked for similar cases online, but couldn't find any. I hope someone knows what caused this to me.

WooCommerce Zip Code Pricing per Customer

Sorry I don't have any code to show yet as I'm just trying to find a solution.
I'm in need of a way to set the price of products based on the users billing zip code. I have a custom registration form, I was thinking of somehow figuring this out during that process. Basically after they fill out their billing info, somehow check their zip code and and apply a price for that customer.
I may be able to write a custom API that would take the zip code and return a price. But what would I do with this price? Store it in user_meta? Then I would have to override $price in a million different templates.
I have googled this and didn't come back with much.
What would the best approach be for this?

Best Way to Pass variable to Woocommerce Product?

Here is the setup.
Customer fills out form of information for product specifications. This creates an entry in the db with a unique detailsID.
They then are taken to a product page, with many variables. They select the variable product and checkout.
Now in the db they have an order as well as a separate table with the details of their request.
What is the best way to connect the product they bought with the detailsID?
I would like to basically pass the detailsID to the product page, then add this detailsID to the product. Or add the orderID back into the details table.
I keep going around whether to add this as meta data, or use a session, or just do post order logic to add the order ID back into the details table.
I really just need to link the two once the order completes but am not sure the best method to do this. I am pretty new to Woocommerce so don't know a lot of the hooks yet.
Thank you so much for your suggestions!
After a lot of research and experimenting here is the method I have decided on. This seems to add the information in a variety of places to make it easy to track orders and to insure that the customer is getting the customized product they want.
add custom data to woocommerce
I am using this method very close to how it is spelled out in this great article. This was really helpful for me being a woocommerce newb.

woocommerce - large number of variations for a variable product

I have a variable product with 3 attributes. The total number of variations generated is 900. This will make the admin page incredibly slow and hard to work with, so I need to find a workaround. I thought about replacing the dynamically generated dropdowns(for attribute values) with static ones, but the shopping cart expects to receive a variation number, which is non-existent in this case. I'd also like to mention that the variations are identical in all parameters, besides the attributes. How can I solve this?
Thanks.

Wordpress - SQL Query

Im trying to write a query to get all posts that are in a certain category that have been posted in the last 60 days, but im unsure as to where to find category information on posts in the database.
There doesnt seem to be any info in the wp_posts table.
Could someone help me form this query, im quite confused.
Cheers,
The reason why the post table doesn't have categories is because all that is done through the taxonomy system (more info) (which takes a few minutes to get your head around).
You can just use query_post() function to query posts from a specific category (see category__in on the linked page). That takes the headache out of taxonomy query.
Alternatively, if you don't want to mess with the main loop (which query_post will), you can create an instance of WP_Query and loop through them with that.
Edit: This page might also interest you

Resources