Support » Plugin: Discount for TheCartPress » Option titles make no sense and do not honor settings

  • In TCPDiscount.class.php starting at line 420 there is filter function tcp_options_title whose job is to print discounted option prices. However it does not take into account price formatting settings or discount formatting settings. Also it always formats discount with tcp_format_the_price regardless of discount type.

    This is my own solution:

    function tcp_options_title( $option_title, $product_id, $option_id_1 = 0, $option_id_2 = 0 ) {
    		$discounts = $this->getDiscountsByProduct();
    		$discounts = $this->getDiscountByProduct( $discounts, $product_id, $option_id_1, $option_id_2 );
    		if ( count( $discounts ) > 0 ) {
    			// HACK:
    			$option_price = floatval(tcp_get_the_price($product_id)) + floatval(tcp_get_the_price($option_id_1));
    			$option_price = $discounts[0]['type'] == 'amount' ? $option_price - $discounts[0]['value'] : $option_price * (1 - $discounts[0]['value'] / 100);
    			$option_title = get_the_title($option_id_1) . ' ' . tcp_format_the_price($option_price);
    			return $option_title;
    			// END OF HACK
    			return $option_title . ' ' . sprintf( __( '(%s off)', 'tcp-discount' ), tcp_format_the_price( $discounts[0]['value'] ) ); // This is obsolete now.
    		}
    		return $option_title;
    	}

    https://wordpress.org/plugins/discounts-for-thecartpress/

  • The topic ‘Option titles make no sense and do not honor settings’ is closed to new replies.