网站建设时如何在WooCommerce中将产品添加到产品选项卡

发布时间:2023-10-08
如果您是插件开发人员,并且想要在woocommerce的产品选项卡中添加新的部分,请在本教程中密切关注,因为我将分享woocommerce黑客在产品选项卡中添加一个部分。
如何在woocommerce中将产品添加到产品选项卡让我们在“滑块”的产品选项卡中创建一个部分。
在产品选项卡中创建新的部分时,我们需要做的第一件事是使用woocommerce过滤器添加新的部分woocommerce_get_sections_products。
1
2
3
4
5
6
7
8
9
10
11
12
13
14
<?php
/**
* create the section beneath the products tab
**/
add_filter( ‘woocommerce_get_sections_products’, ‘wcslider_add_section’ );
function wcslider_add_section( $sections ) {
$sections[‘wcslider’] = __( ‘wc slider’, ‘text-domain’ );
return $sections;
}
现在打开产品选项卡,您将看到另一个部分为“wc滑块”。
让我们为本节创建一个表单。复制下面的代码并将其添加到您的functions.php文件中,以防您不想创建您的插件,否则将下面的代码放在您的插件文件中。
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
<?php
/**
* add settings to the specific section we created before
*/
add_filter( ‘woocommerce_get_settings_products’, ‘wcslider_all_settings’, 10, 2 );
function wcslider_all_settings( $settings, $current_section ) {
/**
* check the current section is what we want
**/
if ( $current_section == ‘wcslider’ ) {
?$settings_slider = array();
?// add title to the settings
?$settings_slider[] = array( ‘name’ => __( ‘wc slider settings’, ‘text-domain’ ), ‘type’ => ‘title’, ‘desc’ => __( ‘the following options are used to configure wc slider’, ‘text-domain’ ), ‘id’ => ‘wcslider’ );
?// add first checkbox option
?$settings_slider[] = array(
‘name’ => __( ‘auto-insert into single product page’, ‘text-domain’ ),
‘desc_tip’ => __( ‘this will automatically insert your slider into the single product page’, ‘text-domain’ ),
‘id’ => ‘wcslider_auto_insert’,
‘type’ => ‘checkbox’,
‘css’=> ‘min-width:300px;’,
‘desc’ => __( ‘enable auto-insert’, ‘text-domain’ ),
?);
?// add second text field option
?$settings_slider[] = array(
‘name’ => __( ‘slider title’, ‘text-domain’ ),
‘desc_tip’ => __( ‘this will add a title to your slider’, ‘text-domain’ ),
‘id’ => ‘wcslider_title’,
‘type’ => ‘text’,
‘desc’ => __( ‘any title you want can be added to your slider with this option!’, ‘text-domain’ ),
?);
$settings_slider[] = array( ‘type’ => ‘sectionend’, ‘id’ => ‘wcslider’ );
?return $settings_slider;
/**
* if not, return the standard settings
**/
} else {
?return $settings;
}
}
刷新管理页面,你会看到新的部分添加为“wc滑块”与基本选项。您可以根据您的要求更改或自定义上述代码。
上一个:电放与海运单选择有技巧
下一个:怎么样学好声乐 学好声乐方法

炸狼牙薯条做法图解 美食等着你
金锭子怎么做出来的 金锭子的做法
Wordfence Security Premium v​​7.5.3(更改日志)中的新增功能
去红血丝最快的方法 怎么去除去红血丝
洋葱黄瓜做法步骤 做洋葱炒黄瓜的技巧
应用程序登陆页面设计的最新趋势
现代水利风景资源景观设计有哪些发展对策?
城市桥梁工程钻孔灌注桩基础冲击钻成孔要求有哪些?
断路器应怎样选用? 跳闸后怎样检查处理?
2019年新规定——投标无需现金、保函,可采用承诺制!