Это означает, что наиболее переносимым способом определения реализации методов классов шаблонов является определение их внутри определения класса шаблона.
template < typename ... >
class MyClass
{
int myMethod()
{
// Not just declaration. Add method implementation here
}
};
Ниже приведенный ниже код выведет ваш пользовательский текст сразу после краткого описания продукта с правильной категорией продукта и правильным продуктом (Yith) . Марка (так что для YITH WooCommerce Brands плагин) .
add_action( 'woocommerce_single_product_summary', 'custom_single_product_summary', 2 );
function custom_single_product_summary(){
global $product;
remove_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_excerpt', 20 );
add_action( 'woocommerce_single_product_summary', 'custom_single_excerpt', 20 );
}
function custom_single_excerpt(){
global $post, $product;
$short_description = apply_filters( 'woocommerce_short_description', $post->post_excerpt );
if ( ! $short_description )
return;
// Get product categories
$categories = wp_get_post_terms( $post->ID, 'product_cat', array( 'fields' => 'names' ) );
// Get product brands (NOTE: for Woocommerce brands plugin, the taxonomy is 'product_brand')
$brands = wp_get_post_terms( $post->ID, 'yith_product_brand', array( 'fields' => 'names' ) );
// The custom link
$custom_link = '<span style="text-decoration: underline;"><a href="https://power-light.nl/contact/">'.__("klantenservice").'</a></span>';
// The custom text
$custom_text = sprintf(__("Zoekt u naast de %s andere %s van dit merk? Bekijk dan eens de gehele collectie van %s. Powerlight is officieel dealer van %s. Heeft u een specifieke vraag over dit product? Neem gerust eens contact op met onze %s. Onze adviseurs staan graag voor u klaar."), $product->get_name(), reset($categories), reset($brands), reset($brands), $custom_link );
?>
<div class="woocommerce-product-details__short-description">
<?php echo $short_description . $custom_text; // WPCS: XSS ok. ?>
</div>
<?php
}
Код идет в файле function.php вашей активной дочерней темы (или активной темы). проверено и работает.
Если вы используете плагин Woocommerce Brands, вам придется заменить код
blockquote>'yith_product_brand'
на'product_brand'
. Вот и все.