在订购单中键入时强制自动替换字母

时间:2019-03-01 15:51:08

标签: wordpress woocommerce

有人对如何自动替换woocommerce订单中的字母有任何想法!基本上,当有人输入希腊语时,我需要自动替换那些希腊字母!

1 个答案:

答案 0 :(得分:1)

我认为您将必须使用此钩子来获取新创建的订单:

add_action( 'woocommerce_new_order', 'convert_greeklish_for_wc_order',  1, 1  );
function create_invoice_for_wc_order() {
   function create_invoice_for_wc_order( $order_id ) { 
    // get order details data...
    $order = new WC_Order( $order_id );

    // Here goes the code to get all the fields

    // Convert fields to greek

    // Set new fields values
   }; 
}

并修改此代码以将greeklisk转换为希腊:

<?php

function greeklish($new_text){

        $greek_len   = array('α','ά','Ά','Α','β','Β','γ', 'Γ', 'δ','Δ','ε','έ','Ε','Έ','ζ','Ζ','η','ή','Η','θ','Θ','ι','ί','ϊ','ΐ','Ι','Ί', 'κ','Κ','λ','Λ','μ','Μ','ν','Ν','ξ','Ξ','ο','ό','Ο','Ό','π','Π','ρ','Ρ','σ','ς', 'Σ','τ','Τ','υ','ύ','Υ','Ύ','φ','Φ','χ','Χ','ψ','Ψ','ω','ώ','Ω','Ώ',' ',"'","'",',');

        $english_len = array('a', 'a','A','A','b','B','g','G','d','D','e','e','E','E','z','Z','i','i','I','th','Th', 'i','i','i','i','I','I','k','K','l','L','m','M','n','N','x','X','o','o','O','O','p','P' ,'r','R','s','s','S','t','T','u','u','Y','Y','f','F','ch','Ch','ps','Ps','o','o','O','O',' ','',' ',' ');
        $new_text  = str_replace($greek_len,$english_len,$new_text);
        return $new_text;
    }

    $conv = greeklish("Το κείμενο σου εδώ!");

    echo $conv; #To keimeno sou edo!

?>