Product_Components::render( $attributes, $instance )
Summary
No summary available.Source
File: src/BigCommerce/Shortcodes/Product_Components.php
public function render( $attributes, $instance ) { $attr = shortcode_atts( self::default_attributes(), $attributes, self::NAME ); if ( ! empty( $attr['id'] ) ) { // The $attr['id'] is the BC product ID try { $product = Product::by_product_id( absint( $attr['id'] ) ); } catch ( \Exception $e ) { return $this->product_not_found(); } } elseif ( ! empty( $attr['sku'] ) ) { try { $product = Product::by_product_sku( sanitize_text_field( $attr['sku'] ) ); } catch ( \Exception $e ) { return $this->product_not_found(); } } else { $post_id = empty( $attr['post_id'] ) ? get_the_ID() : absint( $attr['post_id'] ); if ( empty( $post_id ) || get_post_type( $post_id ) !== Product::NAME ) { return $this->product_not_found(); } $product = new Product( $post_id ); } switch ( $attr['type'] ) { case Components::SKU: $sku = Product_Sku::factory( [ Product_Description::PRODUCT => $product, ] ); return $sku->render(); case Components::DESCRIPTION: $description = Product_Description::factory( [ Product_Description::PRODUCT => $product, ] ); return $description->render(); case Components::IMAGE: $product_image = Product_Featured_Image::factory( [ Product_Featured_Image::PRODUCT => $product, Product_Featured_Image::SIZE => $this->image_size(), Product_Featured_Image::CLASSES => [ 'bc-component' ], ] ); return $product_image->render(); case Components::ADD_TO_CART: if ( $attr['preview'] ) { $product_form = Product_Form_Preview::factory( [ Product_Form::PRODUCT => $product, Product_Form::SHOW_OPTIONS => false, ] ); } else { $product_form = Product_Form::factory( [ Product_Form::PRODUCT => $product, ] ); } return $product_form->render(); default: $title_args = [ Product_Title::PRODUCT => $product, Product_Title::SHOW_CONDITION => false, Product_Title::SHOW_INVENTORY => false, ]; if ( $attr['preview'] ) { $title_args[ Product_Title::USE_PERMALINK ] = false; } $title = Product_Title::factory( $title_args ); return $title->render(); } }