Can't remove WooCommerce's image zoom - php

I am trying to remove the image zoom from my custom themed website which uses WooCommerce. Here is what I've tried adding in my functions.php file:
add_action( 'after_setup_theme', 'remove_pgz_theme_support', 100 );
function remove_pgz_theme_support() {
remove_theme_support( 'wc-product-gallery-zoom' );
}
and this
add_action( 'wp', 'remove_pgz_theme_support', 20 );
function remove_pgz_theme_support() {
remove_theme_support( 'wc-product-gallery-zoom' );
}
I've spend some time googling but the answers always recommend trying something along the lines of the above.

I disable all image effects with:
add_action('wp', 'remove_woo_image_effects');
function remove_woo_image_effects() {
// this should be disable the gallery slider and lightbox
remove_theme_support('wc-product-gallery-lightbox');
remove_theme_support('wc-product-gallery-slider');
// this should be disable the zoom
remove_theme_support('wc-product-gallery-zoom');
}
I tested it with DIVI and two from my custom themes
checked it here with custom theme

The solution that worked for me is adding the following to your functions.php file
// Add WooCommerce support
function add_woocommerce_support() {
add_theme_support( 'woocommerce' );
}
add_action( 'after_setup_theme', 'add_woocommerce_support' );

Related

Wordpress how to load additional stylesheets (charts.css)

I'd like to enqueue a stylesheet called charts.css & charts.min.css.
I'm not sure, why it's not working.
That's my added code in functions.php Wordpress:
function additional_stylesheets() {
wp_register_style( 'custom01', get_template_directory_uri().'/assets/css/minified/charts.min.css' );
wp_enqueue_style( 'custom01' );
wp_register_style( 'custom02', get_template_directory_uri().'/assets/css/unminified/charts.css' );
wp_enqueue_style( 'custom02' );
}
add_action( 'wp_enqueue_scripts', 'additional_stylesheets' );
I tried in elementor to style a table but nothin' happened.
So I also tried to use:
<link rel="stylesheet" href="wp-content/themes/astra/assets/css/minified/charts.min.css">
but that's also not working.
Did I make a mistake somewhere?
I use the theme astra in WordPress.
The path is wp-content/themes/astra/.
After appending styleheets in WordPress I do not have to call them in html code anymore am I right?
You don't need to register them. Instead use the following code:
function additional_stylesheets() {
wp_enqueue_style('charts_min_styles', get_theme_file_uri('/assets/css/minified/charts.min.css'), NULL, 1.2, false);
wp_enqueue_style('charts_styles', get_theme_file_uri('/assets/css/unminified/charts.css'), NULL, 1.2, false);
}
add_action( 'wp_enqueue_scripts', 'additional_stylesheets' );
The code goes to the functions.php of your active theme or child them.

How to only deregister Wordpress stylesheet for non-logged in users?

I use the following code in my functions.php to disable the dashicons.min.css file from the frontend. It works fine, but how can I use that action only for visitors, who are not currently signed in to WordPress?
The reason is that the WordPress admin bar at the top is broken, if the dashicons css file is not available.
add_action( 'wp_print_styles', 'my_deregister_styles', 100 );
function my_deregister_styles() {
wp_deregister_style( 'dashicons' );
}
You want to use the function is_user_logged_in() which comes with WordPress. Read about it at https://developer.wordpress.org/reference/functions/is_user_logged_in/.
So your code would be:
add_action( 'wp_print_styles', 'my_deregister_styles', 100 );
function my_deregister_styles() {
if( !is_user_logged_in() )
wp_deregister_style( 'dashicons');
}

Remove Woocommerce action from external plugin

