Skip to content

Instantly share code, notes, and snippets.

@BurlesonBrad
Created March 24, 2016 12:54
Show Gist options
  • Save BurlesonBrad/bf5bc4ef47203d9b5b9e to your computer and use it in GitHub Desktop.
Save BurlesonBrad/bf5bc4ef47203d9b5b9e to your computer and use it in GitHub Desktop.
Add TOS Condition for Wholesalers
<?php
/**
* Checkout terms and conditions checkbox
*
* @author WooThemes
* @package WooCommerce/Templates
* @version 2.5.0
*/
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
if ( wc_get_page_id( 'terms' ) > 0 && apply_filters( 'woocommerce_checkout_show_terms', true ) ) : ?>
<?php do_action( 'woocommerce_checkout_before_terms_and_conditions' ); ?>
<p class="form-row terms wc-terms-and-conditions">
<input type="checkbox" class="input-checkbox" name="terms" <?php checked( apply_filters( 'woocommerce_terms_is_checked_default', isset( $_POST['terms'] ) ), true ); ?> id="terms" />
<label for="terms" class="checkbox"><?php printf( __( 'I&rsquo;ve read and accept the <a href="%s" target="_blank">terms &amp; conditions</a>', 'woocommerce' ), esc_url( wc_get_page_permalink( 'terms' ) ) ); ?> <span class="required">*</span></label>
<input type="hidden" name="terms-field" value="1" />
</p>
<?php do_action( 'woocommerce_checkout_after_terms_and_conditions' ); ?>
<?php endif; ?>
@BurlesonBrad
Copy link
Author

/** Example Code from wholesale Site Plugin **/

global $current_user;
if (isset($current_user) && class_exists('WWP_Wholesale_Roles')) {
    $wwp_wholesale_roles = WWP_Wholesale_Roles::getInstance();
    $wwp_wholesale_role = $wwp_wholesale_roles->getUserWholesaleRole();

    if (!empty($wwp_wholesale_role)) {
        // Do something for wholesale customer
        echo "is wholesale customer";
    }
}

What we need is for line 17 above to echo out a different page when a wholesaler is checking out

<label for="terms" class="checkbox"><?php printf( __( 'I&rsquo;ve read and accept the <a href="%s" target="_blank">terms &amp;
 conditions</a>', 'woocommerce' ), esc_url( **OUR NEW PAGE** ) ); ?> <span class="required">*</span></label>

That way, when a wholesale customer is checking out, the link to their specific TOS will be their specific page.

@daigo75
Copy link

daigo75 commented Mar 25, 2016

This should do the trick. Simply replace 12345 with the actual ID of the terms page that applies to wholesalers.

add_filter('woocommerce_get_terms_page_id', function($page_id) {
    global $current_user;
    if(isset($current_user) && class_exists('WWP_Wholesale_Roles')) {
        $wwp_wholesale_roles = WWP_Wholesale_Roles::getInstance();
        $wwp_wholesale_role = $wwp_wholesale_roles->getUserWholesaleRole();

        if(!empty($wwp_wholesale_role)) {
            // Set ID of Wholesaler Terms page
            $page_id = 12345;
        }
    }
    return $page_id;
}, 10, 1);

@BurlesonBrad
Copy link
Author

Once this is added to the theme-customizations/custom/functions.php file the site goes down.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment