0

I'm modifying a theme for WordPress and i can't find a solution for:

   1. How can I delete the WooCommerce product image inside the gallery? Because this image is added automatically and cannot be deleted.

IMAGES: https://i.stack.imgur.com/ZusX5.jpg

   2. How can I deactivate the cart page, is it possible? I'm only interested in the Checkout page. I've been looking at some codes but they don't allow to select more than 2 products.

Greetings to all who comment, I hope these issues can help more people in the future.

Martín
  • 11
  • 5

1 Answers1

0

Redirect to Checkout when a Product has been added to the Cart


Second question answer: How can I deactivate the cart page, is it possible? I'm only interested in the Checkout page. I've been looking at some codes but they don't allow to select more than 2 products.

Step 1.

// Disable AJAX add to cart buttons
First of all, we have to do some small configurations in WooCommerce Settings – Uncheck the “Enable AJAX add to cart buttons on archives” checkbox.

Step 2.

// Change text on add to cart buttons
/*
 * Change button text on Product Archives
 */
add_filter( 'woocommerce_loop_add_to_cart_link', 'nik_add_to_cart_text_1' );

function nik_add_to_cart_text_1( $add_to_cart_html ) {
    return str_replace( 'Add to cart', 'Buy now', $add_to_cart_html );
}

/*
 * Change button text on product pages
 */
add_filter( 'woocommerce_product_single_add_to_cart_text', 'nik_add_to_cart_text_2' );

function nik_add_to_cart_text_2( $product ){
    return 'Buy now';
}

I decided that str_replace() for this situation is the most simple and easy solution, but if you do not want to use it, you can replace the first part of the code with this one:

/*
 * Change button text on Product Archives
 */
add_filter( 'woocommerce_product_add_to_cart_text', 'nik_add_to_cart_text_1', 10, 2 );

function nik_add_to_cart_text_1( $text, $product ){
    return $product->is_purchasable() && $product->is_in_stock() ? 'Buy Now' : 'Read more';
}

Step 3.

// Redirect to Checkout Page
add_filter( 'woocommerce_add_to_cart_redirect', 'nik_skip_cart_redirect_checkout' );

function nik_skip_cart_redirect_checkout( $url ) {
    return wc_get_checkout_url();
}

Step 4.

// Remove “The product has been added to your cart” message
add_filter( 'wc_add_to_cart_message_html', 'nik_remove_add_to_cart_message' );

function nik_remove_add_to_cart_message( $message ){
    return '';
}
  • Thanks for comment @Nikhil but now I can only select 1-in-1 products. Also if I make certain combinations cart page appears again :( a question, how do I delete the message that says "PRODUCT" removed. Undo? – Martín Dec 11 '19 at 20:58
  • hide message. "PRODUCT" removed, undo? checkout the link, https://stackoverflow.com/questions/38189428/woocommerce-unset-product-removed-notice-on-cart-page Hope this helps you. – Nikhil Warvatkar Dec 12 '19 at 02:53
  • if you want to add multiple products and the checkout, you must enable the ajax add to cart button. And don't use step 3 "Redirect to Checkout Page". And you have to override some of the woocommerce files. How have to create a button with a checkout link near the "add to cart" button. When "add to cart" is selected, display none the add to cart button after ajax complete and display block the checkout button. This way you can achieve direct checkout also. – Nikhil Warvatkar Dec 12 '19 at 03:08