Customer functions woocommerce to wc refactor

This commit is contained in:
Coen Jacobs 2013-11-25 13:52:53 +01:00
parent aaa14894ca
commit 1663eafb68
8 changed files with 43 additions and 22 deletions

View File

@ -41,7 +41,7 @@ class WC_Report_Customer_List extends WP_List_Table {
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>';
}

View File

@ -213,7 +213,7 @@ class WC_API_Products extends WC_API_Resource {
'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 ),
);
}

View File

@ -614,14 +614,14 @@ class WC_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 );

View File

@ -798,14 +798,14 @@ class WC_Form_Handler {
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() ) {

View File

@ -21,14 +21,14 @@ if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
* @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 );
/**
@ -39,7 +39,7 @@ add_filter( 'show_admin_bar', 'woocommerce_disable_admin_bar', 10, 1 );
* @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 ) )
@ -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 );
@ -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 ) );
@ -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 );
@ -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
@ -217,7 +215,7 @@ add_action( 'woocommerce_order_status_completed', 'woocommerce_paying_customer'
* @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();
@ -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
@ -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] ) {
@ -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);

View File

@ -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
*/

View File

@ -43,7 +43,7 @@ if ( ! comments_open() )
<?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">

View File

@ -39,7 +39,7 @@ $rating = intval( get_comment_meta( $comment->comment_ID, 'rating', true ) );
<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>: