WordPress at Your Fingertips
function is not described

WC_Shortcodes::product_add_to_cart_url() public WC 1.0

Get the add to cart URL for a product.

{} It's a method of the class: WC_Shortcodes{}

No Hooks.

Return

String.

Usage

$result = WC_Shortcodes::product_add_to_cart_url( $atts );
$atts(array) (required)
Attributes.

Code of WC_Shortcodes::product_add_to_cart_url() WC 5.9.0

public static function product_add_to_cart_url( $atts ) {
	if ( empty( $atts ) ) {
		return '';
	}

	if ( isset( $atts['id'] ) ) {
		$product_data = get_post( $atts['id'] );
	} elseif ( isset( $atts['sku'] ) ) {
		$product_id   = wc_get_product_id_by_sku( $atts['sku'] );
		$product_data = get_post( $product_id );
	} else {
		return '';
	}

	$product = is_object( $product_data ) && in_array( $product_data->post_type, array( 'product', 'product_variation' ), true ) ? wc_setup_product_data( $product_data ) : false;

	if ( ! $product ) {
		return '';
	}

	$_product = wc_get_product( $product_data );

	return esc_url( $_product->add_to_cart_url() );
}