Skip to content

Commit

Permalink
Customer functions woocommerce to wc refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
coenjacobs committed Nov 25, 2013
1 parent aaa1489 commit 1663eaf
Show file tree
Hide file tree
Showing 8 changed files with 43 additions and 22 deletions.
2 changes: 1 addition & 1 deletion includes/admin/reports/class-wc-report-customer-list.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public function output_report() {
echo '<div id="poststuff" class="woocommerce-reports-wide">';

if ( ! empty( $_GET['link_orders'] ) && wp_verify_nonce( $_REQUEST['_wpnonce'], 'link_orders' ) ) {
$linked = woocommerce_update_new_customer_past_orders( absint( $_GET['link_orders'] ) );
$linked = wc_update_new_customer_past_orders( absint( $_GET['link_orders'] ) );

echo '<div class="updated"><p>' . sprintf( _n( '%s previous order linked', '%s previous orders linked', $linked, 'woocommerce' ), $linked ) . '</p></div>';
}
Expand Down
2 changes: 1 addition & 1 deletion includes/api/class-wc-api-products.php
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ public function get_product_reviews( $id, $fields = null ) {
'rating' => get_comment_meta( $comment->comment_ID, 'rating', true ),
'reviewer_name' => $comment->comment_author,
'reviewer_email' => $comment->comment_author_email,
'verified' => (bool) woocommerce_customer_bought_product( $comment->comment_author_email, $comment->user_id, $id ),
'verified' => (bool) wc_customer_bought_product( $comment->comment_author_email, $comment->user_id, $id ),
);
}

