国产av日韩一区二区三区精品,成人性爱视频在线观看,国产,欧美,日韩,一区,www.成色av久久成人,2222eeee成人天堂

在WooCommerce中,將訂單詳細(xì)資訊元資料顯示在結(jié)帳確認(rèn)郵件和管理員訂單頁面中
P粉022140576
P粉022140576 2023-08-15 12:06:40
0
1
635
我們有一些被定義為“套件”的產(chǎn)品。它們是由其他產(chǎn)品組成的產(chǎn)品清單。定義套件的資料儲(chǔ)存在元資料數(shù)組中。我創(chuàng)建了一個(gè)鉤子,用於在產(chǎn)品頁面和購(gòu)物車中顯示元資料。我需要在「完成的訂單電子郵件」和「管理員訂單頁面」中做類似的事情,但我不知道如何做。這是我創(chuàng)建的鉤子: <pre class="brush:php;toolbar:false;">add_filter( 'bis_show_kit_meta', 'bis_show_kit_meta_contents', 10, 3 ); function bis_show_kit_meta_contents($productID) { global $wpdb; $postMeta = get_post_meta($productID,'',true); if ((isset($postMeta['bis_kit_id'])) and ($postMeta['bis_kit_id'][0] > 1)) { echo 'This is a Kit containing the following items:<br>'; echo $postMeta['bis_kit_type'][0].'<br>'; foreach($postMeta as $kititem) { foreach ($kititem as $value) { $newvalue = unserialize($value); if ($newvalue) { $newvalue2 = unserialize($newvalue); if($newvalue2['type']=="kititem"){ echo '<li>' .$newvalue2['quantity']. ' -> ' .chr(9). $newvalue2['name']. '</li>'; } } } } } }</pre> 當(dāng)前函數(shù)已經(jīng)鉤入了我的子主題中的對(duì)應(yīng)模板。 我不知道如何將類似的函數(shù)應(yīng)用於<code>customer-completed-email.php</code>文件,也不知道在管理員編輯訂單頁面中應(yīng)該在哪裡鉤入。 我在另一篇文章中找到了一些程式碼,看起來類似於我需要做的事情,但我無法弄清楚管理員訂單的修改在哪個(gè)文件中。 我找到的程式碼是: <pre class="brush:php;toolbar:false;">add_action('woocommerce_before_order_itemmeta','woocommerce_before_order_itemmeta',10,3); function woocommerce_before_order_itemmeta($item_id, $item, $product){ … }</pre> 非常感謝任何建議
P粉022140576
P粉022140576

全部回覆(1)
P粉736935587

WooCommerce已經(jīng)有了一堆鉤子,你可以在WooCommerce模板中使用它們,而不是添加自己的鉤子...

良好的開發(fā)規(guī)則是先使用現(xiàn)有的鉤子。如果沒有方便或可用的鉤子,那麼你可以透過子主題覆蓋WooCommerce模板。為什麼?因?yàn)槟0逵袝r(shí)會(huì)更新,然後你需要更新編輯過的模板,而鉤子則不需要。

對(duì)於「客戶完成訂單」通知,請(qǐng)使用woocommerce_order_item_meta_end動(dòng)作鉤子,如下所示:

// 將email_id設(shè)置為全局變量
add_action('woocommerce_email_before_order_table', 'set_email_id_as_a_global', 1, 4);
function set_email_id_as_a_global($order, $sent_to_admin, $plain_text, $email = null ){
    if ( $email ) {
        $GLOBALS['email_id_str'] = $email->id;
    }
}

// 在“客戶完成訂單”電子郵件通知中顯示自定義訂單項(xiàng)元數(shù)據(jù)
add_action( 'woocommerce_order_item_meta_end', 'custom_email_order_item_meta', 10, 2 );
function custom_email_order_item_meta( $item_id, $item ){
    // 獲取email ID全局變量
    $refGlobalsVar = $GLOBALS;
    $email_id = isset($refGlobalsVar['email_id_str']) ? $refGlobalsVar['email_id_str'] : null;

    // 僅適用于“客戶完成訂單”電子郵件通知
    if ( ! empty($email_id) && 'customer_completed_order' === $email_id ) {
        bis_show_kit_meta_contents( $item->get_product_id() );
    }
}

這將允許你只在「客戶完成訂單」通知中顯示自訂元資料。

或者,你可以將鉤子替換為具有相同函數(shù)變數(shù)參數(shù)的woocommerce_order_item_meta_start。

將程式碼放在你的子主題的functions.php檔案中或外掛中。

最新下載
更多>
網(wǎng)站特效
網(wǎng)站源碼
網(wǎng)站素材
前端模板