If I have products without a price and all of them will be like that, I have 2 buttons.
Read more (cart icon) (instead of add to cart) and – Show details (doc icon)
Both linking to the product itself.
If there is no price in the product, how to hide the read more with the cart icon, center the show details and remove the | from the text?
Hey peterolle,
To remove the “Add to Cart” button that changes to “Read More” for products without a price and add the class single_button to the div avia_cart_buttons so the button is centered add this code to the end of your child theme functions.php file in Appearance ▸ Editor:
add_action('woocommerce_before_shop_loop_item', 'start_custom_output_buffer', 9);
function start_custom_output_buffer() {
ob_start();
}
add_action('woocommerce_after_shop_loop_item', 'modify_and_end_custom_output_buffer', 25);
function modify_and_end_custom_output_buffer() {
$output = ob_get_clean();
global $product;
if ('' === $product->get_price()) {
$output = str_replace("avia_cart_buttons", "avia_cart_buttons single_button", $output);
}
echo $output;
}
add_filter('woocommerce_loop_add_to_cart_link', 'custom_woocommerce_loop_add_to_cart_link', 10, 2);
function custom_woocommerce_loop_add_to_cart_link($button, $product) {
if ('' === $product->get_price()) {
return '';
}
return $button;
}
Please ensure to copy the code from the forum and not an email notification so the symbols are not converted.
This is the expected results:
Best regards,
Mike
Works like a charm Mike, Thank you!
Hi,
Glad we were able to help, if you have any further questions please create a new thread and we will gladly try to help you. Thank you for using Enfold.
Best regards,
Mike