I have two questions about my products/ product pages. I attached a photo below for reference.
Also my website is crisisequipped.com (in case that helps in any way).
I’m wondering if in place of the “Related Products” text, I could have it say “Top-Selling Products” and configure the results to consistently show the same 4 top-selling products on my site?
When you hover the mouse over the product, a button pops up that says “Add to Cart”. I’m wondering if this can say “View Product” instead and for the link to direct them to that product page, not the cart?
Please install and activate the child theme and login through FTP then edit the functions.php then add this code:
/**
* Remove related products output
*/
remove_action( 'woocommerce_after_single_product_summary', 'woocommerce_output_related_products', 20 );
add_action( 'woocommerce_after_single_product_summary', 'add_top_selling_products', 50 );
function add_top_selling_products() {
echo '<h2>This is my custom action function</h2>';
echo do_shortcode('[best_selling_products]');
}
Add this code to the functions.php as well:
// Replace add to cart button by a linked button to the product in Shop and archives pages
add_filter( 'woocommerce_loop_add_to_cart_link', 'replace_loop_add_to_cart_button', 10, 2 );
function replace_loop_add_to_cart_button( $button, $product ) {
// Not needed for variable products
if( $product->is_type( 'variable' ) ) return $button;
// Button text here
$button_text = __( "View product", "woocommerce" );
return '<a class="button" href="' . $product->get_permalink() . '">' . $button_text . '</a>';
}
Kindly note that since this is a custom code that changes the default behavior/display of the theme, you will be responsible to maintain or update the code in case you require further changes or if the code stops working in future updates. If you are uncertain how to proceed, it would be best to get in touch with a developer.
The thought of having to update the code in the future scares me a bit … so instead of changing all the code, I’m wondering if there’s a way to only change the “Related Products” text to “Top-Selling Products”?