e; } $order = wc_get_order( get_post()->ID ); if ( ! $order ) { return false; } // At this point (no packaging data), only show if there's at least one existing and shippable product. foreach ( $order->get_items() as $item ) { if ( $item instanceof \WC_Order_Item_Product ) { $product = $item->get_product(); if ( $product && $product->needs_shipping() ) { return true; } } } return false; } /** * Checks if the store is in the US and has its default currency set to USD. * * @return bool */ private function store_in_us_and_usd() { $base_currency = get_woocommerce_currency(); $base_location = wc_get_base_location(); return in_array( $base_currency, $this->supported_currencies, true ) && in_array( $base_location['country'], $this->supported_countries, true ); } /** * Checks if WooCommerce Shipping & Tax is not installed. * * @return bool */ private function wcs_not_installed() { return ! $this->wcs_version; } /** * Checks if WooCommerce Shipping & Tax is up to date. */ private function wcs_up_to_date() { return $this->wcs_version && version_compare( $this->wcs_version, $this->min_wcs_version, '>=' ); } } -admin/includes/plugin.php'; return 0 === validate_plugin( self::PLUGIN_FILE ); } /** * Install and activate WooCommerce Payments. * * @return boolean Whether the plugin was successfully activated. */ private function install_and_activate_wcpay() { $install_request = array( 'plugins' => self::PLUGIN_SLUG ); $installer = new \Automattic\WooCommerce\Admin\API\Plugins(); $result = $installer->install_plugins( $install_request ); if ( is_wp_error( $result ) ) { return false; } wc_admin_record_tracks_event( 'woocommerce_payments_install', array( 'context' => 'inbox' ) ); $activate_request = array( 'plugins' => self::PLUGIN_SLUG ); $result = $installer->activate_plugins( $activate_request ); if ( is_wp_error( $result ) ) { return false; } return true; } /** * Install & activate WooCommerce Payments plugin, and redirect to setup. */ public function install_on_action() { // TODO: Need to validate this request more strictly since we're taking install actions directly? if ( ! isset( $_GET['page'] ) || 'wc-admin' !== $_GET['page'] || ! isset( $_GET['action'] ) || 'setup-woocommerce-payments' !== $_GET['action'] ) { return; } $data_store = Notes::load_data_store(); // We already have this note? Then mark the note as actioned. $note_ids = $data_store->get_notes_with_name( self::NOTE_NAME ); if ( empty( $note_ids ) ) { return; } $note_id = array_pop( $note_ids ); $note = Notes::get_note( $note_id ); if ( false === $note ) { return; } $action = $note->get_action( 'get-started' ); if ( ! $action || ( isset( $action->nonce_action ) && ( empty( $_GET['_wpnonce'] ) || ! wp_verify_nonce( wp_unslash( $_GET['_wpnonce'] ), $action->nonce_action ) // phpcs:ignore WordPress.Security.ValidatedSanitizedInput ) ) ) { return; } if ( ! current_user_can( 'install_plugins' ) ) { return; } $this->install_and_activate_wcpay(); // WooCommerce Payments is installed at this point, so link straight into the onboarding flow. $connect_url = add_query_arg( array( 'wcpay-connect' => '1', '_wpnonce' => wp_create_nonce( 'wcpay-connect' ), ), admin_url() ); wp_safe_redirect( $connect_url ); exit; } }