Im working with Wordpress.
For the last hour Im trying to find a code in php. files considering the "Quick view" button, but with no results.
Does anyone know where I can find it?
Best regards.
Filip
It depends on the eCommerce plugin you are using and also on the theme. If you are using woocommerce with a theme built for woocommerce then you can find these kind of things in "woocomerce" folder located in theme directory. If there is no such directory in your theme then take a look at woocommerce plugin directory.
If you are using this plugin for the quick view
You can try this code:
add_filter('woocommerce_loop_quick_view_button','custom_quick_view');
function custom_quick_view($output)
{
$output = 'My Cutom Output';
return $output;
}
For OceanWP theme please try this code:
add_filter('ocean_woo_quick_view_button_html','custom_quick_view');
function custom_quick_view($output)
{
global $product;
$output = '<a href="#" id="product_id_' . $product->get_id() . '"
class="owp-quick-view" data-product_id="' . $product->get_id() . '"><i
class="icon-eye"></i>' . esc_html__( 'Quick View', 'oceanwp' ) . '</a>'; //Edit the $output as you want
return $output;
}
Place this code in your functions.php
Ok If anyone looking to change the text this how I did it and it works with any Theme:
Just add this a snippet in WordPress so you don't need to play around with function file or even when you update the theme or the plugin it will not change or break the text.
add_filter('woocommerce_loop_quick_view_button','custom_quick_view');
function custom_quick_view($output)
{
global $product;
$output = '<a href="#" id="product_id_' . $product->get_id() . '"
class="quick-view-button button" data-product_id="' . $product->get_id() . '"><i
class="icon-eye"></i>' . esc_html__( 'Buy Now', 'wc_quick_view' ) . '</a>'; //Edit the $output as you want
return $output;
}
Related
I have managed to get all product links on my Woocommerce site to open in a new tab, however, I am using endless scroll with ajax for loading more products and the products that get loaded via endless scroll does not open in a new tab when clicking on them.
Here is my current code for opening products in a new tab;
remove_action( 'woocommerce_before_shop_loop_item','woocommerce_template_loop_product_link_open', 10 );
add_action ( 'woocommerce_before_shop_loop_item', 'chr_function_open_new_tab', 10 );
function chr_function_open_new_tab() {
echo '<a target="_blank" href="' . get_the_permalink() . '" class="woocommerce-LoopProduct-link">';
}
Any help with this is highly appreciated.
Thanks in advance!
I think that your remove_action cannot take an action. That's why it gives a trouble. So try this code:
add_action('init',function(){ remove_action( 'woocommerce_before_shop_loop_item', 'woocommerce_template_loop_product_link_open', 10 ); } ,0);
function chr_function_open_new_tab() {
echo '<a target="_blank" href="' . get_the_permalink() . '" class="woocommerce-LoopProduct-link">';
}
Second Other Solution, you can do it with simple jQuery
add_action('wp_footer',function(){
if ( has_term( 'stone', 'product_cat' ) ) {
echo '<script>
//for existing content
jQuery(".woocommerce-LoopProduct-link").attr("target","_blank");
//for content part which comes from AJAX
jQuery( document ).ajaxComplete(function() {
jQuery(".woocommerce-LoopProduct-link").attr("target","_blank");
});
</script>';
}
});
Instead try to use this dedicated filter hook for add to cart button:
// Change loop add to cart ajax button to a linked button to single product pages
add_filter( 'woocommerce_loop_add_to_cart_link', 'replace_loop_add_to_cart', 20, 2 );
function replace_loop_add_to_cart( $html, $product ) {
$link = $product->get_permalink();
$text = __("Read More", "woocommerce");
return '' . $text . '';
}
And here for the product link:
add_filter( 'woocommerce_before_shop_loop_item', 'replace_template_loop_product_link_open', 1 );
function replace_loop_product_link() {
remove_action( 'woocommerce_before_shop_loop_item','woocommerce_template_loop_product_link_open', 10 );
add_action ( 'woocommerce_before_shop_loop_item', 'new_loop_product_link_open', 10 );
}
function new_loop_product_link_open() {
global $product;
echo '<a href="' . esc_url( $product->get_permalink() ) . '" target="_blank" class="woocommerce-LoopProduct-link woocommerce-loop-product__link">';
}
Code goes in function.php file of your active child theme (or active theme). Tested and works.
But in your case, it could not work as expected, depending on how your custom ajax functionality is implemented. As the problem remains for products loaded via ajax, the target="_blank" need to be implemented in the corresponding script too.
At this point nobody can help you more as we can't guess how this functionality is built.
I recently added code snippet to my functions.php child theme file which task is to echo a "Read More" button under all products which leads the user to the click product page. The product-id link is not working. Here is the code:
/*-ADD NEW BUTTON THAT LINKS TO PRODUCT PAGE FOR EACH PRODUCT */
add_action('woocommerce_after_shop_loop_item','replace_add_to_cart');
function replace_add_to_cart() {
global $product;
$link = $product->get_permalink();
echo do_shortcode('<br><button link="' . esc_attr($link) . '">Read more</button>');
}
Right now, It just shows a button text(without class) which does not redirect to any product link. I want to add the primary button to it as well.
There is many different errors in your code and your question is not so clear. So you can:
1) To add an additional button (below existing add-to-cart button):
add_action('woocommerce_after_shop_loop_item', 'replace_add_to_cart' );
function replace_add_to_cart() {
global $product;
echo '<br><a class="button" href="' . esc_attr( $product->get_permalink() ) . '">' . __( "Read more" ) . '</a>';
}
Code goes in function.php file of your active child theme (or theme) or also in any plugin file.
Tested and works.
2) Replace add to cart button using the woocommerce_loop_add_to_cart_link filter hook this way:
add_filter( 'woocommerce_loop_add_to_cart_link', 'replace_loop_add_to_cart_button', 10, 2 );
function replace_loop_add_to_cart_button( $button, $product ) {
return '<a class="button" href="' . $product->get_permalink() . '">' . __( "Read more" ) . '</a>';
}
Code goes in function.php file of your active child theme (or theme) or also in any plugin file.
Tested and works.
I am a newbie, please help me with creating a wordpress image shortcode, as simple as:
[img src=""]
Which shows its thumbnail (thumbnail width=100%), links to OR opens the same source image, when clicked.
I tried searching but could not find in existing plugins, please guide me if any.
Please guide me thoroughly for every copy paste in function.php or anywhere else.
// Add Shortcode
function img_shortcode($atts)
{
// Attributes
$atts = shortcode_atts(
[
'src' => '',
'link_to_img' => '',
], $atts, 'img'
);
$return = '';
if ($atts['link_to_img'] == 'yes')
{
$return = '<a href="' . $atts['src'] . '">
<img src="' . $atts['src'] . '"/>
</a>';
}
else{
$return = '<img src="' . $atts['src'] . '"/>';
}
// Return HTML code
return $return;
}
add_shortcode('img', 'img_shortcode');
Code goes in function.php file of your active child theme (or theme). Or also in any plugin php files.
USAGE
Without link:: In PHP
echo do_shortcode('[img src="http://example.com/wp-content/uploads/2017/02/hello.jpg" link_to_img="no"]');
Without link:: In Editor
[img src="http://example.com/wp-content/uploads/2017/02/hello.jpg" link_to_img="no"]
With link:: In PHP
echo do_shortcode('[img src="http://example.com/wp-content/uploads/2017/02/hello.jpg" link_to_img="yes"]');
With link:: In Editor
[img src="http://example.com/wp-content/uploads/2017/02/hello.jpg" link_to_img="yes"]
Hope this helps!
The Gallery feature allows wordpress to add one or more image galleries to your posts and pages using a simple Shortcode
[gallery ids="729,732,731,720"]
enter link description here
I'd like to add a button next to "Add to Cart" on the product page that adds "-sample" to the product URL when clicked.
Example:
You're viewing Product 1's page and the URL is "http://www.example.com/shop/product-1/"
When you click on the button, it adds "-sample" to the URL
"http://www.example.com/shop/product-1-sample/"
How can I achieve this?
Thanks
For woocommerce 3+ (only):
In woocommerce 3 you will use woocommerce_after_shop_loop_item action hook instead, as the hook woocommerce_after_add_to_cart_button will not work anymore.
add_action( 'woocommerce_after_add_to_cart_button', 'add_custom_button', 10, 0 );
function add_custom_button() {
global $product;
$product_link = $product->get_permalink();
$sample_link = substr($product_link, 0, -1) . '-sample/';
echo '<a class="button alt btn-sample" href="' . esc_url( $sample_link ) .'">' . __( "Get a sample", "my_theme_slug" ) . '</a>';
}
Code goes on function.php file of your active child theme (or active theme). Tested and works.
Before woocommerce 3:
This is possible using hook woocommerce_after_add_to_cart_button to add your additional button on product pages, using this custom function:
add_action( 'woocommerce_after_add_to_cart_button', 'add_custom_button', 10, 0 );
function add_custom_button() {
global $product;
$product_link = get_permalink( get_the_id() );
$sample_link = substr($product_link, 0, -1) . '-sample/';
echo '<a class="button alt btn-sample" href="' . esc_url( $sample_link ) .'">' . __( "Get a sample", "my_theme_slug" ) . '</a>';
}
This code goes on function.php file of your active child theme or theme.
This code is tested and fully functional.
Based on this: Add a button after add to cart and redirect it to some custom link in WooCommerce
And this: PHP - How to remove all specific characters at the end of a string?
It's been a long time since the original question, but here's a recent update that works for me, WooCommerce 6.3.1:
/* WooCommerce customization */
add_action( 'woocommerce_after_shop_loop_item', 'custom_select_link', 11 );
function custom_select_link() {
global $product;
// Custom "Select" button.
echo '<a class="custom-button" href="' . esc_url( get_permalink( $product->id ) ) . '"><button class="custom-button"> </button></a>';
}
This answer cites an answer in wordpress.stackexchange.
Sorry if this is a really stupid question. I am just starting to learn PHP and am probably jumping the gun a bit.
I am writing a very 'simple' wordpress plugin which has a custom post type and takes the content from it and returns it on the homepage with a shortcode. Below is the part of the code that handles the shortcode.
add_shortcode("new-tub", "new_tub_short");
function new_tub_short() {
$post_id = 87;
return '<a class="new-tub" href="' . home_url( '/test' , __FILE__ ) . '">' . get_post_field('post_content', $post_id) . '</a>';
}
So currently it wraps a link around the content of the post. All that is in the post will be an image, however, I would like to make it fool proof so it doesnt include another link and paragraph tag.
My question is, is it possible to search for the img tag within that post and return that only?
Thanks in advance,
Alex
You can do this by using strip_tags. Try this,
add_shortcode("new-tub", "new_tub_short");
function new_tub_short() {
$post_id = 87;
return '<a class="new-tub" href="' . home_url( '/test' , __FILE__ ) . '">' . strip_tags(get_post_field('post_content', $post_id), '<img>') . '</a>';
}
http://php.net/manual/en/function.strip-tags.php