Add text under "Place Order" button at WooCommerce checkout - php

I would like to add some text under the "Place Order" button at WooCommerce checkout.
I'm using the woocommerce_review_order_after_submit hook:
add_action( 'woocommerce_review_order_after_submit', 'add_after_checkout_button' );
function add_after_checkout_button() {
echo '<p>By clicking on the purchase button, you agree to our Terms of Service and Privacy Policy</p>';
}
Result (screenshot): https://ibb.co/F38bxDf
Could someone please help me edit this code to:
Add some space at the top (between the text and the "Place Order"
button)
Center align the text
Turn "Terms of Service" and "Privacy Policy" into clickable links
Decrease the line-height of the text
Decrease the font size
Is there a way to give this text a CSS class so I can control the styling of it with custom CSS? Or is possible to somehow type the custom CSS in the code snippet itself?
EDIT:
I've got 2 pieces of code.
Nr 1:
add_action( 'woocommerce_review_order_after_submit', 'add_after_checkout_button' );
function add_after_checkout_button() {
echo '<p class="text-under-place-order">By clicking on the purchase button, you agree to our Terms of Service and Privacy Policy</p>';
}
and
Nr 2:
<script src="https://kit.fontawesome.com/5e15d2f246.js" crossorigin="anonymous"></script>
<div class="row">
<div class="column">
<i class="fas fa-lock"></i>
SSL encrypted payment
</div>
<div class="column">
<i class="fas fa-undo"></i>
100% money-back guarantee
</div>
</div>
Code snippet Nr 1 solves my initial question.
Code snippet Nr 2 is an addition to display "encrypted payment" and "money-back guarantee" above the text as per my request in the comments.
I don't know how to merge these 2 pieces of code into 1.

You could add a class like this:
function add_after_checkout_button() {
echo '<p class="yourClassName">By clicking on the purchase button, you agree to our Terms of Service and Privacy Policy</p>';
}
Or use css inline like this:
function add_after_checkout_button() {
echo '<p style="padding-top: 10px;">By clicking on the purchase button, you agree to our Terms of Service and Privacy Policy</p>';
}
To turn the text into links just use a Terms and Service tag inside, just like you already did with the <p>.
EDIT:
HTML and CSS code to add an "encrypted payment" and "money-back guarantee" as requested in the comments:
<script src="https://kit.fontawesome.com/5e15d2f246.js" crossorigin="anonymous"></script>
<div class="row">
<div class="column">
<i class="fas fa-lock"></i>
SSL encrypted payment
</div>
<div class="column">
<i class="fas fa-undo"></i>
100% money-back guarantee
</div>
</div>
.row {
display: flex;
text-align: center;
}
.column {
flex: 50%;
}

You should just add a class to your tag <p></p> and style it in your style.css file in your child theme.
For the links, just add tags around the words "Terms of Service" and "Privacy Policy"

Related

Add tool tip description next to product attribute dropdown menu woocommerce

I would like to add a tool tip to each product variation dropdown with a small description. Here is a screenshot of what I'm envisioning.
I thought about using CSS and adding the pseudo element :after, but I can't make it clickable. Also I don't see a hook to add content to each dropdown.
I used a woocommerce hook (woocommerce_before_variations_form), bootstrap tooltip and css positioning to move the tooltip btn's where I wanted them.
Woocommerce function:
add_action( 'woocommerce_before_variations_form', 'krank_custom_action', 5 );
function krank_custom_action() {
echo '<button class="krank-tooltip ttone" type="button" data-
toggle="tooltip" data-placement="top" title="Your text here">Your btn text</button>
<button class="krank-tooltip tttwo" type="button" data-toggle="tooltip" data-placement="top" title="Your text here ">Your btn
text</button>';
}
CSS:
/* Tool tips */
button.krank-tooltip {border: none;color: #0157a3;}
button.krank-tooltip.ttone {position: relative;top: 73px;right: -273px;}
button.krank-tooltip.tttwo {position: relative;top: 114px;right: -161px;}

How to add 'view cart' section to a page using woocomerce?

I would like to make a section at the top of my page for customers to be able to access their cart. Is there a way of doing this?
Thanks
You can add view cart button anywhere you want, here is the simple html :
<div style="text-align: right;">
<p>
<a href="http://site_name/shop/cart/" class="button">View Cart
<a href="http://site_name/shop/checkout/" class="button checkout">Checkout
</p>
</div>

How to draw text on top of image HTML?

I need to draw text in top of the image this the look like
when the page load i need to display price in side the photo.I try it like this
<button class="btn btn-danger" id="buy-btn" data-toggle="modal" data-target=".package-buy-modal">BOOK NOW</button>
<img id="price-tag" style="position: relative;width: 100%; /* for IE 6 */" src="<?php echo base_url()?>assets_profile/img/price.png">
<h2 style="-o-transform: rotate(32deg);-moz-transform: rotate(32deg);-webkit-transform: rotate(32deg);">$<?php echo $car_data['Charges']; ?></h2>
But it didn't work as i expected.how can i do this.if there is another easy way to this ?
Here is an example of using background-image within a div so that you can put more inside the div, ie)text
HTML:
<div id='image' src='http://i.stack.imgur.com/1DZ6X.jpg'>
<h2 id='price'>Price: $10</h2>
</div>
CSS:
#image {
width:243px;
height:163px;
background-image:url('http://i.stack.imgur.com/1DZ6X.jpg');
}
check it out here
Add a z-index value to the <img> and the <h2>. For example, z-index:98 on the <img>, and z-index:99 for the <h2>. (A higher value because you want it on top).
I would also recommend moving all styles to a css file, rather than use the inline style attribute.

Customizing a Message Based On What Was Clicked

