Viewing 3 replies - 1 through 3 (of 3 total)
  • Thread Starter guezs

    (@guezs)

    I realized that the code just replace {{product_id}} with the product ID, so what I really need is a variation shortcode. I made a custom one.

    Thanks anyway ??

    Plugin Author Matt Pramschufer

    (@mattpramschufer)

    Awesome, glad you figured it out. I am also looking for other contributors if you wanted to submit a patch/update to be merged into core.

    Thread Starter guezs

    (@guezs)

    I’m not sure that this has to do with your plugin. This is the code I used:

    function variation_page_shortcode( $params ) {
      if ( ! isset( $params[ 'id' ] ) )
        return '';
    
      $ids = str_replace( " ", '', $params[ 'id' ] );
      $ids = explode( ",", $ids );
    
      foreach ( $ids as $id ) {
    	$variation = wc_get_product( (int) $id );
    
    	if ( ! $variation  ) {
    		return '';
    	} elseif ( 'variation' != $variation->product_type ) {
    		return '';
    	} else {
    		$product = wc_get_product( $variation->id );
    		$html = do_shortcode( '[product_page id="' . $product->id . '"]');
    	}
      }
    
      return $html;
    }
    
    add_shortcode( 'variation_page', 'variation_page_shortcode' );

    Then, in your plugin configuration I use:

    [product_page id=”{{product_id}}”]
    [variation_page id=”{{product_id}}”]

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Page product for variations’ is closed to new replies.