How to apply coupons to CoCart plugin? - wordpress

I am using CoCart plugin with WooCommerce. I have a cart with products and the plugin counts me the totals and actually everything. I would like to apply coupons, I made a plugin for this, but I had no idea how to get the cart which had been initialized with CoCart. I tried this: WC()->session->get( 'cart_totals' ) and this: WC()->cart, but in both cases the session and cart is null. So I need a solution to make it possible to get the previously created cart.

a mildly different Solution is discussed in this thread, have a look. below is the excerpt copied from there. the question was initially asked by msargenttrue and answered by Freney
the post suggests that you need to do a manual implementation in PHP which is just copypaste , and call the script to apply on the intended product in database. THREAD <-- the PHP implementation part
FOR the problem
So I need a solution to make it possible to get the previously created
cart.
you must try the js implementation of local storage, the stored item remains on the user device until the cart is cleared explicitly.
localStorage.setItem("cart", "CartID-002");
localStorage.clear() #when you want to remove.
Points to remember
The main features of localStorage are:
Shared between all tabs and windows from the same origin.
The data does not expire. It remains after the browser restart and
even OS reboot.

Related

Can't access to product's reviews in WooCommerce when using Gutenberg as editor

I know that Gutenberg isn't supported on Woocommerce, but I'm trying it anyway and so far is quite good. Im doing it by:
function wplook_activate_gutenberg_products($can_edit, $post_type){
if($post_type == 'product'){
$can_edit = true;
}
return $can_edit;
}
add_filter('use_block_editor_for_post_type', 'wplook_activate_gutenberg_products', 10, 2);
What I notice that there is error when trying add some of the Woo blocks in products, so I decide to disable Woo blocks on products to avoid it. Works ok now.
But in backend and can't access to reviews. I see only comments section but this not working at all. Does anybody dealing with that somehow?
I found this thread trying to find a solution to your last part too.
When I have Gutenberg active on products, even with reviews enabled in WooCommerce settings, when I go to:
Product Data
Advanced
and try and toggle the "Enable Reviews" option
When I save and then refresh the change doesn't seem to take so I am unable to turn reviews on if they are currently off or turn them off if they are currently on.
I have tried to test all of the other options and checkboxes like virtual and downloadable and they all seem to save fine it just seems to be this one setting that doesn't get saved.
I am keeping note of everything I find on the matter and if I manage to find a solution I will come back to share. I'm not sure if it will help with your other issue though which I haven't faced.

How to create Child Plugin for wordpress

Actually I have changed some code in WordPress Store Locator. I want it to remain when plugin will update. So I want to create a child plugin for that. Any ideas on how I could manage it?
This varies plugin to plugin, and it sometimes isn't even possible, other times plugins have documentation to extend them easily (such as WooCommerce and Gravity Forms). Some of them create Action Hooks with do_action() that let you extend the functionality easily. A common example is updating a post after a Gravity Form is submitted with their gform_after_submission hook.
Effectively, it depends on what you want to do, and how the plugin implements the functionality you want to change. If they add text with a Closure or Anonymous Function, it will be harder to modify said text, and you may have to look at something strange like doing a run-time find and replace using Output Buffering, typically on the template_redirect hook.
If you want to remove something a plugin does, you can often unhook it with remove_action. This can be a bit tricky depending on how the plugin is instantiated, sometimes its as simple as:
remove_action( 'some_hook', 'function_to_remove' );
Other times it's more complicated like:
global $plugin_class_var;
remove_action( 'some_hook', array($plugin_class_var, 'function_to_remove') );
Those are the basics of extending (or even 'shrinking'?) a plugin's functionality, and it's not always doable appropriately. Unfortunately the narrow answer to your question is outside of the scope of what we can provide from StackOverflow.
From here, you'll need to figure out exactly what you want to do with the plugin, and dig through the plugin's files to see if there's an appropriate hook or function you can use. If you're still stuck, you'll need to post a new question (don't update this one) with your exact desired result and anything you've tried, and the relevant code that goes along with it. "I want to change a plugin without editing core files" isn't nearly specific enough. "I want to replace an icon with a custom icon in this plugin, here's what I've tried" is specific enough to possibly answer.
Good luck!
I just went through myself and I had so many changes that I couldn't just override the actions.
I created this tool that allows you to create a child plugin like a child theme. You can make updates to the plugin and still update it without losing your changes.
I'm posting this here because it relates and hopefully becomes useful to the next person who runs into this issue.
https://github.com/ThomasDepole/wordpress-child-plugin-tool
As per WordPress standard, it's called plugin's addon.
if the plugin has provided any action to update that functionality then you can use it with your addon (child plugin).
Here I am sending a link for reference.
https://developer.wordpress.org/reference/functions/add_action/

