Text under Add to cart (woocommerce) - wordpress

How can I add a text saying "Contact us for bulk purchase enquiry" under 'Add to cart' button for all woocommerce products.
Thanks

Try adding this code to your functions.php file :
add_action( 'woocommerce_after_add_to_cart_button', 'content_after_addtocart_button_func' );
function content_after_addtocart_button_func() {
// Echo content.
echo '<div style="font-size:10px;"><em>(*Contact us for bulk purchase enquiry)</em></div>';
}
Hope it helps!

Related

Default product short description

On my woocommerce site I want to add the text "Only available in stores" to all my product's short description, and also have that same text be default for all future products I add.
I had a search but the solutions seemed way to complex for me. Is there some code I can paste in the functions.php?
Thanks!
You can solve this problem easily. You need to some code push to theme functions.php or use code snippets plugin. This code only works when the WooCommerce product short description is empty.
function wp_woocommerce_short_description_if_empty(){
global $post;
if (empty($post->post_excerpt)) {
$post_excerpt = '<p class="default-short-desc">';
$post_excerpt .= 'Your Custom Message Here.';
$post_excerpt .= '</p>';
echo $post_excerpt;
}
}
add_action('woocommerce_single_product_summary', 'wp_woocommerce_short_description_if_empty', 21);
You can also try this for your default product description, you can Add Custom Text before/after the Product Short Description
add_filter( 'woocommerce_short_description', 'woo_add_text_after_excerpt_single_product', 20, 1 );
function woo_add_text_after_excerpt_single_product( $post_excerpt ){
/* Method 1: Add Custom Text before the Product Short Description on product page */
/* $content= '<ul class="fancy-bullet-points red">
<li>'.__('Only available in stores').'</li>
</ul>';
return $content.'<br>'.$post_excerpt;
*/
/* Method 2: Add Custom Text after the Product Short Description on product page */
$post_excerpt .= '<ul class="fancy-bullet-points red">
<li>'.__('Only available in stores').'</li>
</ul>';
return $post_excerpt;
}
Note: Add Custom Text before the Product Short Description on the product page - code is commented so you can uncomment accordingly.

How to add "show details" button near the cart button in Woocommerce

I want to add additional button in woocommerce single product. In which file I need to make changes?
Example on screen:
enter image description here
Try this code,
function wc_shop_demo_button() {
echo '<a class="button demo_button" style="padding-right: 0.75em;padding-left: 0.75em;margin-left: 8px; background-color: #0ebc30;" href="'.get_field( "url_demo" ).'" target="_blank">Show Details</a>';
}
add_action( 'woocommerce_after_shop_loop_item', 'wc_shop_demo_button', 20 );
add_action( 'woocommerce_after_add_to_cart_button', 'wc_shop_demo_button', 20 );
Hope this will helps you. For more details visit,
how to add button after woocommerce shop loop item
First of all, create a Custom Field using Advanced Custom Fields plugin for Woocommerce Product Page.
For creating a custom field using the ACF plugin, refer to the below article.
https://wpmayor.com/woocommerce-custom-fields-how-to-create-and-display-them/
To display the Custom Button in the frontend of the website, add the below code in functions.php file.
function rf_custom_product_button() {
echo '<a class="button custom_button" href="'.get_field( "custom_button" ).'" target="_blank">Click Here</a>';
}
add_action( 'woocommerce_after_add_to_cart_button', 'rf_custom_product_button', 20 );
add_action( 'woocommerce_after_shop_loop_item', 'rf_custom_product_button', 20 );
In the above code, Change the "custom_button" to the name of the field which you create using ACF.

Custom Button in WooCommerce add order admin page

I want to add a custom button in the page where admin can manually create new order (Admin Order page).
Admin -> Woocommerce -> order -> Add order
After i add product and when clicked edit button can i show a custom button near to Add Meta button ? I cannot find a hook to use.
add_action( 'woocommerce_after_order_itemmeta', 'editable_order_meta_general' );
function editable_order_meta_general(){
?>
<button class="add_values button"><?php _e( 'Add Custom', 'woocommerce' ); ?></button>
<?php
}
I have added the above code. I got the result but the button is displayed soon after i add the product. I only want the button to display when i click edit button.
This is my error
This is my requirement.
#UPDATE
When i added the following code, it worked. Is it the right way ? Since woocommerce button in the same field is set display:none; initially .
add_action( 'woocommerce_after_order_itemmeta', 'editable_order_meta_general' );
function editable_order_meta_general(){
?>
<div class="edit" style="display: none;">
<button class="add_values button"><?php _e( 'Add Custom', 'woocommerce' ); ?></button>
</div>
<?php
}
#Answer
As mentioned by Loiz in comment, there is no hook in WooCommerce to achieve this requirement. Have to change logic or something else.
The hook you're looking for is woocommerce_order_item_add_action_buttons()
I found this tutorial: https://hungred.com/how-to/woocommerce-hook-custom-button-admin-order-page/
Hope that helps

WooCommerce modify text "This product is currently out of stock and unavailable"

I'm using WordPress/WooCommerce with the plugin Booster.
I'm trying to hide the prices and "Add to Cart" button for visitors from China. Using Booster, I was able to do this, but instead of displaying prices and "Add to Cart", it is displaying "This product is out of stock and unavailable".
How can I change the text to something more useful, such as "Please contact us for more information on this product"?
Thanks for any help!
Rick
If you want to remove prices and add to cart button from shop page to all your products, try this hook
add_action( 'woocommerce_after_shop_loop_item_title', , 'your_func_name', 10 );
add_action('woocommerce_after_shop_loop_item', 'your_function_name', 10 );
function your_function_name()
{
remove_action('woocommerce_after_shop_loop_item','woocommerce_template_loop_add_to_cart', 10 );
}
function your_func_name()
{
remove_action('woocommerce_after_shop_loop_item_title','woocommerce_template_loop_price', 10 );
?>
<div>
<?php _e('This product is out of stock and unavailable'); ?>
<p><?php _e('Please contact us for more information on this product'); ?> </p>
</div>
<?php
}

how to add text area and checkbox before order details on Woocommerce checkout page

I want to add some one check box, one text area and one link before the order details on checkout. I tried to find all over the stackoverflow but I did not found any exact information or code. If anyone help me so I will be very thankful to you. check screen shot for more info http://prntscr.com/9dtloy
add_action( 'woocommerce_review_order_before_payment', 'skyverge_before_paying_notice' );
function skyverge_before_paying_notice() {
wc_print_notice( __( 'Here is some text', 'woocommerce' ), 'error' );
}
I tried this code which is showing something like this http://prntscr.com/9dttsi
Thanks
Have you tried add_action( 'woocommerce_review_order_before_order_total', 'my_custom_fields' );
function my_custom_fields(){
// put your custom fields out here
}
The following hook will add the text before the order details but below the "Your order" text.
//Hook
add_action('woocommerce_before_cart_contents', 'fields_before_order_details');
//function
function fields_before_order_details(){
wc_print_notice( __( 'Here is some text', 'woocommerce' ), 'error' );
}
This is not the only hook that will achieve this, you can find a list of more Woocommerce hooks here.
This is how we can show content right before the "Your Order"
add_action('woocommerce_after_checkout_billing_form', 'fields_before_order_details');
//function
function fields_before_order_details(){
echo 'Terms & Conditions';
}
Thanks all for your contribution

Resources