Woocomerce - How to Relate to Product Change?

I am trying to find a way to get a link to a specific product variant.

I thought I solved it with this plugin ... https://wordpress.org/plugins/woocommerce-direct-variation-link/

However, I have two product names attribute names and can't make it work? I put _, -, &, and + between two words, but don't go.

Here is the document ... In my case, I would have a "color style" instead of just a "color" mysite.com/product/happy-ninja/?color=blue

mysite.com/product/happy-ninja/?color=blue&size=small (additional options should be separated by '&')

mysite.com/product/happy-ninja/?color=blue+green (where the value of the option is "Blue Green" with a space replaced by a "+")

Thanks!

MrMO

+7
source share
8 answers

I tried so many solutions and plugins, but found a way to easily do this without a plugin. I'm not sure if this worked back in October 2015, but now it works.

I explained this in this YouTube video https://www.youtube.com/watch?v=Y_hMI4bXN6A

What you want to do is add something like "/? Attribute_color = red" behind your product.

website.com/shop/product1/?attribute_color=red
website.com/shop/product1/?attribute_length=10m

, , , . : (/) . , .

, , . , ( URL). , , URL.

:

: | ,

website.com/shop/product1/?attribute_color=red > will work
website.com/shop/product1/?attribute_Color=red > will not work
website.com/shop/product1/?attribute_color=Red > will not work
website.com/shop/product1/?attribute_color=Black > will work
website.com/shop/product1/?attribute_color=black > will not work

YouTube https://www.youtube.com/watch?v=Y_hMI4bXN6A

+7

, , , WooCommerce :

  1. → ( > ) - !

: http://website.com/product/product-name/?attribute_colours=Grey

, colours , , Grey - .

+ .

, & ?attribute_[slug]=Variation.

+4

Variation Swatches WooCommerce, , wordpress/woocommerce .

, , " " " " . . url, :

example.eg/product/product-name-slug/?attribute_pa_kids-size=27&attribute_pa_color=navy

?attribute_pa_ - slug ( ) = - slug slug (27, 28, , , ...). , URL-. , .

+2

, %20, ​​ url.

+1

:

$variation_product_url = $variation_product->get_permalink();

WooCommerce ; URL.

+1

HTML- , , - URL-:? attribute_YOUR_ID = YOUR_VALUE

, , &

:

website.com/shop/product1/?attribute_id_of_variable_combo=value_of_combo 
0

, , , , .

URL, URL.

:

URL :

domain.com/shop/product-x/?attribute_color=blue

URL- :

domain.com/shop/product-x/?attribute_pa_color=blue

- "pa_".

: , , , .

0

, , URL, .

, , attribute. - . , . :

enter image description here

, https://example.com/some_product/?attribute_pa_size=small

, , https://example.com/some_product/?attribute_pa_size=small&attribute_pa_color=red

, . woocommerce get_permalink, URL-. , ... WordPress / .

add_action( 'woocommerce_product_after_variable_attributes', 'gdy_add_wc_varition_permalink', 100, 3 ); 

function gdy_add_wc_varition_permalink( $loop, $variation_data, $variation ) {

    echo '<a href="' . get_permalink( $variation->ID ) . '" target="_blank">' . __( 'Permalink for this variation' ) . '</a>';

}
0
source

Source: https://habr.com/ru/post/1612151/


All Articles