Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Author Mike Jolley (a11n)

    (@mikejolley)

    Why not have one policy checkbox, but link to a page containing all policies? Not sure why you’d need several. Anyhow, if you do, it would require customisation or perhaps the checkout field editor extension.

    I have a similar issue. Not sure how to open a thread.

    Any how, we have a Policy button and want to add a Rental Agreement checkbox that’s required.

    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: http://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.

    Plugin Author Mike Jolley (a11n)

    (@mikejolley)

    screenprintr code should be wrapped in backticks (`) and really your own thread should be started (support tab, new topic form is at the bottom).

    Your error is because you’re using the function name ‘woo_custom_cart_button_text’ twice anyhow. Thats not allowed. Combine the functions or rename one.

    If you need a dev, jobs.wordpress.net

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Adding SEVERAL Policy checkboxes to Checkout page’ is closed to new replies.