woocommerce attributes not showing on front end

I have setup a Woocommerce store with hundreds of variable products (months ago). Everything has been working great with product variations/attributes so far, but today I got a message saying that customers are unable to pick a size for some of our products.
So, I have been looking into this, but I do not see why this is not working as intended...
I have set the attributes correctly on the back-end, I know this because it has been working as intended for the last 6+ months. I have also looked at the attributes & variations settings for these products, and they are all still set correctly.
Then, I double-checked to make sure the variation still had a price set, which it does.
Then, I checked the front-end of the site, and sure enough, the "size" attributes no longer show any options.
Any thoughts on why this might be? I have looked around stackoverflow a bit already... and the only thing I have found that I haven't tried yet, is: disabling all the plugins and reverting the site's theme to a default theme... I am really trying to avoid going down that road...
Sample URL (manually set product "Size" attributes on product page back-end):
https://www.worldequestrianbrands.com/product/contour-all-purpose-pad-with-bare-flaps/
Any/all help is greatly appreciated!
WordPress: 4.7.4 - WooCommerce: 3.0.5
Update #1:
Follow up:
After investigation, and an email from a fellow stackoverflow user, I have narrowed this down to a plugin version incompatibility with WooCommerce 3.0.5. Rolling back to WC 3.0.4 restored all the products' custom attributes to the front-end of the site. I am not sure what or why this issue happened, all I know is that rolling back WC was as a temporary workaround.
More Info:
When I first posted this issue on stackoverflow, I was running WC 3.0.5. When running that version, this was my experience:
I have Variable Products setup with multiple Custom Attributes (set for each product, not through the WooCommerce > Attributes settings admin-sidebar feature of WC).
If I went to edit a Variable Product with custom attributes, all of custom attributes showed up fine on the back-end, but only 1 of the custom attributes would not show any options on the front-end (e.g. "size" attribute).
Looking again at the back-end of the product, the size attribute is listed, with variations, and a set price.
I tried clicking "Update" on a product, just to see what would happen, and when the back-end page reloaded, the custom attribute I set was gone (e.g. "size").
So, I figured it wasn't loading that Custom Attribute for some reason, so I went to the proper: WooCommerce > Attributes, and set the "size" attributes there
Then went back to the variable products, and added the newly set "size" attributes, from the proper WooCommerce > Attributes that I setup
Clicked "Update" to commit the changes, and there we go, now the "size" attribute shows up correctly on the front-end
I manually updated over 100+ products this way
A fellow stackoverflow user emailed me and mentioned he had the same issue, but rolling back to WC 3.0.4 worked for him, as a "workaround"
I rolled WC back from 3.0.5 > 3.0.4, and boom, all the Custom Attributes we have set are now loading on the front-end of each product, as intended.
So, after all of that... I am still not sure exactly what is causing the issue, all I know is rolling back WC seems to allow certain Custom Attributes to be displayed again, on the front-end.
If I find out anything else, I'll be sure to update here!
Thank you again for any/all help with this! I am glad this 'workaround' is possible, for now, but the root of the issue is still unresolved.
I have not looked at any PHP or any other server logs yet, due to limited time, but I am happy to report any follow up info I can - or the actual issue AND solution! :)
Any other insights are greatly appreciated! I am still curious why this is happening...
Cheers!
Update #2:
This seems to be a known issue with WooCommerce 3.0.5, as stated on github
"We've identified the cause of the errors. This issue happens when you have a custom attribute with the same name as a global attribute. We're working on a fix now."

