Place text underneath product images WooCommerce - wordpress

I am attempting to add text beneath the product gallery images of my Wordpress Woo-commerce site.
I have attempted to use the general scripts found online:
add_action( 'woocommerce_after_single_product_summary' , 'bbloomer_add_below_prod_gallery', 5 );
function bbloomer_add_below_prod_gallery() {
echo '<div class="woocommerce-product-gallery" style="background: #fdfd5a; padding: 1em 2em">';
echo '<span>THIS IS A TEST. YOU CAN ADD TEXT, IMAGES AND ANY HTML</span>';
echo '</div>';
}
You can see in the following screenshot that the text appears here and not beneath the actual image
The website link this is referencing can be found at: https://www.tattiniboots.com/product/retriever/
Update:
After trying the proposed solution below, the div text shows all the way at the bottom:
I am attempting to get this div to appear here:
The link I am working at is found here: https://www.tattiniboots.com/product/terranova/

You need to add style clear:both in your div. check the below code.
add_action( 'woocommerce_after_single_product_summary' , 'bbloomer_add_below_prod_gallery', 5 );
function bbloomer_add_below_prod_gallery() {
echo '<div class="woocommerce-product-gallery" style="background: #fdfd5a; padding: 1em 2em; clear:both;">';
echo '<span>THIS IS A TEST. YOU CAN ADD TEXT, IMAGES AND ANY HTML</span>';
echo '</div>';
}

Related

Add text upper left corner Wordpress Storefront

This started out as a Question, but I sort of made it work. I am sharing it for anyone who needs to know. Or maybe there is a better way?
I'd like to show a welcome message on the home page. Should be placed in the upper left corner.
This is what I did:
add_action( 'storefront_header', 'pfn_userinheader',1);
function pfn_userinheader() {
?>
<span class="pfn_great_header2"> Hello! blablabla</span>
<?php
}
Now the text is placed where the secondary menu. More like top, right of middle. I have no idea why just there. Anyway, I would like it to be placed in the top left corner.
This is my css:
.pfn_great_header2{
position: absolute !important;
left: 0;
top:0;
width: 10% !important;
color: #0071A1;
}
It works. Is it a good way of doing this?
I have something similar on my site but it displays a different message if the customer is already logged in.
If you wanted to do this, you could use something like this:
add_action( 'storefront_header', 'pfn_userinheader',1);
function pfn_userinheader() {
if ( is_user_logged_in() ) {
echo '<span class="pfn_great_header2">Welcome back <?php $current_user = wp_get_current_user(); echo $current_user->user_firstname; ?>!</span>';
}
elseif {
echo '<span class="pfn_great_header2"> Hello! blablabla</span>';
}
}

Advanced Custom Fields (ACF) css

I have been trying to find out how to add PHP from ACF to style some text in CSS. Using: https://www.advancedcustomfields.com/resources/color-picker/
.special-color {
background-color: <?php the_field('color'); ?>;
}
To echo php into workable CSS, you'll have to include the CSS in the php sections of the site (or something more advanced, probably using functions.php). This will work if you simply add:
<style>
.special-color {
background-color: <?php the_field('color'); ?>;
}
</style>
..to (say) your single.php file within the loop.
As an aside, I don't think this would be a viable way to alter site colours (if that's what you are trying to do?), but more as a way of (say) specifying a particular color for a title of one post.
Then you might think of including the style INLINE (pseudo code):
<h1 style="color: <?php the_field('color'); ?>">Post title</h1>
Simply I get the "advanced custom field" value (which is custom_color for an element) of the current post, and then change the element's color using JQuery.
So I created a new js file (custom_css.js) in the child theme with the following code:
jQuery(document).ready(function($) {
console.log(css.custom_color);
// add dynamic css to the elements
});
Then here is the code in functions.php file:
add_action('wp_enqueue_scripts', 'custom_css');
/* Get position details */
function custom_css() {
wp_enqueue_script('custom_css', get_stylesheet_directory_uri() . '/js/custom_css.js', array('jquery'));
wp_localize_script('custom_css', 'css', array(
'admin_url' => admin_url(),
'custom_color' => get_field('custom_color', get_queried_object_id() )
));
}

Adding space to `echo`ed result

Here I have code in which php echoes out the number of followers, the result is displayed under Followers wrapped in h2 tags but in the start of line i.e, under Fo, I just want to display numbers in somewhat center under followers adding several &nbsp to echo mysqli_num_rows($resultfollowers); does the work but is their any one word alternative for that rather than typing several &nbsp
<h2>Followers</h2>
<?php
$checkfollowers = "SELECT * FROM follow_user WHERE user_id='$user_id'";
$resultfollowers = mysqli_query($con,$checkfollowers);
echo mysqli_num_rows($resultfollowers);
?>
Yes. Use CSS to set a width for the container and use text-align: center; to center the text.
Visual presentation has nothing to do with MySQL or PHP.
Example with inline styles:
echo sprintf( '<p style="width: 20em; text-align:center;">%s</p>', $resultfollowers );

Trying to hide image styling, if no image is present - Advanced Custom Fields images

I have styled my images on my Content Page Template to have borders, backgrounds and box-shadow. If I don't use the optional image field and leave it empty, it leaves the css styling with a small box. I have been trying to hide the entire .content-img class if there is no image present. The code below works fine for rendering the images if they are present. How to hide it if no image is present.
<?php the_field('top_headline'); ?></h1>
<div class="content-top"><?php the_field('content_top'); ?></div>
<div class="content-img"><?php
$image = get_field('content_image');
$size = 'medium'; // (thumbnail, medium, large, full or custom size)
if( $image ) {
echo wp_get_attachment_image( $image, $size );
} ?>
Thanks for your help in advance.
So I took care of it using CSS instead of in the array. instead of using the css class .content-img (which is my parent div), I added the image to the class .content-img img and if no image is present, the css wont show.

css positioning issue - happening on some pages but not others

I've noticed that on some product pages of my site (but not all) I'm getting a strange issue where one of the product images appears in the row below the one it's meant to.
So on some pages the 'People who bought this also purchased...' images, on the last line one of the products drops down a line and is obviously out of place.
http://tinyurl.com/cs6d3q5
but most other pages are fine!
http://tinyurl.com/clwq3dz
I can't figure out whats the problem. As far as I can see they should both act the same way. Can anyone enlighten me and also tell me how they debugged it? I use Firebug and developer tools on FF but they don't seem as useful as they once did
thanks
here's the code used to create it:
if($also_purchased_products->RecordCount() > 0) {
echo '<div style="clear:both"></div>';
echo '<div class="sideboxHeading">People who bought this also purchased...</div> <div class="ProdInfoDotSpacer"></div>';
while (!$also_purchased_products->EOF) {
$also_purchased_products->fields['products_name'] = zen_get_products_name($also_purchased_products->fields['products_id']);
echo '<div class="alsoPurchasedWrapper">';
echo '' . zen_image(DIR_WS_IMAGES . $also_purchased_products->fields['products_image'], $also_purchased_products->fields['products_name'], SMALL_IMAGE_WIDTH, SMALL_IMAGE_HEIGHT) . '<br />';
echo '' . $also_purchased_products->fields['products_name'] . '';
echo '</div>';
$also_purchased_products->MoveNext();
}
}
its because
Black/Sage Guinness harp knit
here Black/Sage Guinness harp knit scarf is long try sorting it
The problem appears when the previous item text link is more than one line long. You can truncate it, as NullPointer says, or set a height on .alsoPurchasedWrapper:
.alsoPurchasedWrapper {
float: left;
width: 150px;
margin: 5px 0px 10px 20px;
height: 170px;
}

Resources