How to override the fncatelog.php function in cscart - php

I need to override the fncatelog.php in cscart in my new addon.
My addon files :-
1. app/addons/newaddon/frontend/controllers/frontend/categories.post.php
2. design/themes/response/templates/addons/newaddon/overrides/blocks/product_filters/original.tpl
In func.php
I need to override the fn_get_filters_products_count() this function in my newaddon.
How can I do . Please help me.

You can not override the whole function. But you can use hooks to modify input arguments and returning argument.
In your case hooks are
get_filters_products_count_pre to modify input args,
get_filters_products_count_before_select_filters to change query param
To know more about cscart hooks please use this link - http://docs.cs-cart.com/4.3.x/developer_guide/core/coding_standards/hooks.html

You can use one of the following hook to modify data returning by this function:
get_filters_products_count_pre
get_filters_products_count_before_select_filters
get_product_filter_fields
You can read more about hooks system in CS-Cart at the http://docs.cs-cart.com/4.2.x/addons/hooking/index.html page.

Related

How to use hooks in child theme to override a plugin?

I want to add some HTML code to a plugin but I want to do that in a child theme, the function that I wanna override it is in a file named as admin-functions.php
I want to add extra buttons to booked_render_custom_fields function
admin-functions.php:
function booked_render_custom_fields($calendar = false) { ?>
<button class="button">Text</button>;
<?php }
any suggestion? thanks
you can't really override a function like that. you can only use the filters and hooks that the plugin implements. but you got some options:
a) make a copy of the plugin, change it's name and make the changes you need. after that, it wont get updates anymore. you'll have to implement them manually.
b) you could add just one line to the original plugin and define a filter or hook to which you subscribe in your functions.php . so you only have to fix this one line after updating the plugin.
c) since the newer versions of wordpress, you have the possibilites to run your own code after any shortcode. so you could add or inject your own html into the output of the shortcode. https://developer.wordpress.org/reference/hooks/do_shortcode_tag/

How to hook a function into filter in a class of plugin from wordpress

I am not very old on Wordpress.
I am developing a website which has a Third party plugin having class Plugin_Class and there are some filters in the construct of it. I want to hook my additional function to filter Plugin_filter_1 from functions.php.
I have tried with the syntax add_filter( 'Plugin_filter_1', array('Plugin_Class', 'my_function_defined_in_functions_php' ) );,
it gives me error even if the class is visible ( checked with get_declared_classes() )
The detailed answer will be appreciated
Thanks for your help
Regards
Possibly the issue is that your second parameter for add_filter is an array with Plugin_Class as the first element- this means wordpress will try to fire PluginClass::my_function_defined_in_functions_php, which doesn't exist.
Instead, just pass it a string of 'my_function_defined_in_functions_php'.
If this doesn't work with just this edit, show us the code in the plugin class- including the class name and entire construct method. There are more possible issues.

WordPress hooks for executing right before any action or page loading

I'm quite new to WP. Task is to develop a plugin for oauth authentication on one of not popular openID providers. I did the same for CodeIgniter project, but WP is a CMS and is little bit complex for me to understand. In Codeigniter i check authorisation before each action. In WP i need a hook which uses for it... before each page printing, or maybe.. it would be right to say before each action in terms of frameworks. What is this hook's name?
Last hook before loading the template is template_redirect
You can use it like this:
function my_function(){
// your code goes here
}
add_action( "template_redirect", "my_function" );
You can use init hook. It will be performed before element or HTML code. It's also useful to manage POST and GET variables. The syntax is something like this:
function yourfunction() {
dosomething();
}
add_action('init', 'yourfunction');
A list of all available hooks can be found here: https://codex.wordpress.org/Plugin_API/Action_Reference
Information about Hooks: https://codex.wordpress.org/Plugin_API#Hooks.2C_Actions_and_Filters
Other hooks must be suggested and will be added in a future release if is a good suggestion.
Or you'd have to edit the core files ;)
You mean a hook when all wordpress function will available but before any output including headers sent?
Well hook your function on init. That will call when visiting site. If you want this hook only for admin area then it is admin_init.

Can I override a PHP Function that is called in another file/plugin?

First of, I have read "Override default php function" and namespaces doesn't fulfil my need. I have also looked into PHP.net's override_function() but that can't help me with my problem either.
I am using a Wordpress plugin called Jigoshop as an eCommerce solution but in some cases I cannot remove the actions I need to apply my own structure to a 'single product' page. I do not want to edit the plugin files themselves as a plugin update may negate and remove my previous changes. Essentially, I want to control the output through my /themes/mytheme/functions.php file.
Has anyone come across this before whereby the original function is contained in a file I do not want to edit for that same 'updating' reason?
Thanks
EDIT (2012-11-21):
I have a custom function in my functions.php file like so:
function prepare_jigoshop_wrappers() {
remove_action('jigoshop_before_main_content', 'jigoshop_breadcrumb', 20);
add_action('jigoshop_before_main_content', 'custom_jigoshop_breadcrumb', 10);
}
add_action('wp_head', 'prepare_jigoshop_wrappers');
This essentially allows me to apply my own structure & configuration. For other default functions, it is a little more difficult. For example, the 'quantity selector', 'Add to Cart' button and 'stock availability' all are contained within a function called jigoshop_template_single_summary in the jigoshop_template_actions.php file calling the likes of _title, _price, _excerpt, _meta, _sharing & _add_to_cart.
The order these are displayed, I cannot seem to change. Therefore, I want to essentially redefine function jigoshop_template_single_summary() {...}
You may want to look into PECL extension. It may do what you need, docs on PHP.NET.
runkit_function_redefine
(PECL runkit >= 0.7.0)
I don't know this plugin very well but probably this is what you Need Theming with Jigoshop
Override some functions in php(also in common..) is never a good idea. If the plugin doesn't provide a way to hook into it's functionality is sometimes better to use an alternative plugin or rewrite the core code..

How can i create my own hook in drupal6?

How does drupal create its own hook. Similarly i want a customized hook for myself. How am I to proceed ?
May be you are looking for module_invoke_all
Some useful links to start with:
Creating hooks for your Drupal modules
How hooks are invoked with module_invoke_all()
If you have a hook that passes a parameter by reference, and you can not use drupal_alter (for example a presave hook that passes in more than one argument) you can use module_implements.
This way a module could implement it as modulename_foo_presave instead of modulename_presave_alter. It is good for when you you want to let modules alter something at multiple points in its life cycle.
For an example in drupal core checkout the code for the node_validate (drupal 7).
foreach (module_implements('node_validate') as $module) {
$function = $module . '_node_validate';
$function($node, $form, $form_state);
}
from http://api.drupal.org/api/drupal/modules%21node%21node.module/function/node_validate/7
The same approach works in Drupal 6 if you want to create hook that can be implemented in this way.

Categories