Php 在选项卡中显示产品变化数据将禁用其他选项卡内容
因此,我试图在选项卡中显示变量的长度、宽度和高度。一切进展顺利,但它禁用了其他选项卡。本质上,它们返回时没有内容Php 在选项卡中显示产品变化数据将禁用其他选项卡内容,php,wordpress,object,woocommerce,Php,Wordpress,Object,Woocommerce,因此,我试图在选项卡中显示变量的长度、宽度和高度。一切进展顺利,但它禁用了其他选项卡。本质上,它们返回时没有内容 // Update descriptions tab add_filter( 'woocommerce_product_tabs', 'woo_custom_description_tab', 98 ); function woo_custom_description_tab( $tabs ) { $tabs['description']['callback'] = 'woo_cus
// Update descriptions tab
add_filter( 'woocommerce_product_tabs', 'woo_custom_description_tab', 98 );
function woo_custom_description_tab( $tabs ) {
$tabs['description']['callback'] = 'woo_custom_description_tab_content'; // Custom description callback
return $tabs;
}
function woo_custom_description_tab_content() {
global $product;
$available_variations = $product->get_available_variations();
$variation_id=$available_variations[0]['variation_id']; // Variation ID for first variation
$variable_product1 = new WC_Product_Variation( $variation_id );
echo '<strong>Product Box Dimensions</strong>';
if($variable_product1 ->get_length() != ''){
echo '<div class="dimensions">Length: ' . $variable_product1 ->get_length() . ' ' . get_option( 'woocommerce_dimension_unit' );
}
if($variable_product1 ->get_width() != ''){
echo '<div class="dimensions">Width: ' . $variable_product1 ->get_width() . ' ' . get_option( 'woocommerce_dimension_unit' );
}
if($variable_product1 ->get_height() != ''){
echo '<div class="dimensions">Height: ' . $variable_product1 ->get_height() . ' ' . get_option( 'woocommerce_dimension_unit' );
}
}
//更新描述选项卡
添加过滤器(“woocommerce\u product\u tab”、“woo\u custom\u description\u tab”,98);
功能自定义描述选项卡($tabs){
$tabs['description']['callback']='woo_custom_description_tab_content';//自定义描述回调
返回$tabs;
}
函数woo_自定义_说明_选项卡_内容(){
全球$产品;
$available_variations=$product->get_available_variations();
$variation\u id=$available\u variations[0]['variation\u id'];//第一个变体的变体id
$variable\u product1=新的WC\u产品变化($Variation\u id);
回音“产品盒尺寸”;
如果($variable_product1->get_length()!=“”){
回显“长度:”。$variable_product1->get_Length()。”。get_选项('woocommerce_dimension_unit');
}
如果($variable_product1->get_width()!=“”){
回显“宽度:”。$variable_product1->get_Width()。”。get_选项('woocommerce_dimension_unit');
}
如果($variable_product1->get_height()!=“”){
回显“高度:”。$variable_product1->get_Height()。”。get_选项('woocommerce_dimension_unit');
}
}
您的代码中有一些错误
add_filter( 'woocommerce_product_tabs', 'woo_custom_description_tab', 98 );
function woo_custom_description_tab( $tabs ) {
$tabs['description']['callback'] = 'woo_custom_description_tab_content'; // Custom description callback
return $tabs;
}
function woo_custom_description_tab_content() {
global $product;
if ( $product->is_type( 'variable' ) ) { // Before fetching variables, confirm that it is a variable product.
$available_variations = $product->get_available_variations();
$variation_id=$available_variations[0]['variation_id']; // Variation ID for first variation
$variable_product1 = new WC_Product_Variation( $variation_id );
echo '<strong>Product Box Dimensions</strong>';
if($variable_product1 ->get_length() != ''){
echo '<div class="dimensions">Length: ' . $variable_product1 ->get_length() . ' ' . get_option( 'woocommerce_dimension_unit' );
}
if($variable_product1 ->get_width() != ''){
echo '<div class="dimensions">Width: ' . $variable_product1 ->get_width() . ' ' . get_option( 'woocommerce_dimension_unit' );
}
if($variable_product1 ->get_height() != ''){
echo '<div class="dimensions">Height: ' . $variable_product1 ->get_height() . ' ' . get_option( 'woocommerce_dimension_unit' );
}
}
}
add_filter('woocommerce_product_tabs','woo_custom_description_tab',98);
功能自定义描述选项卡($tabs){
$tabs['description']['callback']='woo_custom_description_tab_content';//自定义描述回调
返回$tabs;
}
函数woo_自定义_说明_选项卡_内容(){
全球$产品;
如果($product->是_类型('variable')){//在获取变量之前,请确认它是一个变量产品。
$available_variations=$product->get_available_variations();
$variation\u id=$available\u variations[0]['variation\u id'];//第一个变体的变体id
$variable\u product1=新的WC\u产品变化($Variation\u id);
回音“产品盒尺寸”;
如果($variable_product1->get_length()!=“”){
回显“长度:”。$variable_product1->get_Length()。”。get_选项('woocommerce_dimension_unit');
}
如果($variable_product1->get_width()!=“”){
回显“宽度:”。$variable_product1->get_Width()。”。get_选项('woocommerce_dimension_unit');
}
如果($variable_product1->get_height()!=“”){
回显“高度:”。$variable_product1->get_Height()。”。get_选项('woocommerce_dimension_unit');
}
}
}
要添加新的自定义选项卡,请使用下面的代码段&更新代码
add_filter( 'woocommerce_product_tabs', 'woo_new_product_tab' );
function woo_new_product_tab( $tabs ) {
// Adds the new tab
$tabs['test_tab'] = array(
'title' => __( 'New Product Tab', 'woocommerce' ),
'priority' => 50,
'callback' => 'woo_new_product_tab_content'
);
return $tabs;
}
function woo_new_product_tab_content() {
// The new tab content
echo '<h2>New Product Tab</h2>';
echo '<p>Here\'s your new product tab.</p>';
}
add_filter('woocommerce_product_tabs'、'woo_new_product_tab');
功能woo_新产品_选项卡($tabs){
//添加新选项卡
$tabs['test_tab']=数组(
'title'=>uuuu('newproducttab','woocommerce'),
“优先级”=>50,
“回调”=>“求购新产品”选项卡“内容”
);
返回$tabs;
}
功能woo_新产品_选项卡_内容(){
//新的标签内容
echo“新产品标签”;
echo'这是您的新产品标签。;
}
在WooCommerce文档页面中提供了更多关于产品选项卡的调整
您的代码中有一些错误
add_filter( 'woocommerce_product_tabs', 'woo_custom_description_tab', 98 );
function woo_custom_description_tab( $tabs ) {
$tabs['description']['callback'] = 'woo_custom_description_tab_content'; // Custom description callback
return $tabs;
}
function woo_custom_description_tab_content() {
global $product;
if ( $product->is_type( 'variable' ) ) { // Before fetching variables, confirm that it is a variable product.
$available_variations = $product->get_available_variations();
$variation_id=$available_variations[0]['variation_id']; // Variation ID for first variation
$variable_product1 = new WC_Product_Variation( $variation_id );
echo '<strong>Product Box Dimensions</strong>';
if($variable_product1 ->get_length() != ''){
echo '<div class="dimensions">Length: ' . $variable_product1 ->get_length() . ' ' . get_option( 'woocommerce_dimension_unit' );
}
if($variable_product1 ->get_width() != ''){
echo '<div class="dimensions">Width: ' . $variable_product1 ->get_width() . ' ' . get_option( 'woocommerce_dimension_unit' );
}
if($variable_product1 ->get_height() != ''){
echo '<div class="dimensions">Height: ' . $variable_product1 ->get_height() . ' ' . get_option( 'woocommerce_dimension_unit' );
}
}
}
add_filter('woocommerce_product_tabs','woo_custom_description_tab',98);
功能自定义描述选项卡($tabs){
$tabs['description']['callback']='woo_custom_description_tab_content';//自定义描述回调
返回$tabs;
}
函数woo_自定义_说明_选项卡_内容(){
全球$产品;
如果($product->是_类型('variable')){//在获取变量之前,请确认它是一个变量产品。
$available_variations=$product->get_available_variations();
$variation\u id=$available\u variations[0]['variation\u id'];//第一个变体的变体id
$variable\u product1=新的WC\u产品变化($Variation\u id);
回音“产品盒尺寸”;
如果($variable_product1->get_length()!=“”){
回显“长度:”。$variable_product1->get_Length()。”。get_选项('woocommerce_dimension_unit');
}
如果($variable_product1->get_width()!=“”){
回显“宽度:”。$variable_product1->get_Width()。”。get_选项('woocommerce_dimension_unit');
}
如果($variable_product1->get_height()!=“”){
回显“高度:”。$variable_product1->get_Height()。”。get_选项('woocommerce_dimension_unit');
}
}
}
要添加新的自定义选项卡,请使用下面的代码段&更新代码
add_filter( 'woocommerce_product_tabs', 'woo_new_product_tab' );
function woo_new_product_tab( $tabs ) {
// Adds the new tab
$tabs['test_tab'] = array(
'title' => __( 'New Product Tab', 'woocommerce' ),
'priority' => 50,
'callback' => 'woo_new_product_tab_content'
);
return $tabs;
}
function woo_new_product_tab_content() {
// The new tab content
echo '<h2>New Product Tab</h2>';
echo '<p>Here\'s your new product tab.</p>';
}
add_filter('woocommerce_product_tabs'、'woo_new_product_tab');
功能woo_新产品_选项卡($tabs){
//添加新选项卡
$tabs['test_tab']=数组(
'title'=>uuuu('newproducttab','woocommerce'),
“优先级”=>50,
“回调”=>“求购新产品”选项卡“内容”
);
返回$tabs;
}
功能woo_新产品_选项卡_内容(){
//新的标签内容
echo“新产品标签”;
echo'这是您的新产品标签。;
}
在WooCommerce文档页面中提供了更多关于产品选项卡的调整