Best practice for changes in Woocommerce core functions - woocommerce

There's a woocommerce_single_variation_add_to_cart_button() function in woocommerce/includes/wc-template-functions.php that I'd like to change slightly. Specifically this function output several DOM elements and I need to insert one custom element in between those elements. Obviously I won't make the change in that file otherwise my change will disappear upon next update.
Is there a widely accepted way to override such core PHP function in WooCommerce?

Related

Display a specific existing widget in a WordPress theme, bypassing sidebars

Is it possible to display an existing widget (configured via the widgets control panel) in a WordPress theme bypassing the whole "sidebar" thing? It may not be good practice, but I sort of expect this to be possible - and can't find a way to do it.
I've read about "the_widget", but looks like this function call creates a new one (complete with new title, text etc) instead of reusing a widget that I have configured in the control panel.
If this is not possible - I'll have to use the sidebars, but hoped to avoid doing it in several specific places, seems overkill.
Thanks for any help.
Yes, you can. Just look on the specific widget's code, you'll find the function that the sidebar calls, call that function right on the theme passing the parameters you need in an array.

Is It Possible To Override A Core Class In WordPress

I am attempting to make the sidebar in WordPress be made of a single unordered list. I am about 99% of the way there, but to get to that last 1% I am going to have to change the way that Widgets generate.
To be more specific, in default-widgets.php, the class called WP_Widget_Recent_Comments, function widget, there is code that generated a <ul> tag. I would like to remove that code and just return the <li> tags.
Now I do not want to have to do this every time WordPress needs to be upgraded.
Can someone tell me what the best practices would be to do something like this? I am very interested in maintaining a dynamic sidebar, but I do not want to do this at the cost of upgradeability.
You should not change the core files instead create your own widget using widgets api, here are some links for you
WordPress Widgets Api, another useful article about a step by step tutorial and a plugin here with comprehensive control about their appearance Get Recent Comments, hope it helps.

Showing only items in user's current language in full_review_list for Plone > 4.0.7

A recent change (link to Google Cache as d.p.org seems to be down right now) to the way Plone calculates the review list for the full_review_list view. In order to support LinguaPlone better, WorkflowTool now explicitly adds a Language='all' to the query used to retrieve a worklist, whereas before only results in the user's current language were shown. The code is in Products.CMFPlone.WorkflowTool#getWorklistsResults().
Is it possible to override this new behaviour to obtain the old behaviour?
We really ought to make that customizable via a ZCML override, but you're right, in that form it's not overridable simply. So no matter what approach you're going to take, you'll have to copy that method and modify it somewhere else and then hook it in so that your customized version takes precedence.
Where do you need to see the changes? Just in the initial review list portlet? In that case, just override the renderer for that portlet, add a method to the new renderer, copy in the code, make your changes, then override the renderer to use the renderer method instead of the one on portal_workflow.
If you want to see the changes in the full review list you click through to from the portlet, then you'll have to use collective.monkeypatcher to patch the method on portal_workflow. I'd recommend against this, since you probably want someplace where users can go to see the full review list with all languages.

Alowing end user to have specific CSS rules they can modify

I would like the user to have limited access to controlling certain CSS attributes of divs. The divs would all be similar, all have a some class name, and be displayed across the site with the styling rule of the user. So kind of like a user CSS stylesheet, except with certain rules that they can change.
Allow change to:
.className{
font:all attributes;
all four borders:all attributes;
float:cannot change;
}
Would the best way to be to store these in a database? Store the color, border width, etc in a MySQL database? Seems like a lot, with all of the information.
Allowing the user to have their own CSS document is risky, and I do not want them to be able to change the layout. I want to make this a part of my site, one anyone can use with no knowledge of CSS. I would like for them to have their choice of styles; like letting them have their own theme on a Drupal site, but make the changes easy to make for anyone (like have a list of pre-defined or something). But also they must have full control if they want, of the attributes I allow them to change.
Would preprocessing this information from a database and putting it in a style tag be inefficient? Seems like a lot of queries unless it was all in one query.
You should check out the jQuery UI ThemeRoller script, it uses a number of fields which are passed via the URL. Click on any of the themes on the left and see what happens to the URL.
You could easily replicate it to fit your needs, and instead save those values in a database. You could use the same naming convention too, if you like.
I think it's a great place to start.
To have your users able to generate and preview the styles dynamically, they must be parsed with Javascript (or server side to get tricky). Either way, you have to get a CSS rule out of it somehow, so you might as well do it before you throw it into the database. You're doing what you were going to do anyway, but saving yourself the trouble of making a big table.

Controlling UberCart checkout pane hook priorities

I'm using Drupal 6.15 with ubercart 2.x and I'm trying to implement ubercart's hook_checkout_pane() to override their default uc_cart_checkout_pane(). My goal is to disable some of the default checkout panes - customer information and order comments.
I made a function my_module_checkout_pane() in my_module.module and it does get called, but the uc_cart version seems to be generating what's actually rendered.
I understand why both functions get called and I can change the order they're called in by modifying my module's weight in the system table, but doing so doesn't seem to affect what ends up on the page. Whether my_module's function is called first or second, the uc_cart version is what's rendered. The only way I can get my function to affect the page is to actually alter uc_cart_checkout_pane() so it doesn't return any output but that's not a "good" solution.
Is there some other place I need to do something to make Drupal favor my hook implementation over uc_carts'? Alternatively, is there another way to accomplish this?
you can enable or disable checkout panes in "Checkout settings".
btw: no need to alter module weights, you can do this with pane weights.
If I'm not mistaken, hook_checkout_pane is for creating new checkout panes, not overriding default ones. Seems like you'd use hook_checkout_pane to make your own pane and just use that instead? See http://www.ubercart.org/forum/development/11698/alter_checkout_panes
Apologies if I'm mistaken.

Resources