How to solve it-updating plugins in wordpress?

I have made modifications in several of the plugins in wordpress. But
these plugins are now outdated. I have to submit the project to the
client. The client is asking me to update the plugins. But the problem
is that when I would update plugins, the changes that I made in
plugins would have gone away. So, I want to ask is there any concept
of child plugin in wordpress and if so, how to create it; so that my
changes would remain intact.
I don't know which plugins are you using so I am giving an example of WooCommerce Delivery Date plugin. I have disabled updates for that plugin and I have used below code to achieve it :
/* Function which remove Plugin Update Notices – WooCommerce Delivery Date*/
function disable_plugin_updates( $value ) {
unset( $value->response['woocommerce-delivery-date/woocommerce-delivery-date.php'] );
return $value;
}
add_filter( 'site_transient_update_plugins', 'disable_plugin_updates' );
Just edit the version of the plugin to more than the latest version :
Go to wp-content/plugins/your-plugin/your-plugin.php
generally your-plugin.php is the main file of the plugin and it is having version in the top commented line.
Edit the version of the each plugin
Otherwise install a plugin your admin that will disable updates. Get this plugin from here : https://wordpress.org/plugins/disable-wordpress-updates/
If you're looking to keep a good name, I'd find a way to achieve making the necessary changes without modifying plugins in the first place (this is a bad practice, as I'm sure you know). When people purchase your product or services, they want to know they're not getting a "bad egg" or a "lemon deal"; and that their investment is actually an investment and not a complete waste of effort, money and overall time.
Updates are important! What if they are handling sensitive information on their site? What if their host requires a specific plugin to be a certain version?
Make your change in another way, write your own plugin, include the functionality in a child-theme; you can even handle certain "modifications" by using jQuery to manipulate elements in the DOM (include it in your child theme).
Just don't do something regrettable as some others have suggested. This is only going to last until the next update is released and lead to trouble, a bad reputation, or legal action. Integrity is all a man has. If you throw it away, you're worthless.

Woocommerce/Wordpress Update Transient Values for Layered Navigation

I am writing an addon for the WooCommerce plugin for Wordpress that allows product imports from an excel spreadsheet. All the products import just fine, but I am having trouble updating the layered navigation in the store sidebar. Each item has a manufacturer assigned to it on import and the manufacturer attribute is being set just fine. However, the layered navigation is not being updated - in fact it doesn't even show up unless I manually update an item.
After doing some digging, it looks like the layered navigation uses an option from wp_options called _transient_wc_ln_count_(hash) to store the count/ids of the items with that attribute. I think this is what I need for my script to work properly, but I can't find any documentation/examples about it. I'm hoping there is just a function that I can call to update the transient options. Can someone point me in the right direction?
So I never figured out the exact answer to this question, but I found something that works. After using wp_insert_post to initially add the post, and then inserting the post meta (including the manufacturer meta) with the resulting post ID, I am calling the wp_update_post function which triggers all the automatic update functions for that item, including the transient count issue. Now my product manufacturer count in the sidebar is correct. Hope this helps someone else!
After the upload you can simply call delete_transient( 'wc_attribute_taxonomies' );
That's where the transients are created: http://oik-plugins.eu/woocommerce-a2z/oik_api/wc_get_attribute_taxonomies/
See also: https://wordpress.stackexchange.com/questions/119729/create-attribute-for-woocommerce-on-plugin-activation

Resources