最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

php - Trying to place a custom field after the total section in the checkout page in woocommerce

programmeradmin0浏览0评论

This code correctly works but does not place the custom field where I want it. In the add_action I would like to use woocommerce_review_order_after_order_total as the location attribute to place it on the page. I got the hook name from this visual guide / However this hook breaks my code and gives me the following php error.

Fatal error: Uncaught Error: Call to a member function get_value() on string in /Users/anderskitson/Local Sites/river-cafe/app/public/wp-content/themes/salient-child/functions.php on line 96

Hopefully someone can give me hand. Thanks

/**

* Add custom field to the checkout page

*/

add_action('woocommerce_after_order_notes', 'custom_checkout_field');

/* add_action('woocommerce_review_order_after_order_total', 'custom_checkout_field');*/
/* ^ This is the code that is breaking */ 

function custom_checkout_field($checkout)

{

echo '<div id="custom_checkout_field"><h2>' . __('New Heading') . '</h2>';

woocommerce_form_field('custom_field_name', array(

'type' => 'text',

'class' => array(

'my-field-class form-row-wide'

) ,

'label' => __('Custom Additional Field') ,

'placeholder' => __('New Custom Field') ,

) ,

$checkout->get_value('custom_field_name'));

echo '</div>';

}
发布评论

评论列表(0)

  1. 暂无评论