久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

在 WooCommerce 格式的產品尺寸輸出中將長度重命名

Rename Length to Diameter in WooCommerce formatted product dimensions output(在 WooCommerce 格式的產品尺寸輸出中將長度重命名為直徑)
本文介紹了在 WooCommerce 格式的產品尺寸輸出中將長度重命名為直徑的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

我正在使用這個 woocommerce_format_dimensions 過濾器鉤子將顯示的尺寸格式從 1 x 1 x 1 in 替換為 1 L英寸 x 1 寬英寸 x 1 高英寸

I’m using this woocommerce_format_dimensions filter hook to replace displayed dimensions format from 1 x 1 x 1 in to 1 L in. x 1 W in. x 1 H in.

add_filter( 'woocommerce_format_dimensions', 'custom_formated_product_dimentions', 10, 2 );
function custom_formated_product_dimentions( $dimension_string, $dimensions ){
    if ( empty( $dimension_string ) )
        return __( 'N/A', 'woocommerce' );

    $dimensions = array_filter( array_map( 'wc_format_localized_decimal', $dimensions ) );
    foreach( $dimensions as $key => $dimention )
        $label_with_dimensions[$key] = $dimention . ' ' . strtoupper( substr($key, 0, 1) ) . ' ' . get_option( 'woocommerce_dimension_unit' ) . '.';

    return implode( ' x ',  $label_with_dimensions);
}

$dimensions 數組的

var_dump 如下所示:

var_dump of $dimensions array looks like this:

array(3) { ["length"]=> string(3) "104" ["width"]=> string(3) "136" ["height"]=> string(2) "53" }

我如何將 length" 鍵重命名為 diameter" 并將尺寸順序更改為相反,以便最終結果是:

How could I rename "length" key to "diameter" and change the order of dimensions to be in reverse, so that final result would be:

1 高英寸 x 1 寬英寸 x 1 深英寸

我嘗試使用 array_map 重命名 $dimensions 數組中的鍵,但無法使其正常工作.

I have tried to rename keys in $dimensions array using array_map, but couldn't manage to get it working.

推薦答案

2020 年更新

您只需要設置array keys/values 如您希望在函數中使用它們(重命名一個鍵并重新排序數組),這樣:

You just need to set the array keys/values as you want them in your function (renaming one key and reordering your array), this way:

add_filter( 'woocommerce_format_dimensions', 'Custom_formated_product_dimentions_with_labels', 10, 2 );
function Custom_formated_product_dimentions_with_labels( $dimension_string, $dimensions ){
    if ( empty( $dimension_string ) )
        return __( 'N/A', 'woocommerce' );

    // Set here your new array of dimensions based on existing keys/values
    $new_dimentions = array(
        'height' => $dimensions['height'],
        'width'  => $dimensions['width'],
        'diameter' => $dimensions['length']
    );

    $dimensions = array_filter( array_map( 'wc_format_localized_decimal', $new_dimentions ) );

    $label_with_dimensions = array();

    foreach( $dimensions as $key => $dimention ){
        $dimensions[$key] = ucfirst($key) . ' ' . $dimention . ' ' . get_option( 'woocommerce_dimension_unit' );
    }

    return implode( ' x ',  $dimensions) . '.';
}

代碼位于活動子主題(或主題)的 function.php 文件或任何插件文件中.

此代碼已在 WooCommerce 版本 3+ 上測試并有效

This code is tested on WooCommerce versions 3+ and works

這篇關于在 WooCommerce 格式的產品尺寸輸出中將長度重命名為直徑的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

相關文檔推薦

Cannot use #39;Object as class name as it is reserved Cake 2.2.x(不能使用 Object 作為類名,因為它是保留的 Cake 2.2.x)
Session is lost after an OAuth redirect(OAuth 重定向后會話丟失)
Pagination Sort in Cakephp 3.x(Cakephp 3.x 中的分頁排序)
CakePHP Shared core for multiple apps(CakePHP 多個應用程序的共享核心)
Login [ Auth-gt;identify() ] always false on CakePHP 3(在 CakePHP 3 上登錄 [ Auth-identify() ] 始終為 false)
Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 87 bytes)(致命錯誤:允許的內存大小為 134217728 字節已用盡(嘗試分配 87 字節))
主站蜘蛛池模板: 亚洲精品视频在线看 | 国产91精品网站 | 国产精品成人一区二区三区 | 成人精品视频免费 | 亚洲一区在线播放 | 精品一区二区三区入口 | 7799精品视频天天看 | 久久久久久久久精 | 国产激情免费视频 | 成人免费观看视频 | 欧美国产日韩在线观看成人 | 黄色毛片黄色毛片 | 中文一区| 日韩av免费在线观看 | 精品久久久久久亚洲综合网站 | 成人午夜电影在线观看 | 97人澡人人添人人爽欧美 | 亚洲欧美日韩电影 | 国产一级免费视频 | 毛片网站在线观看视频 | 国产精品久久精品 | 日韩精品| 在线观看av网站 | 99热播精品 | 亚洲激情在线观看 | 亚洲高清在线观看 | 欧美精品成人一区二区三区四区 | 开操网| 丝袜久久 | 欧美一级片 | 久久久精品一区 | 国产激情91久久精品导航 | 成人欧美一区二区三区黑人孕妇 | 九九色综合 | 中文字幕在线观看日韩 | 日日干天天干 | 自拍视频网 | 草久久久 | 久久国产亚洲 | 日本a∨视频 | av免费网站在线观看 |