asked on
function conditional_hover_effect($newdata) {
echo '<script>console.log("Function is firing")</script>';
return $newdata ;
}
add_filter( 'jet-woo-builder/template-functions/product-thumbnail', 'conditional_hover_effect', 10, 2 );
public function get_product_thumbnail( $image_size = 'thumbnail_size', $use_thumb_effect = false, $attr = array() ) {
global $product;
if ( ! is_a( $product, 'WC_Product' ) ) {
return;
}
$thumbnail_id = get_post_thumbnail_id( $product->get_id() );
$enable_thumb_effect = filter_var( jet_woo_builder_settings()->get( 'enable_product_thumb_effect' ), FILTER_VALIDATE_BOOLEAN );
$placeholder_src = apply_filters( 'jet-woo-builder/template-functions/product-thumbnail-placeholder', Elementor\Utils::get_placeholder_image_src() );
$attr = array( 'data-no-lazy' => '1' );
if ( empty( $thumbnail_id ) ) {
return sprintf( '<img src="%s" alt="EMPTY">', $placeholder_src );
}
$html = wp_get_attachment_image( $thumbnail_id, $image_size, false, $attr );
if ( $use_thumb_effect && $enable_thumb_effect ) {
$html = $this->add_thumb_effect( $html, $product, $image_size, $attr );
}
return apply_filters( 'jet-woo-builder/template-functions/product-thumbnail', $html );
}
ASKER
$placeholder_src = apply_filters( 'jet-woo-builder/template-functions/product-thumbnail-placeholder', Elementor\Utils::get_placeholder_image_src() );
return apply_filters( 'jet-woo-builder/template-functions/product-thumbnail', $html );
function conditional_hover_effect($newdata) {
$newdata = $newdata . "<script>console.log('Function is firing')</script>";
return '<div class="this_is_the_wrapper_of_newdata">' .$newdata . '</div>';
}
add_filter( 'jet-woo-builder/template-functions/product-thumbnail', 'conditional_hover_effect');
public function get_product_thumbnail( $image_size = 'thumbnail_size', $use_thumb_effect = false, $attr = '' ) {
Somewhere in your theme templates, this function will be called, and it will be passing true in as the second argument. You'd want to change that to pass in false. Doing this means the additional HTML for enabling the thumb effect won't be added, because it's conditional based on this bit of code (lines 74-76):if ( $use_thumb_effect && $enable_thumb_effect ) {
$html = $this->add_thumb_effect( $html, $product, $image_size, $attr );
}
Have a search through your theme's (or the parent theme's) template files for get_product_thumbnail. When you find it, that's probably the best place to turn it on and off.
ASKER
$thumbnail = jet_woo_builder_template_functions()->get_product_thumbnail( $size, true );
if ( is_archive() || is_category() || is_tax() || is_product_category() || has_term( 'lips' ) ) {
$thumbnail = jet_woo_builder_template_functions()->get_product_thumbnail( $size, false );
echo "<script>console.log('Shop page');</script>";
}else{
echo "<script>console.log('Not shop page');</script>";
$thumbnail = jet_woo_builder_template_functions()->get_product_thumbnail( $size, true );
}
ASKER
PHP is a widely-used server-side scripting language especially suited for web development, powering tens of millions of sites from Facebook to personal WordPress blogs. PHP is often paired with the MySQL relational database, but includes support for most other mainstream databases. By utilizing different Server APIs, PHP can work on many different web servers as a server-side scripting language.
TRUSTED BY
In your filter, you're not actually doing anything with $newdata - you're just taking it in as an argument, and then returning it ... unchanged. The idea of a filter is that it changes the data before returning it:
Open in new window
Now the $newdata is passed in, we add some additional text to it, and then we return it.