我想快速更改ubercart表單數據(我想刪除購物車中產品節點的鏈接)。我找到了一個解決方案,通過創建一個新模塊(下面的鏈接和代碼)來實現hook_form_alter()。hook_form_alter - 模塊或template.php
我的問題是,我必須創建一個新的模塊,或者我可以只添加此功能到我的主題的template.php文件?我嘗試了以後,但我無法得到它的工作(我將函數重命名爲NameOfMyTheme_form_alter)。如果我遇到一些我想改變的代碼,你怎麼知道你是否應該創建一個模塊或者改變你的主題?)。
http://www.ubercart.org/forum/support/2298/remove_product_links_shopping_cart
function your_module_form_alter(&$form, &$form_state, $form_id) {
if($form_id == 'uc_cart_view_form') {
foreach($form['items'] as $key => $item) {
if(!empty($item['desc']['#value'])) {
$form['items'][$key]['desc']['#value'] = strip_tags($item['desc']['#value']);
}
}
}
}
感謝克萊夫+1呼籲的主題。出於某種原因,themeName_form_alter不會被調用(我在函數頂部添加了一個dd()來檢查)。最後,我重寫了生成購物車HTML的themeName_uc_cart_view_form()。 – spiderplant0 2012-08-10 09:23:58
嗨克萊夫,我已經在我的自定義模塊中嘗試過hook_form_alter。但它不起作用。這個問題有什麼特別的原因嗎? – Ananth 2014-05-07 12:09:46