php - 如何在 Woocommerce 3 中设置不存在的尺寸测量单位

标签 php wordpress woocommerce product dimensions

在 WooCommerce 中,我想将产品的高度、宽度和长度显示的厘米更改为英尺,

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

enter image description here

最佳答案

尝试以下代码来更改前端显示的尺寸单位:

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 文件中。


更新:全局(任何地方)使用尺寸单位“ft”(英尺)

Woocommerce 尺寸可用单位为“米”、“厘米”、“毫米”、“英寸”和“码”。

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

您可以执行以下操作:

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

     update_option( 'woocommerce_dimension_unit', 'ft' );
    
  2. 浏览您网站的任何页面。

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

  4. 您还可以删除第一个代码片段,因为它不再需要了。

  5. 你已经完成了。

你会得到类似的东西:

enter image description here

在后端:

enter image description here


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

enter image description here

关于php - 如何在 Woocommerce 3 中设置不存在的尺寸测量单位,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51304704/

相关文章:

php - MySQL - 如何选择表中的行,其中 id 值位于另一个表中的逗号分隔字段中?

css - Wordpress 类别页面不读取 CSS 文件

php - Wordpress XMLRPC API 发布(html)错误解析错误格式不正确

php - WooCommerce 在前端自定义日期后显示产品总销售额

php - 创建订单时将 WooCommerce 订单状态从处理中设置为待处理

wordpress - 没有 PayPal 帐户无法启用结帐

javascript - 如何通过单击一个复选框将多个复选框值附加到文本区域

php - 这个 PDO 脚本有什么问题

php - HTML - 表格内容对齐

php - 点击后隐藏提交按钮