I am trying to create an automatic text in the description of the WooCommerce articles and put \"article only available in the store.\"
I thought about putting it in
So you can use it this way:
add_filter( 'woocommerce_short_description', 'single_product_short_description', 10, 1 );
function single_product_short_description( $post_excerpt ){
global $product;
$product_id = method_exists( $product, 'get_id' ) ? $product->get_id() : $product->id;
if ( is_single( $product_id ) )
$post_excerpt = '' . __( "article only available in the store.", "woocommerce" ) . '
';
return $post_excerpt;
}
Normally this code will override existing short description text in single product pages, if this short description exist…
(update) - Related to your comment
If you want to display this without overriding the excerpt (short description), you can add it before this way:
add_filter( 'woocommerce_short_description', 'single_product_short_description', 10, 1 );
function single_product_short_description( $post_excerpt ){
global $product;
$product_id = method_exists( $product, 'get_id' ) ? $product->get_id() : $product->id;
if ( is_single( $product_id ) )
$post_excerpt = '
' . $post_excerpt;
return $post_excerpt;
}
So you will get your message before, and after (if short description exist) the short description…
You can style it targeting in your active theme style.css
file the class selector .product-message
, for example this way:
.product-message {
background-color:#eee;
border: solid 1px #666;
padding: 10px;
}
You will need to write your own style rules to get it as you want.