Edit File by line
/home/zeestwma/richards.../wp-conte.../plugins/woocomme.../includes/shortcod...
File: class-wc-shortcode-cart.php
<?php
[0] Fix | Delete
/**
[1] Fix | Delete
* Cart Shortcode
[2] Fix | Delete
*
[3] Fix | Delete
* Used on the cart page, the cart shortcode displays the cart contents and interface for coupon codes and other cart bits and pieces.
[4] Fix | Delete
*
[5] Fix | Delete
* @package WooCommerce\Shortcodes\Cart
[6] Fix | Delete
* @version 2.3.0
[7] Fix | Delete
*/
[8] Fix | Delete
[9] Fix | Delete
use Automattic\WooCommerce\Internal\FraudProtection\CartEventTracker;
[10] Fix | Delete
use Automattic\WooCommerce\Internal\FraudProtection\FraudProtectionController;
[11] Fix | Delete
[12] Fix | Delete
defined( 'ABSPATH' ) || exit;
[13] Fix | Delete
[14] Fix | Delete
/**
[15] Fix | Delete
* Shortcode cart class.
[16] Fix | Delete
*/
[17] Fix | Delete
class WC_Shortcode_Cart {
[18] Fix | Delete
[19] Fix | Delete
/**
[20] Fix | Delete
* Calculate shipping for the cart.
[21] Fix | Delete
*
[22] Fix | Delete
* @throws Exception When some data is invalid.
[23] Fix | Delete
*/
[24] Fix | Delete
public static function calculate_shipping() {
[25] Fix | Delete
try {
[26] Fix | Delete
WC()->shipping()->reset_shipping();
[27] Fix | Delete
[28] Fix | Delete
$address = array();
[29] Fix | Delete
[30] Fix | Delete
$address['country'] = isset( $_POST['calc_shipping_country'] ) ? wc_clean( wp_unslash( $_POST['calc_shipping_country'] ) ) : ''; // WPCS: input var ok, CSRF ok, sanitization ok.
[31] Fix | Delete
$address['state'] = isset( $_POST['calc_shipping_state'] ) ? wc_clean( wp_unslash( $_POST['calc_shipping_state'] ) ) : ''; // WPCS: input var ok, CSRF ok, sanitization ok.
[32] Fix | Delete
$address['postcode'] = isset( $_POST['calc_shipping_postcode'] ) ? wc_clean( wp_unslash( $_POST['calc_shipping_postcode'] ) ) : ''; // WPCS: input var ok, CSRF ok, sanitization ok.
[33] Fix | Delete
$address['city'] = isset( $_POST['calc_shipping_city'] ) ? wc_clean( wp_unslash( $_POST['calc_shipping_city'] ) ) : ''; // WPCS: input var ok, CSRF ok, sanitization ok.
[34] Fix | Delete
[35] Fix | Delete
if ( $address['postcode'] ) {
[36] Fix | Delete
$address['postcode'] = wc_format_postcode( $address['postcode'], $address['country'] );
[37] Fix | Delete
}
[38] Fix | Delete
[39] Fix | Delete
$address = apply_filters( 'woocommerce_cart_calculate_shipping_address', $address );
[40] Fix | Delete
[41] Fix | Delete
if ( $address['postcode'] && ! WC_Validation::is_postcode( $address['postcode'], $address['country'] ) ) {
[42] Fix | Delete
throw new Exception( __( 'Please enter a valid postcode / ZIP.', 'woocommerce' ) );
[43] Fix | Delete
}
[44] Fix | Delete
[45] Fix | Delete
if ( $address['country'] ) {
[46] Fix | Delete
if ( ! WC()->customer->get_billing_first_name() ) {
[47] Fix | Delete
WC()->customer->set_billing_location( $address['country'], $address['state'], $address['postcode'], $address['city'] );
[48] Fix | Delete
}
[49] Fix | Delete
WC()->customer->set_shipping_location( $address['country'], $address['state'], $address['postcode'], $address['city'] );
[50] Fix | Delete
} else {
[51] Fix | Delete
WC()->customer->set_billing_address_to_base();
[52] Fix | Delete
WC()->customer->set_shipping_address_to_base();
[53] Fix | Delete
}
[54] Fix | Delete
[55] Fix | Delete
WC()->customer->set_calculated_shipping( true );
[56] Fix | Delete
WC()->customer->save();
[57] Fix | Delete
[58] Fix | Delete
wc_add_notice( __( 'Shipping costs updated.', 'woocommerce' ), 'notice' );
[59] Fix | Delete
[60] Fix | Delete
do_action( 'woocommerce_calculated_shipping' );
[61] Fix | Delete
[62] Fix | Delete
} catch ( Exception $e ) {
[63] Fix | Delete
if ( ! empty( $e ) ) {
[64] Fix | Delete
wc_add_notice( $e->getMessage(), 'error' );
[65] Fix | Delete
}
[66] Fix | Delete
}
[67] Fix | Delete
}
[68] Fix | Delete
[69] Fix | Delete
/**
[70] Fix | Delete
* Output the cart shortcode.
[71] Fix | Delete
*
[72] Fix | Delete
* @param array $atts Shortcode attributes.
[73] Fix | Delete
*/
[74] Fix | Delete
public static function output( $atts ) {
[75] Fix | Delete
if ( ! apply_filters( 'woocommerce_output_cart_shortcode_content', true ) ) {
[76] Fix | Delete
return;
[77] Fix | Delete
}
[78] Fix | Delete
[79] Fix | Delete
// Constants.
[80] Fix | Delete
wc_maybe_define_constant( 'WOOCOMMERCE_CART', true );
[81] Fix | Delete
[82] Fix | Delete
// Track cart page loaded for fraud protection.
[83] Fix | Delete
if ( wc_get_container()->get( FraudProtectionController::class )->feature_is_enabled() ) {
[84] Fix | Delete
wc_get_container()->get( CartEventTracker::class )
[85] Fix | Delete
->track_cart_page_loaded();
[86] Fix | Delete
}
[87] Fix | Delete
[88] Fix | Delete
$atts = shortcode_atts( array(), $atts, 'woocommerce_cart' );
[89] Fix | Delete
$nonce_value = wc_get_var( $_REQUEST['woocommerce-shipping-calculator-nonce'], wc_get_var( $_REQUEST['_wpnonce'], '' ) ); // @codingStandardsIgnoreLine.
[90] Fix | Delete
[91] Fix | Delete
// Update Shipping. Nonce check uses new value and old value (woocommerce-cart). @todo remove in 4.0.
[92] Fix | Delete
if ( ! empty( $_POST['calc_shipping'] ) && ( wp_verify_nonce( $nonce_value, 'woocommerce-shipping-calculator' ) || wp_verify_nonce( $nonce_value, 'woocommerce-cart' ) ) ) { // WPCS: input var ok.
[93] Fix | Delete
self::calculate_shipping();
[94] Fix | Delete
[95] Fix | Delete
// Also calc totals before we check items so subtotals etc are up to date.
[96] Fix | Delete
WC()->cart->calculate_totals();
[97] Fix | Delete
}
[98] Fix | Delete
[99] Fix | Delete
// Check cart items are valid.
[100] Fix | Delete
do_action( 'woocommerce_check_cart_items' );
[101] Fix | Delete
[102] Fix | Delete
// Calc totals.
[103] Fix | Delete
WC()->cart->calculate_totals();
[104] Fix | Delete
[105] Fix | Delete
if ( WC()->cart->is_empty() ) {
[106] Fix | Delete
wc_get_template( 'cart/cart-empty.php' );
[107] Fix | Delete
} else {
[108] Fix | Delete
wc_get_template( 'cart/cart.php' );
[109] Fix | Delete
}
[110] Fix | Delete
}
[111] Fix | Delete
}
[112] Fix | Delete
[113] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function