diff --git a/includes/class-wc-embed.php b/includes/class-wc-embed.php new file mode 100644 index 0000000000000..4d40239d01c64 --- /dev/null +++ b/includes/class-wc-embed.php @@ -0,0 +1,162 @@ +get_product( get_the_ID() ); + + // add the price + $title = $title . '' . $_product->get_price_html() . ''; + } + return $title; + } + + /** + * Check if this is an embedded product - to make sure we don't mess up regular posts + * + * @return bool + */ + public static function is_embedded_product() { + if ( function_exists( 'is_embed' ) && is_embed() && is_product() ) { + return true; + } + return false; + } + + /** + * Create the excerpt for embedded products - we want to add the buy button to it + * + * @return string + */ + public static function the_excerpt( $excerpt ) { + // make sure we're only affecting embedded products + if ( WC_Embed::is_embedded_product() ) { + + // get product + $_pf = new WC_Product_Factory(); + $_product = $_pf->get_product( get_the_ID() ); + + // add the exerpt + $excerpt = wpautop( $excerpt ); + + // add the button + $excerpt .= WC_Embed::product_button(); + } + return $excerpt; + } + + /** + * Create the button to go to the product page for embedded products. + * + * @return string + */ + public static function product_button( ) { + $button = '%s →'; + return sprintf( $button, get_the_permalink(), __( 'View The Product', 'woocommerce' ) ); + } + + /** + * Returns number of comments for embedded products. Since we don't want the comment icon to show up we're going to return 0. + * + * @return string + */ + public static function get_comments_number( $comments ) { + // make sure we're only affecting embedded products + if ( WC_Embed::is_embedded_product() ) { + return 0; + } + return $comments; + } + + /** + * Returns whether or not comments are open Since we don't want the comment icon to show up we're going to return false. + * + * @return bool + */ + public static function comments_open( $comments_open ) { + // make sure we're only affecting embedded products + if ( WC_Embed::is_embedded_product() ) { + return false; + } + return $comments_open; + } +} + +WC_Embed::init(); diff --git a/woocommerce.php b/woocommerce.php index 0c0f60594a091..564e07f83df1c 100644 --- a/woocommerce.php +++ b/woocommerce.php @@ -266,6 +266,7 @@ public function frontend_includes() { include_once( 'includes/class-wc-customer.php' ); // Customer class include_once( 'includes/class-wc-shortcodes.php' ); // Shortcodes class include_once( 'includes/class-wc-https.php' ); // https Helper + include_once( 'includes/class-wc-embed.php' ); // Embeds } /**