Move up product data woocommerce on mobile - wordpress

is there a way ON MOBILE to move the 3 dropdowns section to the above the product name and gallery image?
I am using the woocommerce plugin and for the dropdowns im using the PRODUCT DATA - VAriable product section.
check the link:
Website

I would need more about your actual code (or a demo version) to achieve what you exactly want. You could use a bit of jQuery in your function.php, the following code as not been tested but the logic is there:
/*Move the variation div to another created one
======================================================================= */
add_action( 'wp_footer', 'move_variations_product_tab' );
function move_variations_product_tab() {
if (is_product()) :
$product = wc_get_product( get_the_ID() );
if($product->is_type( 'composite' )){
?>
<script>
jQuery(document).ready(function($) {
$(window).load(function() {
$( ".variations_form" ).wrap( "<div id='variations-content'></div>" );
$( ".woocommerce-product-gallery" ).before( "<div class='container product-before-gallery'></div>" );
document.getElementsByClassName("product-before-gallery")[0].appendChild(
document.getElementById("variations-content")
);
});
});
</script>
<?php
}
endif;
}
Replace "product-short" by the container of your description.
Wrapping around the div you want to move.
Creating a new class before the desired location
Move the wrapped div (#variations-content) under the newly created one
(.product-before-gallery).
Hope that helps! Let me know how it goes and give more info if you needs help.
Cheers

Related

placing a php code under the price in woocommerce

I have an php code which I want to put in my product page.
but I want to place this PHP below the price. when I add this snippet to my "single-product-style3.php" file which represent my layout for product page, the code adds below my add to cart button but I want it to be under the price.
I have another code which I use for my "view cart" page.
Just to clarify everything here is two screenshot, I want the paybright text to be in the red spot.
https://imgur.com/wbXBlF0
https://imgur.com/li4Duzd
Can someone help me please?
this is my website address: https://mayagallery.ca/
I wanted to know where should I upload and add this snippet:
<?php
function pb_modal() {
$pb_product_price = get_post_meta( get_the_ID(), '_price', true);
$pb_product_format = number_format((float)$pb_product_price, 2, '.', '');
echo "<script id='pb_prequalify' type='text/javascript' src='https://app.paybright.com/dist/sdk.js?public_key=*******'></script>
<script>
pb_prequalify_init();
</script>
<div id='paybright-widget-container'></div>";}
add_action( 'woocommerce_after_add_to_cart_form', 'pb_modal', 1);
?>
You should try this:
add_filter( 'woocommerce_get_price_html', 'woo_add_text_after_price_single_product', 20, 1 );
function woo_add_text_after_price_single_product($price){
// Your custom text
$custom_text = '<span style="color: #ff0000;">My Custom Text Here...</span>';
return $price.'<br>'.$custom_text;
}
Reference URL: https://stackoverflow.com/a/68936308/16560548
If you want to show test on shop page also you should try such type - https://stackoverflow.com/a/69025097/16560548

How to display feautured image of a post when hovering on the posts link (WordPress)?

I want to make my website's first page so you have posts listed with only titles and meta (reader friendly, easy to load...).
When you found something interesting you'd put the cursor on the title (linking to the post) and that would display a featured image beside (either on a specific spot on the site or offset just enough to not cover any of the text or replacing the cursor).
It's been done before, here is an example:
I'm assuming I'd have to use this to get the feautured image:
get_the_post_thumbnail_url( int|WP_Post $post = null, string|array $size = 'post-thumbnail' ).
The problem is I that I only know HTML and CSS, some very basic JS and have no clue about PHP. I found a couple examples on the web but couldn't get any to work.
Can you tell me how to get the image from the post link and display it (dynamically so it can work for any post link on the site)?
Thank you.
You can add output of the_post_thumbnail inside a <div></div> tag which it is hidden, Then you can show it when mouse:hover has been happened.
Structure is something like this:
<div class="featured-image">
<?php the_title(); ?>
<php the_post_thumbnail( 'full' ); ?>
</div>
In css file you should set:
div.featured-image img{
display:none;
}
When mouse hover has been occurred you should display Featured Image,Code will be something like this:
div.featured-image a:hover + img{
display: inline-block;
}
Try using this the_post_thumbnail(); it should display the post's image.
Check those:
https://developer.wordpress.org/reference/functions/get_the_post_thumbnail/
https://codex.wordpress.org/Post_Thumbnails
https://smartwp.com/wordpress-get-featured-image/
That's the first link when I googled it, so I will post solution here.
So I've achieved this effect by using Ajax:
AJAX is an acronym standing for Asynchronous JavaScript and XML and this technology helps us to load data from the server without a browser page refresh.
Details: https://api.jquery.com/jquery.ajax/
Diagram is helpful in understanding: https://i.stack.imgur.com/Zqyrn.gif
I've created jQuery which is getting url from the hovered link and sends it through Ajax to a server, and if process is successful, it renders the data returned:
var hrefValue;
jQuery(document).ready(function($) {
$('#bio-box').find('a').mouseover(function() {
hrefValue = ($(this).attr('href'))
//console.log(hrefValue)
$.ajax({
url: frontendajax.ajaxurl,
type: 'POST',
data: {
'action': 'image',
'php_test': hrefValue
},
success: function(data){
$('#featured-image').html(data);
//console.log(data);
}
});
});
});
This function generates the data:
function fimg() {
if ( isset( $_POST['php_test'] ) ) {
$testing = sanitize_text_field( wp_unslash( $_POST['php_test'] ) );
$post_id = url_to_postid( $testing );
echo get_the_post_thumbnail( $post_id );
}
die();
}
add_action( 'wp_ajax_image', 'fimg' );
add_action( 'wp_ajax_nopriv_image', 'fimg' );
HTML:
<div id="featured-imageā€>
</div>
It is working, and solves the problem. I hope it will help someone. Make notice that whole thing still needs some sanitation.

How to clear form input on page load woocommerce checkout

I am offering customers a repurchase on the order confirmed page. If they click the link they are sended directly to the checkout page. However, the form is then prefilled with the previous data. I would like to clear it, because the idea is one product(ticket) per person.
So far i have the following (and in the page source i can see the script is loaded):
function print_script() {
if (isset($_GET['extrapersoon']) && is_page(21560)){
echo '<script>
window.addEventListener("load", function(){myFunction()};
function myFunction() {
document.getElementsByClassName("woocommerce-checkout").reset();
}
</script>';
}
}
add_action('wp_print_scripts', 'print_script');
I tried other triggers too, such as window.load but no result yet.
Anyone?
You should put the script in the footer using add_action( 'wp_footer', 'print_script' ); to make sure the form gets cleared after the data was loaded into it.
Wordpress has jQuery on default, so I'm using it to look for all the forms in the document and clear them. The function is automatically called on page load, therefore no need for a event listener.
<?php
function print_script() {
if (isset($_GET['extrapersoon']) && is_page(21560)) { ?>
<script type="text/javascript">
( function( $ ) {
$('form').each(function() { this.reset() });
}( jQuery ) );
</script>
<?php }
}
add_action( 'wp_footer', 'print_script' ); ?>

Change Wordpress logo click redirection

I would like to change the logo redirection when clicked. Right now when you click on the logo, the user is redirected to the homepage but I want it to redirect to another site. How do I do this?
I agree with Stu Mileham. Another way to implement what you are asking for would be to use JavaScript / jQuery.
Save the following code to a .js file (eg. pageRedirect.js, let's say placed in a js folder inside your theme's root folder):
(function($) {
$(document).ready(function() {
$('#pageLogo').on( "click", function(event) {
event.preventDefault();
window.location.assign("http://www.google.com/");
});
});
})(jQuery);
To make the previous code work, you would have to select somehow the page logo via jQuery.
On the previous code this is achived via $('#pageLogo') since I have made the assumption that your logo has an id with the value pageLogo.
Of course, to enable your theme to use this pageRedirect.js file, you have to enqueue it by placing the following code to your theme's functions.php file:
/**
* Enqueue pageRedirect script.
*/
function pageRedirect_scripts() {
wp_enqueue_script( 'page-redirect-js', get_template_directory_uri() . '/js/pageRedirect.js', array('jquery'), '20150528', true );
}
add_action( 'wp_enqueue_scripts', 'pageRedirect_scripts' );
Code Explanation:
//-jQuery selects html element with id='pageLogo'
//-when it is clicked, it calls a function in which it passes the event
$('#pageLogo').on( "click", function(event) {
//prevents page from redirecting to homepage
event.preventDefault();
//redirects to your desired webpage
window.location.assign("http://www.google.com/");
});
If you don't have the option to change the link from admin then you will have to edit your theme's header.php file (most likely, depends on how the theme is built though).
Many themes have a tag similar to the following:
<img src="logo.jpg">
You would need to change this to:
<img src="logo.jpg">
I've added the target tag to open the site in a new window, this is my personal preference when re-directing to a different site but it's optional.
Your theme files might look very different to this, it's impossible to know for sure without seeing some code, but this should give you an idea.
Also be aware that your changes could be overwritten by a theme update. This can be avoided by creating a child theme.
https://codex.wordpress.org/Child_Themes
Depends on your theme
Some theme creators gives you the possibility to change the link from admin
Some theme creators just believe that clicking the logo you need to go on homepage - so you need to edit the theme
Depending upon the theme you are using, you can try one of the following options.
Explore the admin options and see if the theme provides a direct way to change the link on the logo.
If not found in admin options, try looking for the code in header.php. Do an inspect element on your logo and see the html code surrounding the logo file, If the code is directly present in header.php, your task is simple. Just change the code to update the URL, instead of reading it from home_url(). Something like <a href="<?php echo home_url();?>"> will need to be replaced with <a href="https://www.example.com">
The other option to look for is get_custom_logo. Some themes get the logo code from this function. You can apply a filter to change the home_url just before this method is called in your theme and then remove filter afterwards. Or else you can copy the code from wordpress and update it with a differently named function say get_custom_link_logo in functions.php then where'ver your theme is using get_custom_logo you can use get_custom_link_logo instead of that.
function get_custom_link_logo ( $blog_id = 0 ) {
$html = "";
$switched_blog = false;
if ( is_multisite() && ! empty( $blog_id ) && (int) $blog_id !== get_current_blog_id() ) {
switch_to_blog( $blog_id );
$switched_blog = true;
}
$custom_logo_id = get_theme_mod( 'custom_logo' );
// We have a logo. Logo is go.
if ( $custom_logo_id ) {
$custom_logo_attr = array(
'class' => 'custom-logo',
'itemprop' => 'logo',
);
/*
* If the logo alt attribute is empty, get the site title and explicitly
* pass it to the attributes used by wp_get_attachment_image().
*/
$image_alt = get_post_meta( $custom_logo_id, '_wp_attachment_image_alt', true );
if ( empty( $image_alt ) ) {
$custom_logo_attr['alt'] = get_bloginfo( 'name', 'display' );
}
/*
* If the alt attribute is not empty, there's no need to explicitly pass
* it because wp_get_attachment_image() already adds the alt attribute.
*/
$html = sprintf( '%2$s',
esc_url( "https://www.example.com" ),
wp_get_attachment_image( $custom_logo_id, 'full', false, $custom_logo_attr )
);
}
// If no logo is set but we're in the Customizer, leave a placeholder (needed for the live preview).
elseif ( is_customize_preview() ) {
$html = sprintf( '<img class="custom-logo"/>',
esc_url( "https://www.example.com" )
);
}
if ( $switched_blog ) {
restore_current_blog();
}
/**
* Filters the custom logo output.
*
* #since 4.5.0
* #since 4.6.0 Added the `$blog_id` parameter.
*
* #param string $html Custom logo HTML output.
* #param int $blog_id ID of the blog to get the custom logo for.
*/
return apply_filters( 'get_custom_logo', $html, $blog_id ); }
This might not cover all the use cases, but you get the idea. Depending upon the theme you'll have a similar solution for your case. The important thing to figure out which case you fall under will be to identify the code where html for your logo is getting added. header.php is a good starting point.
Use this javascript in the header or footer of your theme:
<script>
document.getElementsByClassName("site-logo")[0].getElementsByTagName('a')[0].href="https://www.test.com";
</script>
i am assuming that site-logo is the class name of your LOGO.

I want to add a button after ad to cart of single product page in woo commerce

I am new in woo commerce. I have tried with this code But it is not working
function contact_concierge() {
return '<a class="fsfb" href="'.site_url().'">CONTACT CONCIERGE</a>';
}
add_action('woocommerce_after_cart', 'contact_concierge');
I want to add the button after the singple page add to cart table. PLease help me.
The closest place you can get it to is underneath the product title, using:
function contact_concierge() {
echo '<a class="fsfb" href="'.site_url().'">CONTACT CONCIERGE</a>';
}
add_action('woocommerce_single_product_summary', 'contact_concierge');
Screenshot:
Reference:
http://docs.woothemes.com/document/hooks/
<?php do_action( 'woocommerce_after_add_to_cart_button' ); ?>
and
<?php do_action( 'woocommerce_after_add_to_cart_form' ); ?>
Are actually much closer to what the OP was looking for... assuming I understood correctly. The former is directly after the add to cart button and is therefore inside the <form> element. The latter is after the </form> closing tag.
You can see them in the WooCommerce templates /single-product/add-to-cart/single.php as well as variable.php and grouped.php.
function contact_concierge() {
echo'<a class="fsfb" href="'.site_url().'">CONTACT CONCIERGE</a>';
}
add_action('woocommerce_after_add_to_cart_button', 'contact_concierge');

Resources