Edit File by line
/home/zeestwma/richards.../wp-conte.../plugins/woocomme.../includes
File: class-wc-embed.php
<?php
[0] Fix | Delete
/**
[1] Fix | Delete
* WooCommerce product embed
[2] Fix | Delete
*
[3] Fix | Delete
* @version 2.4.11
[4] Fix | Delete
* @package WooCommerce\Classes\Embed
[5] Fix | Delete
*/
[6] Fix | Delete
[7] Fix | Delete
use Automattic\WooCommerce\Enums\ProductType;
[8] Fix | Delete
[9] Fix | Delete
if ( ! defined( 'ABSPATH' ) ) {
[10] Fix | Delete
exit;
[11] Fix | Delete
}
[12] Fix | Delete
[13] Fix | Delete
/**
[14] Fix | Delete
* Embed Class which handles any WooCommerce Products that are embedded on this site or another site.
[15] Fix | Delete
*/
[16] Fix | Delete
class WC_Embed {
[17] Fix | Delete
[18] Fix | Delete
/**
[19] Fix | Delete
* Init embed class.
[20] Fix | Delete
*
[21] Fix | Delete
* @since 2.4.11
[22] Fix | Delete
*/
[23] Fix | Delete
public static function init() {
[24] Fix | Delete
[25] Fix | Delete
// Filter all of the content that's going to be embedded.
[26] Fix | Delete
add_filter( 'the_excerpt_embed', array( __CLASS__, 'the_excerpt' ), 10 );
[27] Fix | Delete
[28] Fix | Delete
// Make sure no comments display. Doesn't make sense for products.
[29] Fix | Delete
add_action( 'embed_content_meta', array( __CLASS__, 'remove_comments_button' ), 5 );
[30] Fix | Delete
[31] Fix | Delete
// In the comments place let's display the product rating.
[32] Fix | Delete
add_action( 'embed_content_meta', array( __CLASS__, 'get_ratings' ), 5 );
[33] Fix | Delete
[34] Fix | Delete
// Add some basic styles.
[35] Fix | Delete
add_action( 'embed_head', array( __CLASS__, 'print_embed_styles' ) );
[36] Fix | Delete
}
[37] Fix | Delete
[38] Fix | Delete
/**
[39] Fix | Delete
* Remove comments button on product embeds.
[40] Fix | Delete
*
[41] Fix | Delete
* @since 2.6.0
[42] Fix | Delete
*/
[43] Fix | Delete
public static function remove_comments_button() {
[44] Fix | Delete
if ( self::is_embedded_product() ) {
[45] Fix | Delete
remove_action( 'embed_content_meta', 'print_embed_comments_button' );
[46] Fix | Delete
}
[47] Fix | Delete
}
[48] Fix | Delete
[49] Fix | Delete
/**
[50] Fix | Delete
* Check if this is an embedded product - to make sure we don't mess up regular posts.
[51] Fix | Delete
*
[52] Fix | Delete
* @since 2.4.11
[53] Fix | Delete
* @return bool
[54] Fix | Delete
*/
[55] Fix | Delete
public static function is_embedded_product() {
[56] Fix | Delete
if ( function_exists( 'is_embed' ) && is_embed() && is_product() ) {
[57] Fix | Delete
return true;
[58] Fix | Delete
}
[59] Fix | Delete
return false;
[60] Fix | Delete
}
[61] Fix | Delete
[62] Fix | Delete
/**
[63] Fix | Delete
* Create the excerpt for embedded products - we want to add the buy button to it.
[64] Fix | Delete
*
[65] Fix | Delete
* @since 2.4.11
[66] Fix | Delete
* @param string $excerpt Embed short description.
[67] Fix | Delete
* @return string
[68] Fix | Delete
*/
[69] Fix | Delete
public static function the_excerpt( $excerpt ) {
[70] Fix | Delete
global $post;
[71] Fix | Delete
[72] Fix | Delete
// Get product.
[73] Fix | Delete
$_product = wc_get_product( get_the_ID() );
[74] Fix | Delete
[75] Fix | Delete
// Make sure we're only affecting embedded products.
[76] Fix | Delete
if ( self::is_embedded_product() ) {
[77] Fix | Delete
echo '<p><span class="wc-embed-price">' . $_product->get_price_html() . '</span></p>'; // WPCS: XSS ok.
[78] Fix | Delete
[79] Fix | Delete
if ( ! empty( $post->post_excerpt ) ) {
[80] Fix | Delete
ob_start();
[81] Fix | Delete
woocommerce_template_single_excerpt();
[82] Fix | Delete
$excerpt = ob_get_clean();
[83] Fix | Delete
}
[84] Fix | Delete
[85] Fix | Delete
// Add the button.
[86] Fix | Delete
$excerpt .= self::product_buttons();
[87] Fix | Delete
}
[88] Fix | Delete
return $excerpt;
[89] Fix | Delete
}
[90] Fix | Delete
[91] Fix | Delete
/**
[92] Fix | Delete
* Create the button to go to the product page for embedded products.
[93] Fix | Delete
*
[94] Fix | Delete
* @since 2.4.11
[95] Fix | Delete
* @return string
[96] Fix | Delete
*/
[97] Fix | Delete
public static function product_buttons() {
[98] Fix | Delete
$_product = wc_get_product( get_the_ID() );
[99] Fix | Delete
$buttons = array();
[100] Fix | Delete
$button = '<a href="%s" class="wp-embed-more wc-embed-button">%s</a>';
[101] Fix | Delete
[102] Fix | Delete
if ( $_product->is_type( ProductType::SIMPLE ) && $_product->is_purchasable() && $_product->is_in_stock() ) {
[103] Fix | Delete
$buttons[] = sprintf( $button, esc_url( add_query_arg( 'add-to-cart', get_the_ID(), wc_get_cart_url() ) ), esc_html__( 'Buy now', 'woocommerce' ) );
[104] Fix | Delete
}
[105] Fix | Delete
[106] Fix | Delete
$buttons[] = sprintf( $button, get_the_permalink(), esc_html__( 'Read more', 'woocommerce' ) );
[107] Fix | Delete
[108] Fix | Delete
return '<p>' . implode( ' ', $buttons ) . '</p>';
[109] Fix | Delete
}
[110] Fix | Delete
[111] Fix | Delete
/**
[112] Fix | Delete
* Prints the markup for the rating stars.
[113] Fix | Delete
*
[114] Fix | Delete
* @since 2.4.11
[115] Fix | Delete
*/
[116] Fix | Delete
public static function get_ratings() {
[117] Fix | Delete
// Make sure we're only affecting embedded products.
[118] Fix | Delete
if ( ! self::is_embedded_product() ) {
[119] Fix | Delete
return;
[120] Fix | Delete
}
[121] Fix | Delete
[122] Fix | Delete
$_product = wc_get_product( get_the_ID() );
[123] Fix | Delete
[124] Fix | Delete
if ( $_product && $_product->get_average_rating() > 0 ) {
[125] Fix | Delete
?>
[126] Fix | Delete
<div class="wc-embed-rating">
[127] Fix | Delete
<?php
[128] Fix | Delete
printf(
[129] Fix | Delete
/* translators: %s: average rating */
[130] Fix | Delete
esc_html__( 'Rated %s out of 5', 'woocommerce' ),
[131] Fix | Delete
esc_html( $_product->get_average_rating() )
[132] Fix | Delete
);
[133] Fix | Delete
?>
[134] Fix | Delete
</div>
[135] Fix | Delete
<?php
[136] Fix | Delete
}
[137] Fix | Delete
}
[138] Fix | Delete
[139] Fix | Delete
/**
[140] Fix | Delete
* Basic styling.
[141] Fix | Delete
*/
[142] Fix | Delete
public static function print_embed_styles() {
[143] Fix | Delete
if ( ! self::is_embedded_product() ) {
[144] Fix | Delete
return;
[145] Fix | Delete
}
[146] Fix | Delete
?>
[147] Fix | Delete
<style type="text/css">
[148] Fix | Delete
a.wc-embed-button {
[149] Fix | Delete
border-radius: 4px;
[150] Fix | Delete
border: 1px solid #ddd;
[151] Fix | Delete
box-shadow: 0px 1px 0 0px rgba(0, 0, 0, 0.05);
[152] Fix | Delete
display:inline-block;
[153] Fix | Delete
padding: .5em;
[154] Fix | Delete
}
[155] Fix | Delete
a.wc-embed-button:hover, a.wc-embed-button:focus {
[156] Fix | Delete
border: 1px solid #ccc;
[157] Fix | Delete
box-shadow: 0px 1px 0 0px rgba(0, 0, 0, 0.1);
[158] Fix | Delete
color: #999;
[159] Fix | Delete
text-decoration: none;
[160] Fix | Delete
}
[161] Fix | Delete
.wp-embed-excerpt p {
[162] Fix | Delete
margin: 0 0 1em;
[163] Fix | Delete
}
[164] Fix | Delete
.wc-embed-price {
[165] Fix | Delete
display: block;
[166] Fix | Delete
opacity: .75;
[167] Fix | Delete
font-weight: 700;
[168] Fix | Delete
margin-top: -.75em;
[169] Fix | Delete
}
[170] Fix | Delete
.wc-embed-rating {
[171] Fix | Delete
display: inline-block;
[172] Fix | Delete
}
[173] Fix | Delete
</style>
[174] Fix | Delete
<?php
[175] Fix | Delete
}
[176] Fix | Delete
}
[177] Fix | Delete
[178] Fix | Delete
WC_Embed::init();
[179] Fix | Delete
[180] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function