I'm switching to a new Wordpress plugin I've written myself that will run along side an old plugin on top of the Woocommerce cart. While I'm running the two plugins I want to remove the old plugin's action that calls it's table to display in the users my account page. I will be adding logic after to work out if it's needed, but for now I just need to remove it.
This is how the action is being called in the old plugin.
class WC_Subscriptions {
public static function init() {
// Display Subscriptions on a User's account page
add_action( 'woocommerce_before_my_account', __CLASS__ . '::get_my_subscriptions_template' );
}
}
WC_Subscriptions::init();
So far in my own plugin I have called the following and none of them work.
remove_action( 'woocommerce_before_my_account', array('WC_Subscriptions', 'get_my_subscriptions_template' ) );
// no error but still shows the table
and the last one
remove_action( 'woocommerce_before_my_account', array( WC_Subscriptions::init(), 'get_my_subscriptions_template' ) );
// Fatal error: Class 'WC_Subscriptions' not found in /var/sites/XXXXX on line 45
I have tried changing/adding the $priority from 1, 9, 10, 11 and 99 and that doesn't work either.
It's frustrating as I'm sure it would work if the old plugin was initiated with a new instance so I could do this
global $my_class;
remove_action( 'woocommerce_before_my_account', array( $my_class, 'get_my_subscriptions_template' ) );
Can anyone help?
This always happens, just worked it out.
I needed to hook the remove_action into another action that is called much later.
In the end I did this
class My_new_plugin {
public function __construct() {
add_action( 'wp_head', array($this, 'remove_action_woosubscription_table' ) );
}
public function remove_action_woosubscription_table() {
remove_action( 'woocommerce_before_my_account', array( 'WC_Subscriptions', 'get_my_subscriptions_template' ) );
}
}
You can set third attribute 'priority' as 999
<?php remove_action( $tag, $function_to_remove, $priority ); ?>

Enqueing a jQuery script in Wordpress

I am trying to enqueue a jQuery script to my Wordpress site but for some reason it is not adding. Below is my code I've added to my child theme's functions.php file.
<?php
function itm_adding_scripts() {
wp_register_script('my_amazing_script', '/wp-content/themes/italic-child/js/jQuery.equalHeights.js/js/jQuery.equalHeights.js', array('jquery'),'1.1', true);
wp_enqueue_script('my_amazing_script');
}
add_action( '_enqueue_scripts', 'itm_adding_scripts' );
?>
You have a typo in the action missing wp prefix
Change
add_action( '_enqueue_scripts', 'itm_adding_scripts' );
To
add_action( 'wp_enqueue_scripts', 'itm_adding_scripts' );
Reference: wp_enqueue_scripts docs
You have a typo in your action. It should be wp_enqueue_scripts
add_action( 'wp_enqueue_scripts', 'itm_adding_scripts' );

WordPress remove_filter() to remove theme JS hook via plugin

I have a theme that is adding a custom, full-screen background image via jQuery. The theme is doing this via a class object called td_background. Within the class is a function called wp_head_hook(), and within this hook, a filter is being added for the custom bg. It looks something like this:
class td_background {
// ..some stuff
function __construct() {
add_action('wp_head', array($this, 'wp_head_hook'), 10);
}
function wp_head_hook() {
add_filter( 'td_js_buffer_footer_render', array($this, 'add_js_hook'));
}
function add_js_hook($js) {
// Custom JS added here for background image
return $js
}
}
new td_background();
I'm now trying to de-register the add_js_hook in a custom plugin I'm writing, but am having trouble wrapping my mind around how to do it with all this nesting. I've tried a few things, such as:
<?php
// This...
remove_filter( 'wp_footer', array($td_background, 'td_js_buffer_footer_render'));
// ...and this
remove_filter( 'wp_footer', 'td_js_buffer_footer_render');
// ...and even
remove_filter( 'wp_footer', 'add_js_hook', 100);
?>
I've also tried changing the above to wp_head.
Thoughts? My end goal is to de-register this JavaScript in the footer, so that I can add my own in place of it.
As it's being instantiated anonymously, we have to use the handy function remove_anonymous_object_filter() from WPSE, it would be something like:
// Run this from a plugin
add_action( 'template_redirect', 'kill_anonymous_example', 0 );
function kill_anonymous_example() {
remove_anonymous_object_filter(
'wp_head',
'td_background',
'wp_head_hook'
);
}
I tested killing wp_head as I don't have a td_js_buffer_footer_render running.

Categories