How to add custom class to functions in wordpress - php

I have a wordpress website on localhost, and I want an add to cart button.
I've used a wordpress function for the same, but I need design that of what I've made.
The function I've used is:
print_wp_cart_button_for_product()
I just wanted to know how do I add class to the button which is generated from the above function.
Thanks

I don't have the correct solution to your problem, but what you could do is inspect which classes/id there are already added (in your browser > inpect).
You could define these classes in your CSS and override them with your own styling.

Related

Add an element to a hook with a FrontController

I am currently developing a prestashop module where the user can add as many visual elements (an accordion) as he wishes. I finished the configuration of the back office with my own database, everything is ok on that side.
The problem comes from the fact that depending on the hook chosen by the user (displayHome or a custom hook) the visual element will be added to it.
During my testing phases, I managed to display the corresponding visual rendering on the displayHome hook, via this method in my main file :
public function hookDisplayHome($params)
{
$this->context->smarty->assign([
//...
]);
return $this->display(__FILE__, 'my_file.tpl');
}
The prestashop documentation for the FrontController explains how to configure it for visual rendering on a custom page, but nothing related to hooks.
I tried a similar process with the initContent() method but it doesn't seem to work.
I think that if() will be enough to assign the variables to different places according to the choice of the user. But if I can't just display it, I won't be able to think about it anyway.
How to interact with hooks via the FrontController ?

Where should WordPress pre_cache_alloptions filters be registered?

I have customized some wp-option return values with the dynamic pre_option_{option} hook and for completeness would like to also override these option values when they are returned via wp_load_alloptions(). This function has a hook that is available to allow for this customization: pre_cache_alloptions.
However, although the hook exists there doesn't appear to be any way to call add_filter("pre_cache_alloptions", ...) early enough for it to take effect before the first call to wp_load_alloptions(). Since wp_load_alloptions() is called very early when loading WordPress, and since the values are cached on first-call, I haven't been able to register the hook in time for it to take effect. I have tried calling add_filter("pre_cache_alloptions", ...) during a mu-plugin load and also in a custom theme functions.php file, but neither of those places appear to hook in early enough for this to work.
The only solution I have found so far is to hack the actual wp-includes\plugin.php file and add in the add_filter("pre_cache_alloptions", ...) call right after the require of class-wp-hook.php at the top. This does work as expected when registered at that code point... but I'm searching for a way to register this filter so that it works without altering the core WordPress code.
Since this hook must be registered after the add_filter() function is declared in plugin.php, but before the first call to wp_load_alloptions(), the only user-customizable code point that appears to work is the optional custom db.php file, which is loaded in wp-settings via require_wp_db(). Adding a custom wp-content/db.php file with the necessary add_filter("pre_cache_alloptions", ...) reference at the top works as a means to register this customization in time for it to be useful. After much searching, this appears to be the only way to handle this without mucking with the core itself.

What is the alternative for WP_List_Table CLass in WordPress?

WordPress plugin developers use WP_List_Table class for build HTML tables in admin panel.
But, WordPress official documentation has following note in here.
This class's access is marked as private. That means it is not
intended for use by plugin and theme developers as it is subject to
change without warning in any future WordPress release. If you would
still like to make use of the class, you should make a copy to use and
distribute with your own project, or else use it at your own risk.
Then, what is the alternative to build HTML tables in WordPress admin panel?
There is no alternative to this.
But what you can do is copy and rename the WP_List_Table class. So it won't be affected if WordPress changes the class or the class becomes deprecated.
You can make your own admin pages based in the html of pages like "pages" or "post", create a view for add, another for edit and for list obviously, you have to create your custom page by add_menu in the functions.php and create your own file. Once you have that file you can do whatever you want. You can also work with your own custom tables into wordpress database.
Of course all depend what you want to do, but my suggestion is to use WP_List_Table Class.

Is there a way to register hook NOT creating the module in PrestaShop?

I'm working on my own store, and I want to add some custom functionality. But this functionality is not something standalone, so I'd prefer to completely implemented via overriding controllers/classes and not to create a separate module for this.
But I have to use some hooks (for example - displayAdminProductsExtra to add new tab to admin product page, or actionProductAdd/actionProductUpdate to make some custom edits to DB). I know the way to use hooks from within the modules, but I cant find the way to do without creating my own module).
So the question - is there a way to do so?
Thanks in advance.
Hooks are only meant to be used with modules.
When Hook::exec() is called it will first check if a module is attached to this hook and stop otherwise.
Here is the related code:
// If no modules associated to hook_name or recompatible hook name, we stop the function
if (!$module_list = Hook::getHookModuleExecList($hook_name)) {
return '';
}

What's the best way to include custom HTML in a Symfony form?

I'm working with a Symfony generated admin and need to include some custom HTML into a form. This HTML (a label, img tag, and link) should only appear when the action is 'edit'. What's the best way to do this? It seems like I should just be able to include a partial, but I don't know where to include it from. Thanks.
Depending on the functionality you want the partial to have you could also write a custom widget and use your custom widget instead of the standard symfony one.
(I use this for a widget wich displays me various sizes of images after a file upload)
I think I found the solution:
I created a partial and set it to display within the moduel's generator.yml file (in the 'edit' section)

Categories