How to change a WooCommerce add to cart button in Product List loop but depending on the product type, like for example:
- For products with Variations I want a text in add to cart button to: "Show product"
- For Simple prodcuts "Show product"
- For products Out of stock: "Unavailable"
I tried with below code but doesn't work:
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 ) {
$button_text = __( "Out of stock", "woocommerce" );
return '<a class="view-product" href="' . $product->get_permalink() . '">' . $button_text . '</a>';
if( ! $product->managing_stock() && ! $product->is_in_stock() ) {
return $button;
}
if( $product->is_type( 'variable' ) ) return $button;
}