I am trying to remove the ability to click on an image in woocommerce's product featured images, so that you can no longer click on the image and make it bigger.
Not much skills with css so simple explanations are appreciated.
I have the product-image.php open and I know how to enter custom code into my theme.
Anyone?
Change this line inthe product-image.php
echo apply_filters( 'woocommerce_single_product_image_html', sprintf( '%s', $image_link, $image_title, $image ), $post->ID );
to
echo apply_filters( 'woocommerce_single_product_image_html', sprintf( '%s', $image ), $post->ID );
and in the product-thumbnails.php file, change
echo apply_filters( 'woocommerce_single_product_image_thumbnail_html', sprintf( '%s', $image_link, $image_class, $image_title, $image ), $attachment_id, $post->ID, $image_class );
to
echo apply_filters( 'woocommerce_single_product_image_thumbnail_html', sprintf( '<a title="%s">%s</a>', $image_title, $image ), $attachment_id, $post->ID, $image_class );
Doing the above should remove the ability to click on the image and make it bigger.
works perfectly however I'm facing one issue because of it. I set up my page so that when I click a thumbnail it replaces the product image. When I apply your rule to make the product image unclickable, then the other js doesnt work anymore. Do you have any idea how I could make both work together? The jquery Im using is
(function($){
$(document).ready(function(){
$('.thumbnails a.zoom').click(function(event){
event.preventDefault();
var thumb_url = $(this).find('img').attr('src');
$('.woocommerce-main-image img').attr('src', thumb_url );
});
});
})(jQuery);
Try this
.woocommerce-product-gallery__image {
pointer-events: none;
It works perfectly for me.
Check if your theme has a custom CSS section and just paste it there.
First of all, if you want to replace single-product.php template you have to create a new one in you own theme folder.
Example: wp-content/themes/woocommerce/single-product.php
<?php
global $product;
echo $product->get_image();
?>
Will output only img tag without link and any div's.
This might be helpful https://docs.woocommerce.com/wc-apidocs/source-class-WC_Block_Featured_Product.html#156-175
I was looking for how to disable the zoom and lightbox on product images and the following code (inserted on functions.php) helped:
add_action( 'after_setup_theme', 'remove_pgz_theme_support', 100 );
function remove_pgz_theme_support() {
remove_theme_support( 'wc-product-gallery-zoom' );
remove_theme_support( 'wc-product-gallery-lightbox' );
}
This had, however, the side effect of still allowing users to click on the image, sending them to the direct link of the file. On the OceanWP theme I found this to work (insert it on your css):
img.wp-post-image {
pointer-events:none !important;
This will work for the featured image, but if you have other images in the same product gallery, those ones will still be clickable. To disable the click on those too, insert this extra code on your css:
div.woocommerce-product-gallery__image.flex-active-slide {
pointer-events:none !important;
Hope it helps you!
Related
Need some help with images.
As the topic says, I want to create an image with live updating text on it.
This is mainly used by game servers and players to show off their stats and info. Server-wise, to show if the server is online and how many players are online and such.
I haven no idea how to do it and figured this would be the best place to find out. Since I don't have any idea what this is even called, i did not know what to search for.
Thanx in advance.
This is an html+css+ajax solution. Make the image an html element's background image. Let's use a div. Then position the text in the div. Use ajax to update the text. The image will remain the same while the text can be updated.
Was possible with the use of API. Created an API of the database I want to use, connected to the database and everything worked!
After using $API_GET to get the data, I set it into an array-format.
Used PHP for everything.
From there on I used imagecreatefrompng, obviously to select an image.
Set a few colors using imagecolorallocate and from there on it was purely adding the text on the image as to where I want them using imagettftext.
Creating an image, with live updating stats on it.
But we still have to tell the browser to load it as an image and not a page with an image on it, so therefor...
header( "Content-type: image/png" );
And imagesetthickness to 5, followed by imagepng and imagedestroy.
Code Extracts:
$API_GET = file_get_contents("API URL");
$API_GET = json_decode($API_GET);
$API = array();
foreach ($API_GET as $key => $value) {
$API[$key] = $value;
}
if (file_exists($imagefile)) {
$bg_img = imagecreatefrompng ( "IMAGE URL");
$color_red = imagecolorallocate( $bg_img, 250, 0, 0 );
imagettftext($bg_img, 20, 0, 19, 36, $color_red, 'FONT URL.tff',"Text On Image");
imagesetthickness ( $my_img, 5 );
header( "Content-type: image/png" );
imagepng( $my_img );
imagedestroy( $my_img );
} else {
echo 'Image does not exist.';
}
That is the basic structure of the code.
Thank You for your reply to the question.
This is code from the Dizi-images module (plugin/content/images/images.php) for Joomla. This works, it publishes a image or image gallery at the end of a specific article.
But if I want to publish the image/image gallery to another position (by changing its position in Joomla admin and the getModules-value in the code below) it looses its "connection" to the article. It shows up on every article on the site.
Is it possible to make this code below to be able to publish the image/image gallery to another position without loosing its connection to the specific article?
/*
* load front end images module
*/
public function onContentAfterDisplay( $context, &$row, &$params, $limitstart = null )
{
$jinput = JFactory::getApplication()->input;
$option = $jinput->get('option', '', '');
$view = $jinput->get('view', '', '');
if( $context == 'com_content.article' && ( $modules = JModuleHelper::getModules( 'images' ) ) )
{
return JModuleHelper::renderModule( $modules[ 0 ] );
}
return '';
}
Thanks
Magnus
Screenshot of the modules that I change position on (Joomla Admin/Extensions/Module Manager/)
The plug-in I use is "Dizi images gallery"-extension.
This shows the Dizi-images Tab. Where you add images/image gallery to the article your in.
These three lines of code will allow you load and render any existing modules as needed.
jimport( 'joomla.application.module.helper' );
$module = JModuleHelper::getModule('mod_myimagemodulename', 'Images Gallery');
echo JModuleHelper::renderModule($module, array('style' => 'xhtml'));
If you want to manage from the back end, you will need to make a duplicate of the existing module with different menu position assignments. It sounds like the only limitation is the source images folder, so the module should not mind!
** EDIT **
To create a new position like "right", you would need to add a new jdoc element to your templates index.php where you would like the new position:
<jdoc:include type="moduels" name="right" style="xhtml" />
Then in your templates manifest XML file, add the new position to list of existing positions:
<position>right</position>
Now if you navigate to the module copy you want to place there, you would be able to select the newly created "right" position.
** EDIT **
Noticed something in how the module instance is being loaded, the name should reflect the the module type and name.
$modules = JModuleHelper::getModules( 'images', 'Images gallery' )
And definitely migrate away from JRequest.
Why not just create a new instance of the module for the other position? That way this module stays just as it is and the new module is published elsewhere without conflicting with the code you have.
Also agree with Lodder, use JInput.
I'm beginning to work on Bootstrap in Yii framework and finding some difficulties in making it work the way I want to.
And have not found anything useful in the docs, although I might have missed something.
I have the navbar like this:
<?php $this->widget('bootstrap.widgets.TbNavbar', array(
'collapse'=>true, // requires bootstrap-responsive.css
'fixed'=>'none',
'brand'=>false,
'items'=>array(
array(
'class'=>'bootstrap.widgets.TbMenu',
'items'=>array(
array('label'=>'Home', 'url'=>'#', 'active'=>true),
array('label'=>'Link', 'url'=>'#'),
array('label'=>'Dropdown', 'url'=>'#', 'items'=>array(
array('label'=>'Action', 'url'=>'#'),
array('label'=>'Another action', 'url'=>'#'),
array('label'=>'Something else here', 'url'=>'#'),
'---',
array('label'=>'NAV HEADER'),
array('label'=>'Separated link', 'url'=>'#'),
array('label'=>'One more separated link', 'url'=>'#'),
)),
),
),
),
));
?>
By default submenu drop out by Click event, but I want to submenu drop out at mouseover event. How do it, please help. Thanks in advance.
Im using bootstrap with Yii for a while and submenus popups automatically. Check also this link http://www.bootply.com/60842 which shows that bootstrap submenus popups automatically on mouseover.
You will be probably overriding/missing some css/javascript files. Also check console if your page has no errors after loading.
Find bootstrap.js in the asset folder of the bootstrap extension folder.
Replace the following (rows 797- 800) :
.on('click.dropdown.data-api', clearMenus)
.on('mouseover.dropdown.data-api', '.dropdown form', function (e) { e.stopPropagation() })
.on('mouseover.dropdown.data-api' , toggle, Dropdown.prototype.toggle)
.on('keydown.dropdown.data-api', toggle + ', [role=menu]' , Dropdown.prototype.keydown)
to becomes
.on('click.dropdown.data-api', clearMenus)
.on('mouseover.dropdown.data-api', '.dropdown form', function (e) { e.stopPropagation() })
.on('mouseover.dropdown.data-api' , toggle, Dropdown.prototype.toggle)
.on('keydown.dropdown.data-api', toggle + ', [role=menu]' , Dropdown.prototype.keydown)
In order to work, you have to clean the asset folder in the main directory to generate once from the asset you've just changed.
i know its sounds a bit crazy, but so many clients have problems with not saving their article properly.
I just wanted to use a simple method to trigger the onclick of the APPLY button inside a joomla article in edit mode.
Primarily back end editing as i have a good admin template that allows me to show clients the bare bones.
I know that by clicking apply the page reloads but thats better than nothing.
How on earth do i add do this?
I was hoping something like this would work but i dont quite know how to trigger a button that seems to reside inside a toolbar function of some sort.
I have this:
<script type="text/javascript">
$(document).ready(function() {
$('??????').trigger('click');
});
</script>
What would replace the question marks?
Also i know i would need to put a timer into the jquery code but how do i get the link below to trigger?
http://mydomain.com/administrator/index.php?option=com_content§ionid=1&task=edit&cid[]=97
In the toolbar.content.html.php file joomla has this:
class TOOLBAR_content
{
function _EDIT($edit)
{
$cid = JRequest::getVar( 'cid', array(0), '', 'array' );
$cid = intval($cid[0]);
$text = ( $edit ? JText::_( 'Edit' ) : JText::_( 'New' ) );
JToolBarHelper::title( JText::_( 'Article' ).': <small><small>[ '. $text.' ]</small></small>', 'addedit.png' );
JToolBarHelper::preview( 'index.php?option=com_content&id='.$cid.'&tmpl=component', true );
JToolBarHelper::save();
/////////////////////////////////////
JToolBarHelper::apply(); // < // THIS IS WHAT I WANT TO TRIGGER
/////////////////////////////////////
if ( $edit ) {
// for existing articles the button is renamed `close`
JToolBarHelper::cancel( 'cancel', 'Close' );
} else {
JToolBarHelper::cancel();
}
}
...... more stuff here
}
I know this might sound crazy but wouldnt it be great if autosave could happen even without a reload, but i guess that would mean posting all the data using jquery rather than the php post and reload page method.
Anyways im not expecting a miracle here but if anyone could help that would be great.
Cheers in advance
John
PS:
i just tried something like this hoping maybe it will work but it just reloads the page:
function autosave()
{
window.location = "index.php?option=com_content§ionid=<?php echo $_GET['sectionid'];?>&task=edit&cid[]=<?php echo $row->id;?>"
}
You won't be able to do it without forcing a reload unless you decide to re-write the whole of com_content with an ajax implementation.
Looking at the code you've posted I guessing Joomla! 1.5 - which by default has MooTools 1.12 or 1.2.5 (if you enabled the MooTools upgrade plugin in later versions of 1.5.x) - so more of a question but why not use that?
You will have to modify the admin template to embed the JS you need, 1.5 has few triggers and none that are really worth using in the admin screens (unless you're up for a fair bit of PHP coding)
Somewhere in the <head> tag of com_content's Article view you will need to add this:
<script type="text/javascript">
var interval = 30 //seconds
var timer = setTimeout(submitbutton('apply'),(interval * 1000));
}
</script>
Please note I haven't tried this just typed it straight into here.
Since you're on 1.5 have you tried the Simple Content Versioning extension - it has autosave functionality that appears to be what you want - and probably works whereas who knows with my code in #3.
i am trying to display product gallery images in my custom cms home page. If i use the code from media.phtml to display the gallery images, it does not work. I found this piece of code and it worked.
<div id="thumbs" class = "thumbs-home">
<?php
$obj = new Mage_Catalog_Block_Product_View_Media();
$_product1 = new Mage_Catalog_Model_Product();
// Load all product information of a particular product
$Products_one = Mage::getModel('catalog/product')->load($productId);
// Use your Product Id instead of $id
$countt = count($Products_one->getMediaGalleryImages());
if($countt>0){
foreach ($Products_one->getMediaGalleryImages() as $_image)
{
// For the Original Image
$thumb_img = "<img src=".Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_MEDIA).str_replace(Mage::getBaseUrl('media'),"",$_image->url)." alt=''width='60' height='60' />";
echo "<a href='".Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_MEDIA).str_replace(Mage::getBaseUrl('media'),"",$_image->url)."'rel='lightbox[gallery]'>".$thumb_img."</a>";
//For gallery Image
//$resizeimage = $obj->helper('catalog/image')->init($_product, 'thumbnail', $_image->getFile())->backgroundColor(242,242,243)->resize(400,300);
//echo "<img src=".$resizeimage."alt='' />";
}
}
?>
This gets the actual images and gets resized by the width and height attributes. But i want to resize the image through magento. The last piece of code $resizeimage is not working for some reason. How can i make this work? The problem is that i am using a lightbox to display the gallery images which displays the actual high resolution images that are too large. The light box takes in width and height of image provided and i am not able to figure out as to how i set a standard dimensions for the light box. So the only other option is the have the images resized by magento before passing them to the lightbox. Thanks.
You just need to call proper object, instead of $obj->helper you should use Mage::helper, so your call should look like this:
print Mage::helper('catalog/image')
->init($product, 'thumbnail', $image->getFile())
->backgroundColor(255,255,255)
->resize(100,100);
And that's it! :)