I am trying to have the "Add to Cart" button change to "Make an Inquiry" and I would like that to link to either a tab further down the page or to a separate page all together. I would like this change to be based on availibilty or whether or not the price is listed.I already have a basic understanding on how to change the link and text conditionally, but just not based on the parameters and to the scope I need.
I know this response is incredibly late but below is what I have. The problem I have is that it is not in the position of the the original add to cart button, and its too wide.
add_action('woocommerce_single_product_summary','replace_add_to_cart');
function replace_add_to_cart() {
global $product;
if ( ! $product->is_in_stock() ){
remove_action( 'woocommerce_single_product_summary','woocommerce_template_single_add_to_cart', 30 );
add_action( 'woocommerce_single_product_summary','consult_bezambar_expert', 30 );
function consult_bezambar_expert() {
global $product;
echo '<form action="' . esc_url($product->get_permalink( "#tab- reviews" )) . '" method="get">
<button type="submit" class="single_add_to_cart_button button alt">Consult Bez Ambar Expert</button>
</form>';
}
}
}
add_filter( 'woocommerce_product_single_add_to_cart_text', 'woo_custom_cart_button_text' );
function woo_custom_cart_button_text( $text )
{
if( has_term( 'your-special-category', 'product_cat' ) )
{
$text = __( 'Make an Inquiry', 'your-plugin' );
}
return $text;
}
Add this code in your functions.php file
Related
Attempting to change the title of the "pay for order" page / "customer payment page"
https://url.com/checkout/order-pay/753/?pay_for_order=true&key=wc_order_xxxxxx
Below is not currently working, it is modified from changing the title on the thank you page.
add_filter( 'the_title', 'woo_title_pay_order', 10, 2 );
function woo_title_pay_order( $title, $id ) {
if ( function_exists( 'is_pay_for_order_page' ) &&
is_pay_for_order_page() && get_the_ID() === $id ) {
$title = "Checkout";
}
return $title;
}
Updated
You can use the following to change "Pay for order" page title:
add_filter( 'the_title', 'change_pay_for_order_title' );
function change_pay_for_order_title( $title ) {
if ( is_wc_endpoint_url( 'order-pay' ) ) {
return __('Checkout', 'woocommerce');
}
return $title;
}
Or also the following code based on 'order-pay' endpoint (but changes the breadcrumb):
add_filter( 'woocommerce_endpoint_order-pay_title', 'change_checkout_order_pay_title' );
function change_checkout_order_pay_title( $title ) {
return __( "Checkout", "woocommerce" );
}
Code goes in functions.php file of the active child theme (or active theme). Tested and works.
Related: Set My Account custom items endpoints titles in WooCommerce
I want to be able to display a specific Add To Card Text for each single product, if set.
There are some plugins out there, but they "just" cover Add To Card Text for categories or product types. That's why I tried this way using a Custom Field.
So I wrote this code directly in a template file. This code works, but is it good, safe, at the right place?
// file: /woocommerce-templates/single-product/add-to-cart/simple.php
<button "..." >
<?php
$text = get_post_meta($product->get_id(), 'add_to_cart_text', true);
if ($text) {
echo esc_html($text);
} else {
echo esc_html($product->single_add_to_cart_text()); // this line is default
}
?>
</button>
I would use this instead:
<?php
add_filter( 'woocommerce_product_add_to_cart_text', 'custom_add_to_cart_button_text', 20, 2 );
function custom_add_to_cart_button_text( $button_text, $product ) {
$custom_button_text = get_post_meta( $product->get_id(), 'add_to_cart_text', true );
// If there is custom text set for this product, then display it instead of the default text.
if ( ! empty( $custom_button_text ) ) {
$button_text = __( $custom_button_text, 'text-domain' );
}
return $button_text;
}
Paste it in your functions.php
In Woocommerce, how do I add a "Continue" button inked to the the product page just after?
And inside the product page how to add a checkout button just under the add to cart button?
Any help is appreciated.
The following code will:
In woocommerce archive pages: Add an additional button "Continue" linked to the product (for simple products)
In single product pages: Add an additional button linked to checkout page.
The code:
// Archives pages: Additional button linked to the product
add_action( 'woocommerce_after_shop_loop_item', 'loop_continue_button', 15 );
function loop_continue_button(){
global $product;
if( $product->is_type('simple') ){
$link = $product->get_permalink();
$text = __("Continue", "woocommerce");
echo '' . $text . '';
}
}
// Single product pages: Additional button linked to checkout
add_action( 'woocommerce_single_product_summary', 'product_additional_checkout_button', 1 );
function product_additional_checkout_button() {
global $product;
// For variable product types
if( $product->is_type( 'variable' ) ) {
add_action( 'woocommerce_single_product_summary', 'custom_checkout_button', 21 );
}
// For all other product types
else {
add_action( 'woocommerce_single_product_summary', 'custom_checkout_button', 31 );
}
}
function custom_checkout_button() {
$link = wc_get_checkout_url();
$text = __("Proceed to checkout", "woocommerce");
echo '' . $text . '';
}
Code goes in function.php file of your active child theme (or active theme). Tested and work.
I want to display an additional button below the description to a specific product category: "bracelets"
so I developed a piece of code, which does not work:
add_action( 'woocommerce_single_product_summary', 'my_extra_button_on_product_page', 30 );
function my_extra_button_on_product_page() {
if ( is_product_category('bracelets')) {
global $product;
echo 'Extra Button';
}
}
Any idea about what's wrong here?
Your question is not really clear.
1) If you want to display a custom button for a specific product category on product category archives pages below the description of this product category you will use:
add_action( 'woocommerce_archive_description', 'extra_button_on_product_category_archives', 20 );
function extra_button_on_product_category_archives() {
if ( is_product_category('bracelets') ) {
echo '<a class="button" href="www.test.com">Extra Button</a>';
}
}
2) If you want to display a custom button in single product pages for a specific product category below the short description of this product you will use:
add_action( 'woocommerce_single_product_summary', 'extra_button_on_product_page', 22 );
function extra_button_on_product_page() {
global $post, $product;
if ( has_term( 'bracelets', 'product_cat' ) ) {
echo '<a class="button" href="www.test.com">Extra Button</a>';
}
}
3) If you want to display a custom button in single product pages for a specific product category below the description (in the product tab) of this product you will use:
add_filter( 'the_content', 'add_button_to_product_content', 20, 1 );
function add_button_to_product_content( $content ) {
global $post;
if ( is_product() && has_term( 'bracelets', 'product_cat' ) )
$content .= '<a class="button" href="www.test.com">Extra Button</a>';
// Returns the content.
return $content;
}
4) If you want to display a custom button in single product pages for a specific product category below the product tabs, you will use:
add_action( 'woocommerce_after_single_product_summary', 'extra_button_on_product_page', 12 );
function extra_button_on_product_page() {
global $post, $product;
if ( has_term( 'bracelets', 'product_cat' ) ) {
echo '<a class="button" href="www.test.com">Extra Button</a>';
}
}
Code goes in function.php file of your active child theme (or active theme).
Tested and works.
For product category archives pages use is_product_category().
For all other cases has_term().
add_action( 'woocommerce_after_single_product_summary', 'my_extra_button_on_product_page', 30 );
the following code adds the button before the loop on a product category archive
add_action( 'woocommerce_archive_description', 'extra_button_on_product_category_archives', 20 );
function extra_button_on_product_category_archives() {
if ( is_product_category('bracelets') ) {
echo '<a class="button" href="www.test.com">Extra Button</a>';
}
}
I need help!
I removed the "add to cart" button from my main store page because "see items" makes more sense in this case.
here is the code I added to my child functions.php theme:
`
function remove_loop_button(){
remove_action( 'woocommerce_after_shop_loop_item', 'woocommerce_template_loop_add_to_cart', 10 );
}
add_action('init','remove_loop_button');
add_action('woocommerce_after_shop_loop_item','replace_add_to_cart');
function replace_add_to_cart() {
global $product;
$link = $product->get_permalink();
$text = _( 'See Items');
echo 'See Items';
}
`
It swaps out the button correctly on the main shop page but in the single post, the upsell also shows "see items" when I want it to say "add to cart" ... I have tried everything.
UPDATE: solved i think? it works, anyway :-)
// add add to cart back to upsell
' remove_action( 'woocommerce_after_single_product_summary', 'woocommerce_upsell_display', 15 );
add_action( 'woocommerce_after_single_product_summary', 'woocommerce_output_upsells', 15 );
if ( ! function_exists( 'woocommerce_output_upsells' ) ) {
if ( ! function_exists( 'woocommerce_output_upsells' ) ) {
function woocommerce_output_upsells() {
remove_action('woocommerce_after_shop_loop_item', 'replace_add_to_cart');
add_action('woocommerce_after_shop_loop_item', 'woocommerce_template_loop_add_to_cart');
}
}
} '