Add support for woocommerce-switch-currency

parent 0a2e53c3
......@@ -54,6 +54,7 @@ class Product_Addon_Cart {
* @return void
*/
public function add_cart_item( $cart_item ) {
global $Product_Addon_Prices;
// Adjust price if addons are set
if ( ! empty( $cart_item['addons'] ) ) {
......@@ -96,15 +97,16 @@ class Product_Addon_Cart {
* @return void
*/
public function get_item_data( $other_data, $cart_item ) {
global $Product_Addon_Prices;
if ( ! empty( $cart_item['addons'] ) ) {
foreach ( $cart_item['addons'] as $addon ) {
$name = $addon['name'];
if ( $addon['price'] > 0 && apply_filters( 'woocommerce_addons_add_price_to_name', '__return_true' ) )
$name .= ' (' . woocommerce_price( $addon['price'] ) . ')';
$name .= ' (' . woocommerce_price( $Product_Addon_Prices->get_current_price($addon['price']) ) . ')';
$other_data[] = array(
'name' => $name,
......@@ -126,7 +128,7 @@ class Product_Addon_Cart {
* @return void
*/
public function add_cart_item_data( $cart_item_meta, $product_id ) {
global $woocommerce;
global $woocommerce, $Product_Addon_Prices;
$product_addons = get_product_addons( $product_id );
......@@ -162,7 +164,7 @@ class Product_Addon_Cart {
$cart_item_meta['addons'][] = array(
'name' => esc_attr( $addon['name'] ),
'value' => esc_attr( $option['label'] ),
'price' => esc_attr( $option['price'] )
'price' => esc_attr( get_current_price($option['price']) )
);
}
}
......@@ -202,6 +204,7 @@ class Product_Addon_Cart {
'price' => esc_attr( $chosen_option['price'] )
);
break;
case "custom" :
case "custom_textarea" :
......@@ -225,7 +228,7 @@ class Product_Addon_Cart {
if ( $addon['type'] == "custom_price" ) {
$price = floatval( woocommerce_clean( $posted ) );
//$price = $Product_Addon_Prices->get_current_price($price);
if ( $price >= 0 ) {
$cart_item_meta['addons'][] = array(
'name' => esc_attr( $label ),
......@@ -370,7 +373,7 @@ class Product_Addon_Cart {
if ( $addon['type'] == "custom_price" ) {
$price = floatval( woocommerce_clean( $posted ) );
//$price = $Product_Addon_Prices->get_current_price($price);
if ( $price < 0 ) {
$this->add_error( sprintf( __( 'Invalid price entered for "%s".', 'woocommerce' ), $addon['name'] ) );
return false;
......@@ -587,7 +590,7 @@ class Product_Addon_Cart {
if ( $addon['type'] == "custom_price" ) {
$price = floatval( woocommerce_clean( $posted ) );
$price = $price;
if ( $price >= 0 ) {
$cart_item_meta['addons'][] = array(
'name' => esc_attr( $label ),
......
......@@ -169,7 +169,7 @@ class Product_Addon_Display {
*/
function totals( $post_id ) {
global $product;
global $product, $Product_Addon_Prices;
if ( ! isset( $product ) || $product->id != $post_id )
$the_product = get_product( $post_id );
......
......@@ -50,6 +50,10 @@ if ( is_woocommerce_active() ) {
include_once( 'classes/class-product-addon-cart.php' );
$GLOBALS['Product_Addon_Cart'] = new Product_Addon_Cart();
include_once ( 'classes/class-product-addon-prices.php' );
$GLOBALS['Product_Addon_Prices'] = new Product_Addon_Prices();
}
/**
......
......@@ -8,9 +8,9 @@ $current_value = isset( $_POST['addon-' . sanitize_title( $addon['field-name'] )
<?php foreach ( $addon['options'] as $option ) :
$loop ++;
$price = $option['price'] > 0 ? ' (' . woocommerce_price( $option['price'] ) . ')' : '';
$price = $option['price'] > 0 ? ' (' . woocommerce_price($GLOBALS['Product_Addon_Prices']->get_current_price($option['price']) ) . ')' : '';
?>
<option data-price="<?php echo $option['price']; ?>" value="<?php echo sanitize_title( $option['label'] ) . '-' . $loop; ?>" <?php selected( $current_value, sanitize_title( $option['label'] ) . '-' . $loop ); ?>><?php echo wptexturize( $option['label'] ) . $price ?></option>
<option data-price="<?php echo $GLOBALS['Product_Addon_Prices']->get_current_price($option['price']); ?>" value="<?php echo sanitize_title( $option['label'] ) . '-' . $loop; ?>" <?php selected( $current_value, sanitize_title( $option['label'] ) . '-' . $loop ); ?>><?php echo wptexturize( $option['label'] ) . $price ?></option>
<?php endforeach; ?>
</select>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment