WooCommerce Product Slider Pro

  1. Home
  2. Docs
  3. WooCommerce Product Slider Pro
  4. Hooks: Actions and Filters

Hooks: Actions and Filters

A comprehensive guideline on how to use WooCommerce Product Slider Pro filter hooks. We have added the following hooks for developers to extend functionalities. Simply add the following custom code to your current theme’s functions.php file. It’s recommended to keep the code in the functions.php file of your child theme. Because you might lose your customizations if the theme is updated. Keeping the modified codes in your parent theme’s child theme is therefore the best practice.

1) How to provide the plugin access to the Editors

2) How to change the menu position of Product Slider Pro

3) How to load the style of Product Slider Pro in the header section

4) How to change the category slider image size

5) How to add Custom Fonts in the Typography

6) How to remove any Safe Web Fonts from the plugin

7) How to show current category-wise products

8) How to add Custom Google Fonts in the Typography

 

1) How to provide the plugin access to the Editors

If you want to give the plugin access to the Editor role users you can do it easily with the help of the following custom code. If you check the code you can see there is an action hook (sp_wps_shortcodes_ui_permission) available in the plugin which allows you to modify the plugin’s functionality.

// Give access to the Editors 
function sp_product_slider_pro_show_to_editor($capability) { 
    $capability = 'edit_others_pages'; 
    return $capability; 
} 
add_filter( 'sp_wps_shortcodes_ui_permission', 'sp_product_slider_pro_show_to_editor' );

2) How to change the menu position of Product Slider Pro

If you want to change the menu position of the Product Slider Pro on your dashboard then you can easily do it with the following custom code. If you check the code you will see there is a filter hook (sp_wpspro_post_type_args) available in the plugin which allows you to modify the plugin’s functionality.

// Change the menu position of Product Slider Pro
if( ! function_exists('sp_wpspro_post_type_args_modified')) {
    function sp_wpspro_post_type_args_modified ($args) {
        unset($args['menu_position']);
        $args['menu_position'] = 56;
        return $args;
    }
}
add_filter( 'sp_wpspro_post_type_args', 'sp_wpspro_post_type_args_modified' );

3) How to load the style of  Product Slider Pro in the header section

If you want to load the testimonial style in the header section you can easily do this with the following custom code. Just copy and paste the following code into your current theme’s functions.php file.

add_filter( 'sp_product_slider_style_load_in_header', '__return_true' );

4) How to change the category slider image size

If you want to change the category slider image size then you can easily do it with the following custom code. If you check the code you will see there is a filter hook (single_product_archive_thumbnail_size) available in the plugin which allows you to modify the plugin’s functionality. You can return “full, large, medium, etc” in the code.

// To change category slider image size
if( ! function_exists('single_product_archive_thumbnail_size_modified')) {
    function single_product_archive_thumbnail_size_modified () {
        return 'full'; // large or medium or thumbnail
    }
}
add_filter( 'single_product_archive_thumbnail_size', 'single_product_archive_thumbnail_size_modified' );

5) How to add Custom Fonts in the Typography

If you want to add any custom font to the plugin. You can do this easily with the custom code below. But your custom font must be enqueued/loaded in your theme or site. Then you just need to write the font name in the function below. If you check the code you will see there is a filter hook available (spwps_field_typography_customwebfonts) in the plugin by which you can easily add custom fonts.

if( ! function_exists('spwps_field_typography_customwebfonts_modified')) {
    function spwps_field_typography_customwebfonts_modified() {
        // your custom fonts 
        $custom_fonts = array(
            'VTF Redzone Classic',
            'SP Jupiter',
        );
        return $custom_fonts;
    }
}
add_filter( 'spwps_field_typography_customwebfonts', 'spwps_field_typography_customwebfonts_modified' );

6) How to remove any Safe Web Fonts from the plugin

Suppose you don’t want to use any specific Safe Web Fonts of the plugin, and you don’t want to display them in the Typography section. Then you can do this easily with the following custom code. If you check the code you will see there is a filter hook available (spwps_field_typography_safewebfonts) in the plugin by which you can easily remove the specific font. You just need to put the array key number of the font in the function.

function typography_safewebfonts_remove($webfonts){
    unset($webfonts['0']); // To remove the Arial font
    return $webfonts;
}
add_filter( 'spwps_field_typography_safewebfonts', 'typography_safewebfonts_remove' );

7) How to show current category-wise products

If you want to display current category-wise products in your slider (the shortcode may be in the widget area) on the category archive page then you can easily do it with the following custom code. If you check the code you will see there is a filter hook (sp_wpspro_arg) available in the plugin which allows you to modify the plugin’s functionality. You can return “full, large, medium, etc” in the code.

if( ! function_exists('wpspro_current_category_wise_products') ) {
    function wpspro_current_category_wise_products($arg, $shortcode_id) {
        // write your shortcode ID number here
        if('267' == $shortcode_id ) {
            $wpspro_current_category_obj = get_queried_object();
            if ( isset( $wpspro_current_category_obj->term_id ) ) {
                $arg['tax_query'][] = array(
                    'taxonomy' => 'product_cat',
                    'field'    => 'term_id',
                    'terms'    => $wpspro_current_category_obj->term_id,
                    'operator' => 'IN',
                );
            }
        } 
        return $arg;
    }
}
add_filter( 'sp_wpspro_arg', 'wpspro_current_category_wise_products', 10, 2 );

8) How to add Custom Google Fonts in the Typography

If you want to add any custom font to the plugin. You can do this easily with the custom code below. But your custom font must be enqueued/loaded in your theme or site. Then you just need to write the font name in the function below. If you check the code you will see there is a filter hook available (spwps_field_typography_googlewebfonts) in the plugin by which you can easily add custom fonts.

// To add custom Google fonts
function typography_googlewebfonts_modified(){
    $webfonts = array(
        'VTF Redzone Classic',
        'SP Jupiter',
    );
    return $webfonts;
}
add_filter( 'spwps_field_typography_googlewebfonts', 'typography_googlewebfonts_modified' );