Attempting to Add a 2nd Checkbox in the woocommerce Checkout Page
-
When we attempt to add a second Policy button and want to add a Rental Agreement checkbox that’s required (1st is Terms and Conditions).
We added some code but something crashed and we don’t know if it’s my new box.
Here’s the error: Fatal error: Cannot redeclare woo_custom_cart_button_text() (previously declared in /home/dfraser/public_html/wp-content/themes/bellevue/functions.php:44) in /home/dfraser/public_html/wp-content/themes/bellevue/functions.php on line 54.
Here’s the website that’s down right now: https://www.HalfMoonCabin.com
Here’s the code. Half was already in function.php and the rest we added.
<?php
/**
* Roots includes
*/
include( get_template_directory() . ‘/lib/init.php’); // Initial theme setup and constants
include( get_template_directory() . ‘/lib/wrapper.php’); // Theme wrapper class
include( get_template_directory() . ‘/lib/config.php’); // Configuration
include( get_template_directory() . ‘/lib/activation.php’); // Theme activation
include( get_template_directory() . ‘/lib/titles.php’); // Page titles
include( get_template_directory() . ‘/lib/cleanup.php’); // Cleanup
include( get_template_directory() . ‘/lib/nav.php’); // Custom nav modifications
include( get_template_directory() . ‘/lib/comments.php’); // Custom comments modifications
include( get_template_directory() . ‘/lib/widgets.php’); // Sidebars and widgets
include( get_template_directory() . ‘/lib/scripts.php’); // Scripts and stylesheets
include( get_template_directory() . ‘/lib/custom.php’); // Custom functions// THEMOVATION CUSTOMIZATION
include( get_template_directory() . ‘/lib/class-tgm-plugin-activation.php’); // Bundled Plugins// Activate Option Tree in the theme rather than as a plugin
add_filter( ‘ot_theme_mode’, ‘__return_true’ );
add_filter( ‘ot_show_pages’, ‘__return_false’ );
//add_filter( ‘ot_show_pages’, ‘__return_true’ );// Don’t use Option Tree Meta Boxes for Pages.
if(isset($_GET[‘post’]) && $_GET[‘post’] > “”){
if(get_post_type($_GET[‘post’]) == ‘page’){
add_filter(‘ot_meta_boxes’, ‘__return_false’ );
}
}include_once(get_template_directory() . ‘/option-tree/ot-loader.php’);
include_once(get_template_directory() . ‘/option-tree/theme-options.php’ ); // LOAD THEME SETTINGS
include_once(get_template_directory() . ‘/option-tree/theme-options-defaults.php’); // LOAD OT DEFAULTS
include_once(get_template_directory() . ‘/register-meta-boxes.php’); // LOAD OT DEFAULTS// END Option Tree
add_filter( ‘woocommerce_product_single_add_to_cart_text’, ‘woo_custom_cart_button_text’ ); // 2.1 +
function woo_custom_cart_button_text() {
return __( ‘My Button Text’, ‘woocommerce’ ); /** LINE 44 **/
}
add_filter( ‘add_to_cart_text’, ‘woo_custom_cart_button_text’ ); // < 2.1
function woo_custom_cart_button_text() {
return __( ‘Secure Checkout’, ‘woocommerce’ ); /**LINE 54 **/
}
/**
* Add checkbox field to the checkout
**/
add_action(‘woocommerce_after_order_notes’, ‘my_custom_checkout_field’);function my_custom_checkout_field( $checkout ) {
echo ‘<div id=”my-new-field”><h3>’.__(‘My Checkbox: ‘).'</h3>’;
woocommerce_form_field( ‘my_checkbox’, array(
‘type’ => ‘checkbox’,
‘class’ => array(‘input-checkbox’),
‘label’ => __(‘I have read the Rental Agreement.’),
‘required’ => true,
), $checkout->get_value( ‘my_checkbox’ ));echo ‘</div>’;
}/**
* Process the checkout
**/
add_action(‘woocommerce_checkout_process’, ‘my_custom_checkout_field_process’);function my_custom_checkout_field_process() {
global $woocommerce;// Check if set, if its not set add an error.
if (!$_POST[‘my_checkbox’])
$woocommerce->add_error( __(‘Please agree to my checkbox.’) );
}/**
* Update the order meta with field value
**/
add_action(‘woocommerce_checkout_update_order_meta’, ‘my_custom_checkout_field_update_order_meta’);function my_custom_checkout_field_update_order_meta( $order_id ) {
if ($_POST[‘my_checkbox’]) update_post_meta( $order_id, ‘My Checkbox’, esc_attr($_POST[‘my_checkbox’]));
}As you read the Error, it’s says Line 44 is conflicting with line 54.
My code starts with: * Add checkbox field to the checkout. But if the problem isn’t the new code what is it? I REMARKed line 44 and 54.
- The topic ‘Attempting to Add a 2nd Checkbox in the woocommerce Checkout Page’ is closed to new replies.