Reputation: 369
This is what I have right now:
The text is not wrapped in the standard WooCommerce HTML.
This is what I wan't:
The text here is correctly wrapped in the standard WooCommerce HTML.
This is what I've done
I have added this to functions.php. I'm using Advanced Custom Fields, so I'm storing the contents (plain text) from that field in the $availability variable.
add_filter( 'woocommerce_get_availability', 'wcs_custom_get_availability', 1, 2);
function wcs_custom_get_availability( $availability, $_product ) {
// Change Out of Stock Text
if ( ! $_product->is_in_stock() ) {
$availability['availability'] = the_field("text_stock", "option");
}
return $availability;
}
The text is correctly displayed on the product page, but the HTML normally wrapping the stock information (found in WooCommerce/templates/single-product/stock.php) is not being output.
I have tried this:
add_filter( 'woocommerce_get_availability', 'wcs_custom_get_availability', 1, 2);
function wcs_custom_get_availability( $availability, $_product ) {
// Change Out of Stock Text
if ( ! $_product->is_in_stock() ) {
$availability['availability'] = '<p class="stock ' . esc_attr( $availability['class'] ) . '">' . the_field("text_stock", "option") . '</p>';
}
return $availability;
}
But that leaves me with this weird output:
My questions
Upvotes: 2
Views: 1749
Reputation: 26
Have you tried get_field("text_stock", "option")
instead of the_field("text_stock", "option")
?
Upvotes: 1