get_option( 'buy_now' ) || ! $product instanceof WC_Product ) { return; } if ( ! ( $product->is_virtual() || $product->is_downloadable() ) ) { return; } // The product id travels on the button (as on WooCommerce's own button); the flag on the form target. printf( '', absint( $product->get_id() ), esc_url( add_query_arg( self::FIELD, '1', get_permalink( $product->get_id() ) ) ), esc_html__( 'Buy now', 'agentaos-payments' ) ); } /** * @param bool $passed Whether WooCommerce lets the item in. * @return bool */ public static function empty_cart_first( $passed ) { if ( $passed && self::requested() && WC()->cart ) { WC()->cart->empty_cart(); } return $passed; } /** * @param string $url Where WooCommerce would send the buyer. * @return string */ public static function redirect( $url ) { return self::requested() ? wc_get_checkout_url() : $url; } /** * @return bool */ private static function requested() { return ! empty( $_REQUEST[ self::FIELD ] ); // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- same trust as WooCommerce's add-to-cart form. } /** * @return AgentaOS_Gateway|null */ private static function gateway() { $gateways = WC()->payment_gateways() ? WC()->payment_gateways()->payment_gateways() : array(); return isset( $gateways['agentaos'] ) && $gateways['agentaos']->is_ready() ? $gateways['agentaos'] : null; } }