-
-
Save DeveloperWil/7a88086d8eea1be94dfe4f391b5201a1 to your computer and use it in GitHub Desktop.
Is there also a way to make an exception to the out of stock code below that I'm using to show an item that's out of stock?
/*
- replace read more buttons for out of stock items in woo 2.5.1
**/
if (!function_exists('woocommerce_template_loop_add_to_cart')) {
function woocommerce_template_loop_add_to_cart( $args = array() ) {
global $product;
if (!$product->is_in_stock()) {
echo 'Out of Stock';
}
else
{
$defaults = array(
'quantity' => 1,
'class' => implode( ' ', array_filter( array(
'button',
'product_type_' . $product->product_type,
$product->is_purchasable() && $product->is_in_stock() ? 'add_to_cart_button' : '',
$product->supports( 'ajax_add_to_cart' ) ? 'ajax_add_to_cart' : ''
) ) )
);
$args = apply_filters( 'woocommerce_loop_add_to_cart_args', wp_parse_args( $args, $defaults ), $product );
wc_get_template( 'loop/add-to-cart.php', $args );
}
}
}
Is there also a way to make an exception to the out of stock code below that I'm using to show an item that's out of stock?
/*
- replace read more buttons for out of stock items in woo 2.5.1
**/
if (!function_exists('woocommerce_template_loop_add_to_cart')) {
function woocommerce_template_loop_add_to_cart( $args = array() ) {
global $product;
if (!$product->is_in_stock()) {
echo 'Out of Stock';
}
else
{
$defaults = array(
'quantity' => 1,
'class' => implode( ' ', array_filter( array(
'button',
'product_type_' . $product->product_type,
$product->is_purchasable() && $product->is_in_stock() ? 'add_to_cart_button' : '',
$product->supports( 'ajax_add_to_cart' ) ? 'ajax_add_to_cart' : ''
) ) )
);
$args = apply_filters( 'woocommerce_loop_add_to_cart_args', wp_parse_args( $args, $defaults ), $product );
wc_get_template( 'loop/add-to-cart.php', $args );
}
}
}
On line 37 replace .'/contact' and the rest of the line with
. $product->get_permalink();
Is there also a way to make an exception to the out of stock code below that I'm using to show an item that's out of stock?
/*
- replace read more buttons for out of stock items in woo 2.5.1
**/
if (!function_exists('woocommerce_template_loop_add_to_cart')) {
function woocommerce_template_loop_add_to_cart( $args = array() ) {
global $product;
if (!$product->is_in_stock()) {
echo 'Out of Stock';
}
else
{
$defaults = array(
'quantity' => 1,
'class' => implode( ' ', array_filter( array(
'button',
'product_type_' . $product->product_type,
$product->is_purchasable() && $product->is_in_stock() ? 'add_to_cart_button' : '',
$product->supports( 'ajax_add_to_cart' ) ? 'ajax_add_to_cart' : ''
) ) )
);
$args = apply_filters( 'woocommerce_loop_add_to_cart_args', wp_parse_args( $args, $defaults ), $product );
wc_get_template( 'loop/add-to-cart.php', $args );
}
}
}
Yep, create an array of exempt products IDs like $exempt_products = [109, 596, 700, 1014];
Then modify your line: if (!$product->is_in_stock()) {
to: if (!$product->is_in_stock() && ( !in_array( $product->get_id(), $exempt_products ) ) ) {
That should work.
How can we edit the code to make the button "Reserve Item" go to the actual product page rather than contact?