Skip to content

Commit

Permalink
Move and style the product price in oEmbeds for better display on han…
Browse files Browse the repository at this point in the history
…dheld devices. closes woocommerce#10584
  • Loading branch information
jameskoster committed Mar 21, 2016
1 parent beedd1c commit cbb8fa9
Showing 1 changed file with 9 additions and 22 deletions.
31 changes: 9 additions & 22 deletions includes/class-wc-embed.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ class WC_Embed {
public static function init() {

// Filter all of the content that's going to be embedded.
add_filter( 'the_title', array( __CLASS__, 'the_title' ), 10 );
add_filter( 'the_excerpt_embed', array( __CLASS__, 'the_excerpt' ), 10 );

// Make sure no comments display. Doesn't make sense for products.
Expand All @@ -42,26 +41,6 @@ public static function init() {
add_action( 'embed_head', array( __CLASS__, 'print_embed_styles' ) );
}

/**
* Create the title for embedded products - we want to add the price to it.
*
* @since 2.4.11
* @param string $title Embed title.
* @return string
*/
public static function the_title( $title ) {
// Make sure we're only affecting embedded products.
if ( self::is_embedded_product() ) {

// Get product.
$_product = wc_get_product( get_the_ID() );

// Add the price.
$title = $title . '<span class="wc-embed-price">' . $_product->get_price_html() . '</span>';
}
return $title;
}

/**
* Check if this is an embedded product - to make sure we don't mess up regular posts.
*
Expand All @@ -85,8 +64,13 @@ public static function is_embedded_product() {
public static function the_excerpt( $excerpt ) {
global $post;

// Get product.
$_product = wc_get_product( get_the_ID() );

// Make sure we're only affecting embedded products.
if ( self::is_embedded_product() ) {
echo '<p><span class="wc-embed-price">' . $_product->get_price_html() . '</span></p>';

if ( ! empty( $post->post_excerpt ) ) {
ob_start();
woocommerce_template_single_excerpt();
Expand Down Expand Up @@ -161,7 +145,10 @@ public static function print_embed_styles() {
margin: 0 0 1em;
}
.wc-embed-price {
float:right;
display: block;
opacity: .75;
font-weight: 700;
margin-top: -.75em;
}
.wc-embed-rating {
display: inline-block;
Expand Down

0 comments on commit cbb8fa9

Please sign in to comment.