Per Ashish’s answer that’s been posted, below is the update code for clarification with the correct answer by switching add_to_cart_url()
to get_permalink()
:
global $product, $post;
$hasCustomization = get_post_meta( $post -> ID, '_wcm_custom_design_checkbox', true );
if ( $hasCustomization == 'on' ) {
echo apply_filters(
'woocommerce_loop_add_to_cart_link',
sprintf(
'<a href="https://wordpress.stackexchange.com/questions/237352/%s" rel="nofollow" data-product_id="https://wordpress.stackexchange.com/questions/237352/%s" data-product_sku="https://wordpress.stackexchange.com/questions/237352/%s" class="add_to_cart %s product_type_%s">%s</a>',
esc_url( $product -> get_permalink() ),
esc_attr( $product->id ),
esc_attr( $product->get_sku() ),
$product->is_purchasable() ? '' : '',to show
esc_attr( $product->product_type ),
esc_html( $product->add_to_cart_text() )// Custom Text
),
$product
);
}
else{
echo apply_filters(
'woocommerce_loop_add_to_cart_link',
sprintf(
'<a href="https://wordpress.stackexchange.com/questions/237352/%s" rel="nofollow" data-product_id="https://wordpress.stackexchange.com/questions/237352/%s" data-product_sku="https://wordpress.stackexchange.com/questions/237352/%s" class="add_to_cart %s product_type_%s">%s</a>',
esc_url( $product -> add_to_cart_url() ),
esc_attr( $product -> id ),
esc_attr( $product -> get_sku() ),
$product -> is_purchasable() ? 'add_to_cart_button' : '',
esc_attr( $product -> product_type ),
esc_html( $product -> add_to_cart_text() )
),
$product
);
}
?>