Osc*_* vs 4 php wordpress product woocommerce hook-woocommerce
我正在尝试在说明末尾插入一些文本。过滤器可以吗?
还是我需要通过儿童主题来做到这一点?一直试图找到描述的钩子,但只能找到一个简短的描述。例:
这是一个描述。
只需一些示例文本即可填写说明。
我想要的是注入“这是描述中的最后一行”,因此孔描述将如下所示。
这是一个描述。
只需一些示例文本即可填写说明。
这是描述中的最后一行
我在简短描述之前插入文本的代码是这样的:
add_filter( 'woocommerce_short_description', 'single_product_short_descriptions', 10, 1 );
function single_product_short_descriptions( $post_excerpt ){
global $product;
if ( is_single( $product->id ) )
$post_excerpt = '<div class="product-message"><p>' . __( "Article only available in the store.", "woocommerce" ) . '</p></div>' . $post_excerpt;
return $post_excerpt;
}
Run Code Online (Sandbox Code Playgroud)
您可以通过以下方式使用连接在the_content过滤器挂钩中的此自定义函数:
add_filter( 'the_content', 'customizing_woocommerce_description' );
function customizing_woocommerce_description( $content ) {
// Only for single product pages (woocommerce)
if ( is_product() ) {
// The custom content
$custom_content = '<p class="custom-content">' . __("This is the last line in the description", "woocommerce").'</p>';
// Inserting the custom content at the end
$content .= $custom_content;
}
return $content;
}
Run Code Online (Sandbox Code Playgroud)
代码进入您的活动子主题(或活动主题)的functions.php文件中。经过测试和工作。
添加 -强制产品描述为空(如果要显示此自定义文本):
add_filter( 'woocommerce_product_tabs', 'force_description_product_tabs' );
function force_description_product_tabs( $tabs ) {
$tabs['description'] = array(
'title' => __( 'Description', 'woocommerce' ),
'priority' => 10,
'callback' => 'woocommerce_product_description_tab',
);
return $tabs;
}
Run Code Online (Sandbox Code Playgroud)
代码进入您的活动子主题(或活动主题)的function.php文件中。经过测试和工作。
| 归档时间: |
|
| 查看次数: |
3106 次 |
| 最近记录: |