如何在Woocommerce 3中设置不存在的尺寸测量单位 [英] How to set a non existing dimensions measurement unit in Woocommerce 3

查看:153
本文介绍了如何在Woocommerce 3中设置不存在的尺寸测量单位的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在WooCommerce中,我想将厘米从ft更改为产品的高度,宽度和长度,

In WooCommerce I would like to change cm to ft my products display in height, width and length,

您可以在下面看到带有标题的产品:

You can see the products with their title below:

推荐答案

请尝试以下代码,这些代码将更改前端显示的尺寸单位:

Try the following code that will change the displayed dimensions unit in front end:

add_filter( 'woocommerce_format_dimensions', 'custom_dimention_unit', 20, 2 );
function custom_dimention_unit( $dimension_string, $dimensions ){
    $dimension_string = implode( ' x ', array_filter( array_map( 'wc_format_localized_decimal', $dimensions ) ) );

    if ( ! empty( $dimension_string ) ) {
        $dimension_string .= ' ' . __('ft');
    } else {
        $dimension_string = __( 'N/A', 'woocommerce' );
    }

    return $dimension_string;
}

代码进入您的活动子主题(或活动主题)的function.php文件中。

Code goes in function.php file of your active child theme (or active theme).

更新:将尺寸单位设置为 ft (英尺)全局(任何地方)

Update: Make dimension unit "ft" (feet) globally (everywhere)

Woocommerce维度可用单位为 m, cm, mm, in。和 yd。

Woocommerce dimension available units are "m", "cm", "mm", "in" and "yd".


但是 ft在Woocommerce>中不可用设置>产品>度量部分。

But "ft" is not available in the Woocommerce > Settings > Products > Mesurements section.

您可以执行以下操作:


  1. 将以下行粘贴到function.php文件中并保存:

  1. Paste the following line in your function.php file and save:

 update_option( 'woocommerce_dimension_unit', 'ft' );



  • 浏览网站的任何页面。

  • Browse any page of your web site.

    从function.php文件中删除或注释代码行并保存。

    Remove or comment the line of code from your function.php file and save.

    您也可以删除第一个代码段,因为它不再需要。

    You can also remove the first code snippet as it's not needed anymore.

    您已完成。

    您将得到类似的东西:

    和后端:


    有关信息,请在 Woocommerce >中更改尺寸单位设置> 产品

    For info, to change the dimensions unit in Woocommerce > Settings > Products:

    这篇关于如何在Woocommerce 3中设置不存在的尺寸测量单位的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

  • 查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