Home Forums WoodMart support forum Dynamic Discounts are empty

Dynamic Discounts are empty

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #714712

    Fabio
    Participant

    Hi,

    I have some dynamic discounts that I created quite a while ago, but when I went to change the tiers, I opened one of them and noticed that they were empty. However, the tiers are still being applied to the products even though the settings have disappeared.

    Thank you.

    Attachments:
    You must be logged in to view attached files.
    #714789

    Artem Temos
    Keymaster
    Xtemos team

    Hello,

    To fix this issue (which happened after a data format change in the previous update), please add the following code snippet to the functions.php file in the child theme. Then go to any page on your website to regenerate the data format. It should solve the problem, so you can delete the code from the file after that.

    if ( ! function_exists( 'woodmart_update_dynamic_discounts_data' ) ) {
    	/**
    	 * Update dynamic discounts data.
    	 */
    	function woodmart_update_dynamic_discounts_data() {
    		if ( ! woodmart_get_opt( 'discounts_enabled' ) ) {
    			return;
    		}
    
    		$discounts_ids = get_posts(
    			array(
    				'post_type'      => 'wd_woo_discounts',
    				'posts_per_page' => -1,
    				'fields'         => 'ids',
    				'post_status'    => 'any',
    			)
    		);
    
    		if ( ! is_array( $discounts_ids ) || empty( $discounts_ids ) ) {
    			return;
    		}
    
    		foreach ( $discounts_ids as $discount_id ) {
    			$discount_rules     = get_post_meta( $discount_id, 'discount_rules', true );
    			$discount_condition = get_post_meta( $discount_id, 'discount_condition', true );
    
    			if ( ! empty( $discount_rules ) && is_serialized( $discount_rules ) ) {
    				$unserialized_rules = maybe_unserialize( $discount_rules );
    
    				if ( is_array( $unserialized_rules ) && ! empty( $unserialized_rules ) ) {
    					update_post_meta( $discount_id, 'discount_rules', $unserialized_rules );
    				}
    			}
    
    			if ( ! empty( $discount_condition ) && is_serialized( $discount_condition ) ) {
    				$unserialized_condition = maybe_unserialize( $discount_condition );
    
    				if ( is_array( $unserialized_condition ) && ! empty( $unserialized_condition ) ) {
    					update_post_meta( $discount_id, 'discount_condition', $unserialized_condition );
    				}
    			}
    
    			delete_transient( 'wd_transient_discounts_rule_' . $discount_id );
    		}
    
    		delete_transient( 'wd_all_discounts_post_ids' );
    	}
    
    	add_action( 'init', 'woodmart_update_dynamic_discounts_data' );
    }

    Kind Regards

    #715208

    Fabio
    Participant

    Hi,

    That solved the problem!
    Thank you!

    #715243

    Artem Temos
    Keymaster
    Xtemos team

    You are always welcome. Feel free to contact us if you have any further questions.

Viewing 4 posts - 1 through 4 (of 4 total)

The topic ‘Dynamic Discounts are empty’ is closed to new replies.