Move and style the product price in oEmbeds for better display on handheld devices. closes #10584

This commit is contained in:
James Koster 2016-03-21 10:07:26 +00:00
parent beedd1c930
commit cbb8fa9c66
1 changed files with 9 additions and 22 deletions

View File

@ -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.
@ -42,26 +41,6 @@ class WC_Embed {
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.
*
@ -85,8 +64,13 @@ class WC_Embed {
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();
@ -161,7 +145,10 @@ class WC_Embed {
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;