uct Product object to test. * * @return bool True if it should be converted. */ public function should_convert_product_price( bool $return, $product ): bool { // If it's already false, return it. if ( ! $return ) { return $return; } $currency = $this->multi_currency->get_selected_currency(); // Check for cart items to see if they are in the original currency. if ( $currency->get_code() === $product->get_meta( self::NYP_CURRENCY ) ) { $return = false; } // Check to see if the product is a NYP product. if ( class_exists( '\WC_Name_Your_Price_Helpers' ) && \WC_Name_Your_Price_Helpers::is_nyp( $product ) ) { return false; } return $return; } /** * Add currency to cart edit link. * * @param array $args The cart args. * @param array $cart_item The current cart item. * * @return array */ public function edit_in_cart_args( $args, $cart_item ) { $args['nyp_currency'] = $this->multi_currency->get_selected_currency()->get_code(); return $args; } /** * Maybe convert any prices being edited from the cart * * @param string $initial_price The initial price. * @param mixed $product The product being queried. * @param string $suffix The suffix needed for composites and bundles. * * @return float|string */ public function get_initial_price( $initial_price, $product, $suffix ) { if ( isset( $_REQUEST[ 'nyp_raw' . $suffix ] ) && isset( $_REQUEST['nyp_currency'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended $from_currency = wc_clean( wp_unslash( $_REQUEST['nyp_currency'] ) ); // phpcs:ignore WordPress.Security.NonceVerification.Recommended $raw_price = (float) wc_clean( wp_unslash( $_REQUEST[ 'nyp_raw' . $suffix ] ) ); // phpcs:ignore WordPress.Security.NonceVerification.Recommended $selected_currency = $this->multi_currency->get_selected_currency(); if ( $from_currency !== $selected_currency->get_code() ) { $initial_price = $this->multi_currency->get_raw_conversion( $raw_price, $selected_currency->get_code(), $from_currency ); } } return $initial_price; } }