Automattic\WooCommerce\Blocks\Domain\Services
CheckoutLink::get_products_from_checkout_link
Get the products from the checkout link.
Method of the class: CheckoutLink{}
No Hooks.
Returns
Array. The products (keys) and their quantities (values).
Usage
// protected - for code of main (parent) or child class $result = $this->get_products_from_checkout_link();
CheckoutLink::get_products_from_checkout_link() CheckoutLink::get products from checkout link code WC 10.7.0
protected function get_products_from_checkout_link() {
$raw_products = array_filter( explode( ',', wc_clean( wp_unslash( $_GET['products'] ?? '' ) ) ) ); // phpcs:ignore WordPress.Security.NonceVerification.Recommended
$products = [];
foreach ( $raw_products as $product_id_qty ) {
if ( strpos( $product_id_qty, ':' ) !== false ) {
list( $product_id, $qty ) = explode( ':', $product_id_qty );
} else {
$product_id = $product_id_qty;
$qty = 1;
}
$product_id = absint( $product_id );
$qty = absint( $qty );
if ( ! $product_id || ! $qty ) {
continue;
}
$products[ $product_id ] = $qty;
}
return $products;
}