' . $_product->get_price_html() . ''; } return $title; } /** * Check if this is an embedded product - to make sure we don't mess up regular posts. * * @since 2.4.11 * @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. * * @since 2.4.11 * @param string $excerpt Embed short description. * @return string */ public static function the_excerpt( $excerpt ) { global $post; // Make sure we're only affecting embedded products. if ( self::is_embedded_product() ) { if ( ! empty( $post->post_excerpt ) ) { ob_start(); woocommerce_template_single_excerpt(); $excerpt = ob_get_clean(); } // Add the button. $excerpt .= self::product_buttons(); } return $excerpt; } /** * Create the button to go to the product page for embedded products. * * @since 2.4.11 * @return string */ public static function product_buttons() { $_product = wc_get_product( get_the_ID() ); $buttons = array(); $button = '%s'; if ( $_product->is_type( 'simple' ) && $_product->is_purchasable() && $_product->is_in_stock() ) { $buttons[] = sprintf( $button, esc_url( add_query_arg( 'add-to-cart', get_the_ID(), wc_get_cart_url() ) ), esc_html__( 'Buy Now', 'woocommerce' ) ); } $buttons[] = sprintf( $button, get_the_permalink(), esc_html__( 'Read More', 'woocommerce' ) ); return '

' . implode( ' ', $buttons ) . '

'; } /** * Prints the markup for the rating stars. * * @since 2.4.11 */ public static function get_ratings() { // Make sure we're only affecting embedded products. if ( self::is_embedded_product() && ( $_product = wc_get_product( get_the_ID() ) ) && $_product->get_average_rating() > 0 ) { ?>
get_average_rating() ) ); ?>