Custom button appearing on all product pages in Woocommerce - wordpress

I'm currently using this code with a hook to a specific product but the button seems to be appearing for all other products on my website as well.
add_action('woocommerce_after_add_to_cart_button','additional_single_product_button');
function additional_single_product_button() {
$product_ids = is_single(871);
echo "<br>";
echo "<br>";
echo '<div>';
echo '<a data-type="inline" class="button alt" href="/contact-us/">Pay at Spa # $218 nett</a>';
echo '</div>';}
Here's my website: http://offers.elements.com.sg/
Please advise how I can just add this button for a specific product. Thank you.

Related

How to display product price on custom meta filed woocommerce?

I want to display product price on single page custom field. That filed is only readable filed users cant option to edit that price. Also on variable product page when product variations change according to that price also need to change. I have added below code for display the the custom field on single product page.
add_action('woocommerce_before_add_to_cart_button', 'my_custom_checkout_field');
function my_custom_checkout_field() {
// global $product;
echo "test";
echo '<div id="my_custom_checkout_field">';
echo ' <input type="text" name="my_field_name">';
echo '</div>';
}
I want to add variations product price on that filed.
To get Product price without woocommerce hook
define product as global
global $product;
and then get product price
$product->get_price();
add_action('woocommerce_before_add_to_cart_button', 'my_custom_checkout_field');
function my_custom_checkout_field() {
global $product;
$price = $product->get_price();
echo "test";
echo '<div id="my_custom_checkout_field">';
echo ' <input type="text" name="my_field_name" value=".$price.">';
echo '</div>';
}

How can I add a small logo which is always hovering on every product in grid in woocommerce?

I very new to Woocommerce and Wordpress, I am trying to add a different company logo to each different products in grid but I am not able to do it, I have also tried to find any plugin related to it but I found nothing. Please Friends if you know how to do it do let me Know.
There is the below image of what I am trying to get but not able to :
Click Here for Image
First download the acf plugin then make the image field for wooCommerce product only , After made the image field for products, Try " woocommerce_after_shop_loop_item_title " hook in function.php file ,where you can echo the image field of acf by "get_field" function for ACF. "here is the link : ---- https://www.advancedcustomfields.com/resources/image/".
<?php
// define the woocommerce_after_shop_loop_item_title callback
function action_woocommerce_after_shop_loop_item_title( ) {
// make action magic happen here...
$image = get_field('image'); // ACF field name/slug.
if( !empty($image) ){
?>
<img src="<?php echo $image['url']; ?>" alt="<?php echo $image['alt']; ?>" />
<?php
}
};
// add the action
add_action( 'woocommerce_after_shop_loop_item_title', 'action_woocommerce_after_shop_loop_item_title', 10, 0 );
?>
This will show the image on products ,After that do some styling on that in your theme style.css
If above hook does not work try this hook "woocommerce_after_shop_loop_item",

Is there any way to display the WooCommerce mini-cart on my WordPress site?

I'm developing a website whereby I would like customers to be able to constantly view the contents of their cart so they can add/remove items on the fly (using WooCommerce).
The theme I'm currently using is Flatsome (with the UXBuilder)
I've noticed there is a template for the WooCommerce mini-cart in woocommerce/templates/mini-cart.php. This looks like what I want to be displayed on my page
I have a plugin called WooCommerce Product Tables that (I believe) displays this mini-cart like this
I was wondering if there is any way for me to display this as a fixed element (within a div perhaps) on my page?
I'm quite inexperienced, so any help is appreciated :)
As Bhoomi suggested, using woocommerce_mini_cart(); works however ajax cart doesn't update the minit cart.
Using this method I suggest to wrap mini_cart function with "widget_shopping_cart_content" woocommerce class, for example :
<div class="widget_shopping_cart_content"><?php woocommerce_mini_cart(); ?></div>
So with ajax add to cart, the mini cart is updated also.
First Create the shortcode on function.php
// Add Shortcode
function custom_mini_cart() {
echo '<a href="#" class="dropdown-back" data-toggle="dropdown"> ';
echo '<i class="fa fa-shopping-cart" aria-hidden="true"></i>';
echo '<div class="basket-item-count" style="display: inline;">';
echo '<span class="cart-items-count count">';
echo WC()->cart->get_cart_contents_count();
echo '</span>';
echo '</div>';
echo '</a>';
echo '<ul class="dropdown-menu dropdown-menu-mini-cart">';
echo '<li> <div class="widget_shopping_cart_content">';
woocommerce_mini_cart();
echo '</div></li></ul>';
}
add_shortcode( '[custom-techno-mini-cart]', 'custom_mini_cart' );
Then add this [custom-techno-mini-cart] short code anywhere on page.
Now add this inside your template
<?php echo do_shortcode(['custom-techno-mini-cart']); ?>
Hope This will help you.
Make your layout according to your requirement in first point.
ADD Like This ALSo using This
woocommerce_mini_cart()
You can use woocommerce_mini_cart() wherever you want to display your minicart.
This function loads the mini-cart.php template to display the mini cart.

Send custom field value to email

