• Resolved zhakal

    (@zhakal)


    After upgrading from 2.4.X to newest version of WooCommerce, I get zero price on variation products.

    
    public function __construct( $product )	{
    
    $this->product_type = 'audio_conference';
    parent::__construct( $product );
    $this->meta = $this->set_meta();
    
    $current_pricing = $this->get_pricing();
    
    if ( ! empty( $current_pricing['recording'] ) ) {
    
    	$this->price = ( ! empty( $current_pricing['recording']['sale'] ) ? $current_pricing['recording']['sale'] : $current_pricing['recording']['regular'] );
    } elseif ( ! empty( $current_pricing['event'] ) ) {
    
    	$this->price = ( ! empty( $current_pricing['event']['sale'] ) ? $current_pricing['event']['sale'] : $current_pricing['event']['regular'] );
    } elseif ( ! empty( $current_pricing['ondemand'] ) ) {
    	
    	$this->price = ( ! empty( $current_pricing['ondemand']['sale'] ) ? $current_pricing['ondemand']['sale'] : $current_pricing['ondemand']['regular'] );
    } else {
    
    	$this->price = 0;
    }
    }
    public function get_pricing() {
    
    global $c4cm;
    $pricing = array();
    if (is_array($c4cm['audio-conference']['selections']) || is_object($c4cm['audio-conference']['selections'])) {
    foreach ( $c4cm['audio-conference']['selections'] as $type => $title ) {
    
    	// Check if last sale date is set, if not set to event date
    	if ( ( $type == 'event' || $type == 'bundle' ) && $this->event_has_past() ) {
    		$pricing[$type] = false;
    		continue;
    		
    	}
    	
    	$key_rp = $type . '_price';
    	$key_ep = $type . '_early_bird_price';
    
    	if ( $type == 'recording' && ! $this->meta->{$key_rp} ) {
    		$pricing[$type] = false;
    		continue;
    	}
    	
    	if ( $type == 'ondemand' && ! $this->meta->{$key_rp} ) {
    		$pricing[$type] = false;
    		continue;
    	}2
    
    	$pricing[$type]['regular'] = $this->meta->{$key_rp};
    	
    	// check for early bird sale
    	if ( $this->early_bird_sale_is_active() && $this->meta->{$key_ep} ) {
    		$pricing[$type]['sale'] = $this->meta->$key_ep;				
    	} else {
    		$pricing[$type]['sale'] = false;
    	}
    }
    }
    
    return $pricing;
    }
    

    I have managed to correct all the other issues, but this is the one left and I can’t figure out where the issue is. WooCommerce indicates in their upgrade guidelines that things have changed, but I can’t get my head around it.

    So all help would be greatly appreciated!

    • This topic was modified 6 years, 5 months ago by zhakal.
    • This topic was modified 6 years, 5 months ago by zhakal.
Viewing 4 replies - 1 through 4 (of 4 total)
  • jessepearson

    (@jessepearson)

    Automattic Happiness Engineer

    @zhakal Is your product type extending another product type? Your class declaration isn’t included, so it’s hard to tell all of what is going on here. Would you be able to put your whole file in a Gist? https://gist.github.com/

    Thread Starter zhakal

    (@zhakal)

    jessepearson

    (@jessepearson)

    Automattic Happiness Engineer

    @zhaka I am unsure of what is going on in your file, it seems like you have a custom product type that is saving several different types of prices depending on other data. From what I can tell, all of this data is being saved in custom meta data and is not using the _price meta data at all.

    There was a pretty large code change in how data is managed in WC 3.x, but this should not have affected existing meta data, nor changed how WordPress itself accesses that meta data. Values should still exist and WordPress should return the values.

    Thread Starter zhakal

    (@zhakal)

    The product is having a price as it should on the item page.
    It shows up correctly when viewing, but once it’s added to the cart it shows zero on the total on minicart.

    In the actual “Cart Items” it shows zero on the item, but not on the total.

    On the “Cart totals” it shows zero on both.

    Screenshot 1
    Screenshot 2
    Screenshot 3

    The main difference is between a working one and a non-working is on the add_to_cart area for adding it to the cart:

    <form id="carting-form" action="<?php echo wc_get_cart_url(); ?>" method="post" enctype='multipart/form-data'>
    	<div id="product-info-cnt">
    		<?php echo $product->get_pricing_html(); ?>
    		<input type="hidden" name="add-to-cart" value="<?php echo esc_attr( $product->get_id() ); ?>">
    		<input type="hidden" name="link-back" value="<?php echo esc_attr( $product->get_id() ); ?>">
    	</div>
    </form>

    Other one is the pricing-options.php
    https://gist.github.com/larsmagnusherland/bcd8318846d54e7490fe02469daf5802

    Tried so many things for the last weeks to figure out where this is, but soon giving up. Most other kinks have been solved, but this I really don’t see. Might be blinded by code ??

    • This reply was modified 6 years, 5 months ago by zhakal.
Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘After upgrade to 3.X I get zero price’ is closed to new replies.