Expand Down
4 changes: 2 additions & 2 deletions includes/class-wc-checkout.php
Original file line number Diff line number Diff line change
Expand Up @@ -614,14 +614,14 @@ public function process_checkout() {

$username = ! empty( $this->posted['account_username'] ) ? $this->posted['account_username'] : '';
$password = ! empty( $this->posted['account_password'] ) ? $this->posted['account_password'] : '';
$new_customer = woocommerce_create_new_customer( $this->posted['billing_email'], $username, $password );
$new_customer = wc_create_new_customer( $this->posted['billing_email'], $username, $password );

if ( is_wp_error( $new_customer ) )
throw new Exception( $new_customer->get_error_message() );

$this->customer_id = $new_customer;

woocommerce_set_customer_auth_cookie( $this->customer_id );
wc_set_customer_auth_cookie( $this->customer_id );

// As we are now logged in, checkout will need to refresh to show logged in data
WC()->session->set( 'reload_checkout', true );
Expand Down
4 changes: 2 additions & 2 deletions includes/class-wc-form-handler.php
Original file line number Diff line number Diff line change
Expand Up @@ -798,14 +798,14 @@ public function process_registration() {
return;
}

$new_customer = woocommerce_create_new_customer( $email, $username, $password );
$new_customer = wc_create_new_customer( $email, $username, $password );

if ( is_wp_error( $new_customer ) ) {
wc_add_notice( $new_customer->get_error_message(), 'error' );
return;
}

woocommerce_set_customer_auth_cookie( $new_customer );
wc_set_customer_auth_cookie( $new_customer );

// Redirect
if ( wp_get_referer() ) {
Expand Down
24 changes: 10 additions & 14 deletions includes/wc-customer-functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,14 @@
* @param bool $show_admin_bar
* @return bool
*/
function woocommerce_disable_admin_bar( $show_admin_bar ) {
function wc_disable_admin_bar( $show_admin_bar ) {
if ( apply_filters( 'woocommerce_disable_admin_bar', get_option( 'woocommerce_lock_down_admin', "yes" ) == "yes" ) && ! ( current_user_can('edit_posts') || current_user_can('manage_woocommerce') ) ) {
$show_admin_bar = false;
}

return $show_admin_bar;
}
add_filter( 'show_admin_bar', 'woocommerce_disable_admin_bar', 10, 1 );
add_filter( 'show_admin_bar', 'wc_disable_admin_bar', 10, 1 );


/**
Expand All @@ -39,7 +39,7 @@ function woocommerce_disable_admin_bar( $show_admin_bar ) {
* @param string $password
* @return WP_Error on failure, Int (user ID) on success
*/
function woocommerce_create_new_customer( $email, $username = '', $password = '' ) {
function wc_create_new_customer( $email, $username = '', $password = '' ) {

// Check the e-mail address
if ( empty( $email ) || ! is_email( $email ) )
Expand Down Expand Up @@ -117,7 +117,7 @@ function woocommerce_create_new_customer( $email, $username = '', $password = ''
* @param int $customer_id
* @return void
*/
function woocommerce_set_customer_auth_cookie( $customer_id ) {
function wc_set_customer_auth_cookie( $customer_id ) {
global $current_user;

$current_user = get_user_by( 'id', $customer_id );
Expand All @@ -131,7 +131,7 @@ function woocommerce_set_customer_auth_cookie( $customer_id ) {
* @param int $customer_id
* @return void
*/
function woocommerce_update_new_customer_past_orders( $customer_id ) {
function wc_update_new_customer_past_orders( $customer_id ) {

$customer = get_user_by( 'id', absint( $customer_id ) );

Expand Down Expand Up @@ -189,7 +189,7 @@ function woocommerce_update_new_customer_past_orders( $customer_id ) {
* @param int $order_id
* @return void
*/
function woocommerce_paying_customer( $order_id ) {
function wc_paying_customer( $order_id ) {

$order = new WC_Order( $order_id );

Expand All @@ -203,12 +203,10 @@ function woocommerce_paying_customer( $order_id ) {
update_user_meta( $order->user_id, '_order_count', $old_count + 1 );
}
}
add_action( 'woocommerce_order_status_completed', 'woocommerce_paying_customer' );
add_action( 'woocommerce_order_status_completed', 'wc_paying_customer' );


/**
* woocommerce_customer_bought_product
*
* Checks if a user (by email) has bought an item
*
* @access public
Expand All @@ -217,7 +215,7 @@ function woocommerce_paying_customer( $order_id ) {
* @param int $product_id
* @return bool
*/
function woocommerce_customer_bought_product( $customer_email, $user_id, $product_id ) {
function wc_customer_bought_product( $customer_email, $user_id, $product_id ) {
global $wpdb;

$emails = array();
Expand Down Expand Up @@ -261,8 +259,6 @@ function woocommerce_customer_bought_product( $customer_email, $user_id, $produc
}

/**
* woocommerce_customer_has_capability
*
* Checks if a user has a certain capability
*
* @access public
Expand All @@ -271,7 +267,7 @@ function woocommerce_customer_bought_product( $customer_email, $user_id, $produc
* @param array $args
* @return bool
*/
function woocommerce_customer_has_capability( $allcaps, $caps, $args ) {
function wc_customer_has_capability( $allcaps, $caps, $args ) {
if ( isset( $caps[0] ) ) {
switch ( $caps[0] ) {

Expand Down Expand Up @@ -323,4 +319,4 @@ function woocommerce_customer_has_capability( $allcaps, $caps, $args ) {
}
return $allcaps;
}
add_filter( 'user_has_cap', 'woocommerce_customer_has_capability', 10, 3);
add_filter( 'user_has_cap', 'wc_customer_has_capability', 10, 3);
25 changes: 25 additions & 0 deletions includes/wc-deprecated-functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,31 @@ function woocommerce_mail( $to, $subject, $message, $headers = "Content-Type: te
wc_mail( $to, $subject, $message, $headers, $attachments );
}

/**
* Customer functions (soft deprecated)
*/
function woocommerce_disable_admin_bar( $show_admin_bar ) {
wc_disable_admin_bar( $show_admin_bar );
}
function woocommerce_create_new_customer( $email, $username = '', $password = '' ) {
wc_create_new_customer( $email, $username, $password );
}
function woocommerce_set_customer_auth_cookie( $customer_id ) {
wc_set_customer_auth_cookie( $customer_id );
}
function woocommerce_update_new_customer_past_orders( $customer_id ) {
wc_update_new_customer_past_orders( $customer_id );
}
function wc_paying_customer( $order_id ) {
woocommerce_paying_customer( $order_id );
}
function woocommerce_customer_bought_product( $customer_email, $user_id, $product_id ) {
wc_customer_bought_product( $customer_email, $user_id, $product_id );
}
function woocommerce_customer_has_capability( $allcaps, $caps, $args ) {
wc_customer_has_capability( $allcaps, $caps, $args );
}

/**
* Handle renamed filters
*/
Expand Down
2 changes: 1 addition & 1 deletion templates/single-product-reviews.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
<?php endif; ?>
</div>

<?php if ( get_option( 'woocommerce_review_rating_verification_required' ) == 'no' || woocommerce_customer_bought_product( '', get_current_user_id(), $product->id ) ) : ?>
<?php if ( get_option( 'woocommerce_review_rating_verification_required' ) == 'no' || wc_customer_bought_product( '', get_current_user_id(), $product->id ) ) : ?>

<div id="review_form_wrapper">
<div id="review_form">
Expand Down
2 changes: 1 addition & 1 deletion templates/single-product/review.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
<strong itemprop="author"><?php comment_author(); ?></strong> <?php

if ( get_option('woocommerce_review_rating_verification_label') == 'yes' )
if ( woocommerce_customer_bought_product( $comment->comment_author_email, $comment->user_id, $comment->comment_post_ID ) )
if ( wc_customer_bought_product( $comment->comment_author_email, $comment->user_id, $comment->comment_post_ID ) )
echo '<em class="verified">(' . __( 'verified owner', 'woocommerce' ) . ')</em> ';

?>&ndash; <time itemprop="datePublished" datetime="<?php echo get_comment_date('c'); ?>"><?php echo get_comment_date(__( get_option('date_format'), 'woocommerce' )); ?></time>:
Expand Down

0 comments on commit 1663eaf

Please sign in to comment.