WC Cart Edit Public Function
How would you go about making an edit to the following public function in
your child theme? For instance, I would like to comment out the 'if
statement' in the WooCommerce WC_Cart class function that performs the
check against email and coupon code.
Line 400: /classes/class-wc-cart.php
public function check_customer_coupons( $posted ) {
global $woocommerce;
if ( ! empty( $this->applied_coupons ) ) {
foreach ( $this->applied_coupons as $key => $code ) {
$coupon = new WC_Coupon( $code );
if ( ! is_wp_error( $coupon->is_valid() ) && is_array(
$coupon->customer_email ) && sizeof(
$coupon->customer_email ) > 0 ) {
$coupon->customer_email = array_map( 'sanitize_email',
$coupon->customer_email );
if ( is_user_logged_in() ) {
$current_user = wp_get_current_user();
$check_emails[] = $current_user->user_email;
}
$check_emails[] = $posted['billing_email'];
$check_emails = array_map( 'sanitize_email',
array_map( 'strtolower', $check_emails ) );
/*if ( 0 == sizeof( array_intersect( $check_emails,
$coupon->customer_email ) ) ) {
$coupon->add_coupon_message(
WC_Coupon::E_WC_COUPON_NOT_YOURS_REMOVED );
// Remove the coupon
unset( $this->applied_coupons[ $key ] );
$woocommerce->session->coupon_codes =
$this->applied_coupons;
$woocommerce->session->refresh_totals = true;
} */
}
}
}
}
This function is executed Line 104: /classes/class-wc-cart.php
public function init() {
$this->get_cart_from_session();
add_action('woocommerce_check_cart_items', array( $this,
'check_cart_items' ), 1 );
add_action('woocommerce_check_cart_items', array( $this,
'check_cart_coupons' ), 1 );
add_action('woocommerce_after_checkout_validation', array( $this,
'check_customer_coupons' ), 1 );
}
I think the answer would be useful for anyone else wanting to know how to
edit other functions.
Thank you.
No comments:
Post a Comment