I have a div that has some smaller divs inside it. Each small div has its own id, and belongs to a class.
When you click the div, a message pops up that says "Added to cart" (Guess what this is about) and I want to know how to get the value of the text inside a paragraph inside the div that is clicked. I want to do this with PHP, so I can actually make some server changes with the users's cart.
Here is a site for my code (I try to include as little code, but some you may find unnecessary)
http://jsfiddle.net/av3Da/2/
My html:
<div id="shop">
<input type="button" value="Go To Checkout" id="checkoutbutton" />
<div class="shopitem" id="OrangeBG">
<p class="shopitemname">Orange Background Color</p>
<div class="buyinfo">
<p class="buyinfoname">Buy - 40 Coins</p>
</div>
</div>
<div class="shopitem" id="BlackBG">
<p class="shopitemname">Black Background Color</p>
<div class="buyinfo">
<p class="buyinfoname">Buy - 40 Coins</p>
</div>
</div>
<div class="shopitem" id="GreenBG">
<p class="shopitemname">Green Background Color</p>
<div class="buyinfo">
<p class="buyinfoname">Buy - 40 Coins</p>
</div>
</div>
<div class="shopitem" id="BlueBG">
<p class="shopitemname">Blue Background Color</p>
<div class="buyinfo">
<p class="buyinfoname">Buy - 40 Coins</p>
</div>
</div>
<div class="shopitem" id="YellowBG">
<p class="shopitemname">Yellow Background Color</p>
<div class="buyinfo">
<p class="buyinfoname">Buy - 40 Coins</p>
</div>
</div>
<div class="shopitem" id="PurpleBG">
<p class="shopitemname">Purple Background Color</p>
<div class="buyinfo">
<p class="buyinfoname">Buy - 40 Coins</p>
</div>
</div>
</div>
<div id="confirmbox">
<p>The item "<span id="box_item"></span>" was successfully added to your cart</p>
</div>
My javascript:
$(document).ready(function(){
$(".buyinfo")
.click(AddToCart)
.mouseout(popUpVanish);
$('#confirmbox').hide();
});
function AddToCart() {
$('#confirmbox').show('normal');
}
function popUpVanish() {
$('#confirmbox').delay(2000).fadeOut() ;
}
Why do i need to include code with JSFIDDLE?
Everything looks jumbled up, but that's because its on the fiddle site.
So if I wanted to customize the message to say "You bought X Background Color" and then add that to a PHP database, or javascript array?
In addition, I am looking for some advice on how to change the text on the div that says "Buy for 40 coins" into "Added to cart - Click to remove" and so that you click the button again and it removes the item from the cart.
If my question is not good, please don't just rate it down, write a comment and I'll fix!!!!
thanks
I've just tried to achieve the most part you've asked for. But I can't do all for you, you have to try it yourself and if there is a problem you have to ask another specific question.
// Shop Stuff
var cart = [];
$(document).ready(function(){
var buttonTxt = '';
$(".buyinfo").click(function() {
//Store text and id of the selected element
var txt = $(this).siblings('.shopitemname').text();
var id = $(this).closest('.shopitem').attr('id');
if(!$(this).hasClass('added')) {
buttonTxt = $('.buyinfoname', this).text();
$('#box_item').text(txt);
cart[id] = txt;
//Change text
$('.buyinfoname', this).text('Added to cart - Click to remove');
$(this).addClass('added');
//Show and hide overlay
$('#confirmbox').show('normal').delay(2000).fadeOut();
} else {
delete(cart[id]);
$(this).removeClass('added');
$('.buyinfoname', this).text(buttonTxt);
}
console.log(cart);
});
});
Css to hide the overlay by default.
#confirmbox {
display: none;
}
Look at that fiddle to try it. Have a look at the console to see the output and the current state of cart.

Words not staying in css toggle

I have a toggle that I am using for twitter bootstrap, and one of the words is poping out and not staying inside the toggle, I highlighted the messed up word in a red box below:
My code is:
<div class=\"span9 space\">
<h3 class=\"title pull-left\">$name</h3>
<link rel=\"stylesheet\" href=\"lib/prism/prism-light.css\">
<script src=\"lib/prism/prism.js\"></script>
<link rel=\"stylesheet\" href=\"toggle-switch.css\">
<form class=\"form-horizontal pull-right\">
<div class=\"control-group\">
<label class=\"control-label\"></label>
<div class=\"controls btn disabled switch switch-two\">
<input id=\"week9\" name=\"view\" type=\"radio\" checked>
<label for=\"week9\" onclick=\"\">Not Visited</label>
<input id=\"month10\" name=\"view\" type=\"radio\">
<label for=\"month10\" onclick=\"\">Visited</label>
<span class=\"slide-button btn btn-warning\"></span>
</div>
</div>
</form>
</div>
The toggle I am using is from here:
http://ghinda.net/css-toggle-switch/bootstrap.html
Here is also my live code:
http://www.beerportfolio.com/breweryPage2.php?id=BSsTGw
The issue is that the Switch class does not stretch for your words,
you can solve it by hardcoding the width in the switch class in your style sheet or by adding it in the div you want stretch and this should solve your issue
<div class=\"controls btn disabled switch switch-two\" style=\"width: xxxpx !important;\">
while xxx represent the value you need
I did a live edit on the demo you supplied and used your values for the items and added a smaller width than what is needed and the visited part of 'Not Visited' went to a new line. You might want to have a larger width for your toggle item(s).
EDIT:
It looks like you did modify some of the css or it inherited some, you can modify it any way you want but try:
toggle-switch line 210
.toggle label,
.toggle p,
.switch label {
line-height: 13px;/*30px*/
}
and remove:
bootstrap.min.css line 333
.form-horizontal .controls {
margin-left: 0;/*180px*/
}

Categories