自动文本 woocommerce_short_description 挂钩
Auto text woocommerce_short_description hook
我正在尝试在 WooCommerce 文章的描述中创建一个自动文本并将 "article only available in the store."
我考虑过将它放在这样的函数中:
add_filter ('woocommerce_short_description', 'in_single_product', 10, 2);
function in_single_product () {
echo '<p> my-text-here </ p>';
}
但是文本没有出现在前端。只有当我把文本放在后端时才会出现。
有人知道为什么会这样吗?
对单个产品页面使用条件,return 函数变量而不是回显它。
这将替换单个产品页面中的 post 摘录:
add_filter( 'woocommerce_short_description', 'single_product_short_description', 10, 1 );
function single_product_short_description( $post_excerpt ){
global $product;
// compatibility with WC +3
$product_id = method_exists( $product, 'get_id' ) ? $product->get_id() : $product->id;
if ( is_single( $product_id ) )
$post_excerpt = '<p class="some-class">' . __( "my-text-here", "your_theme_slug" ) . '</ p>';
return $post_excerpt;
}
最好将您的文本添加到 gettex 中进行翻译(将 "your_theme_slug"
替换为您的主题...
参考:How to use different short description in shop page and in product page in woocommerce
写作add_filter
的正确语法
// Define the my_editor_content
function my_editor_content( $post_excerpt ) {
// make filter magic happen here...
return $post_excerpt;
};
// add the filter
add_filter( 'woocommerce_short_description','my_editor_content',10, 1 );
好吧,您可以在子主题的 functions.php 中使用此代码。
function my_editor_content( $post_excerpt ) {
$content = 'The default text, imposed by me, needs to be here in every product.';
return $content.'<br>'.$post_excerpt;
}
add_filter('woocommerce_short_description', 'my_editor_content', 10, 1);
希望对您有所帮助。
我正在尝试在 WooCommerce 文章的描述中创建一个自动文本并将 "article only available in the store."
我考虑过将它放在这样的函数中:
add_filter ('woocommerce_short_description', 'in_single_product', 10, 2);
function in_single_product () {
echo '<p> my-text-here </ p>';
}
但是文本没有出现在前端。只有当我把文本放在后端时才会出现。
有人知道为什么会这样吗?
对单个产品页面使用条件,return 函数变量而不是回显它。
这将替换单个产品页面中的 post 摘录:
add_filter( 'woocommerce_short_description', 'single_product_short_description', 10, 1 );
function single_product_short_description( $post_excerpt ){
global $product;
// compatibility with WC +3
$product_id = method_exists( $product, 'get_id' ) ? $product->get_id() : $product->id;
if ( is_single( $product_id ) )
$post_excerpt = '<p class="some-class">' . __( "my-text-here", "your_theme_slug" ) . '</ p>';
return $post_excerpt;
}
最好将您的文本添加到 gettex 中进行翻译(将 "your_theme_slug"
替换为您的主题...
参考:How to use different short description in shop page and in product page in woocommerce
写作add_filter
的正确语法// Define the my_editor_content
function my_editor_content( $post_excerpt ) {
// make filter magic happen here...
return $post_excerpt;
};
// add the filter
add_filter( 'woocommerce_short_description','my_editor_content',10, 1 );
好吧,您可以在子主题的 functions.php 中使用此代码。
function my_editor_content( $post_excerpt ) {
$content = 'The default text, imposed by me, needs to be here in every product.';
return $content.'<br>'.$post_excerpt;
}
add_filter('woocommerce_short_description', 'my_editor_content', 10, 1);
希望对您有所帮助。