I created custom post type named Emails, and added a custom field using advanced custom fields plugin to one post inside the custom post type called email footer, the field is image field that is supposed to show at the bottom of each automatic email going out of the website.
the current code I'm using
function wpcf7ev_verify_email_address2( $wpcf7_form ){
$email_footer = '<html>
<body style="color:#000000;">
<div style="font-size:16px;font-weight:bold;margin-top:20px;">
Regards,
<br/>
$email_footer .= '<img src="http://mysite.col/footer_image.jpg" width="100%" alt=""/>
</div>';
$email_footer .='<div style="display:none;">'.generateRandomString().
'</div></body>
</html>
';
the code is working, it displays the image with this url at the bottom: http://mysite.col/footer_image.jpg
but I don't want hardcoded, I want to be able to modify it with the custom field I created
I looked at ACF documentation and found this, but I don't know how to use it to still show that exact field on custom post type I created:
<?php
$image = get_field('image');
if( !empty($image) ): ?>
<img src="<?php echo $image['url']; ?>" alt="<?php echo $image['alt']; ?>" />
<?php endif; ?>
The code you've outlined from the ACF documentation tells you how to get the image from an ACF field using Image (with type array).
If we were to implement this into your function, we'd have to reference the image from the page somewhere. Without knowing how you're calling this there are a couple of ways you could embed it.
The first way, we pass it through to the function called on the page, like so...
wpcf7ev_verify_email_address2(get_field('image'));
and then update your function like so...
function wpcf7ev_verify_email_address2($image, $wpcf7_form)
{
$email_footer = '<div style="font-size:16px;font-weight:bold;margin-top:20px;">Regards,<br/>';
// get the image from the passed in image function.
$email_footer .= '<img src="' . $image['url'] . '" width="100%" alt="' . $image['alt'] . '"/></div>';
$email_footer .='<div style="display:none;">' . generateRandomString() . '</div>';
}
Or, the second way, if you are calling the function to modify an action or something, you'd have to get the image from whichever page ID / options page it is assigned to in your ACVF settings. This would make your function look a little like this:
function wpcf7ev_verify_email_address2($wpcf7_form)
{
// get image acf field from page with id 1
$image = get_field('image', 1);
// or get image from acf field on options page
// $image = get_field('image', 'options');
$email_footer = '<div style="font-size:16px;font-weight:bold;margin-top:20px;">Regards,<br/>';
$email_footer .= '<img src="' . $image['url'] . '" width="100%" alt="' . $image['alt'] . '"/></div>';
$email_footer .='<div style="display:none;">' . generateRandomString() . '</div>';
}
All of the above is presuming that your function is working as intended, with you needing help grabbing the ACF field, and the image is uploaded. You can wrap your declarations of get_field in if statements if required.

social icon location in wordpress

function flx_social_sharing_buttons($content) {
// Show this on post and page only. Add filter is_home() for home page
if(is_singular()){
// Get current page URL
$shortURL = get_permalink();
// Get current page title
$shortTitle = get_the_title();`enter code here`
// Construct sharing URL without using any script
$twitterURL = 'https://twitter.com/intent/tweet?text='.$shortTitle.'&url='.$shortURL.'&via=flx';
$facebookURL = 'https://www.facebook.com/sharer/sharer.php?u='.$shortURL;
$googleURL = 'https://plus.google.com/share?url='.$shortURL;
$tumblrURL = 'http://www.tumblr.com/share/link?url='.$shortURL;
// Add sharing button at the end of page/page content
$content .= '<div class="flx-social">';
$content .= '<a class="flx-link flx-facebook" href="'.$facebookURL.'" target="_blank"><i class="fa fa-facebook"></i></a>';
$content .= '<a class="flx-link flx-twitter" href="'. $twitterURL .'" target="_blank"><i class="fa fa-twitter"></i></a>';
$content .= '<a class="flx-link flx-googleplus" href="'.$googleURL.'" target="_blank"><i class="fa fa-google-plus"></i></a>';
$content .= '<a class="flx-link flx-tumblr" href="'.$tumblrURL.'" target="_blank"><i class="fa fa-tumblr"></i></a>';
$content .= '</div>';
return $content;
}else{
// if not post/page then don't include sharing button
return $content;
}
};
add_filter( 'the_content', 'flx_social_sharing_buttons');
i use this code to display sociAl sharing buttons below my post ,
i need to add shortcode functionality so that it appears wherever i want
how to do it pls help
You simply can do it with bellow code,
<?php echo do_shortcode('[the_content]'); ?>
just pest this code where you want social icons and u can get it on those place.
I'm not sure that I understand your question correctly, but hopefully you'll be able to use the following to address your challenge.
If I wanted to repurpose the function to render the social sharing buttons, I would start of by changed the first line to
function flx_social_sharing_buttons($content = false) {
The code should at this stage still, as expected, add the social sharing buttons after each post. To add it programmatically or within a post or page you can add the following line, creating a shortcode:
// Add the [my-social-buttons] shortcode
add_shortcode( 'my-social-buttons', 'flx_social_sharing_buttons' );
Documentation available at: https://codex.wordpress.org/Shortcode_API
Great resource for creating shortcodes and other Wordpress features:
http://generatewp.com
You can now use the shortcode in a post or page. To use it inside a php file, do the following
echo do_shortcode('[my-social-buttons]');
If you find that you'd rather now use your function programatically all that's left to do is to remove the original hook, if your social sharing buttons are now duplicated:
// Remove or comment out
// add_filter( 'the_content', 'flx_social_sharing_buttons');

Resources