Edit File by line

Deprecated: str_replace(): Passing null to parameter #2 ($replace) of type array|string is deprecated in /home/sportsfever/public_html/filemanger/function.php on line 93
/home/sportsfe.../httpdocs/wp-conte.../themes/Divi/includes/builder/frontend.../theme-bu...
File: WoocommerceProductVariablePlaceholder.php
<?php
[0] Fix | Delete
[1] Fix | Delete
/**
[2] Fix | Delete
* Class ET_Theme_Builder_Woocommerce_Product_Variable_Placeholder
[3] Fix | Delete
*
[4] Fix | Delete
* Variable product class extension for displaying WooCommerce placeholder on Theme Builder
[5] Fix | Delete
*/
[6] Fix | Delete
class ET_Theme_Builder_Woocommerce_Product_Variable_Placeholder extends WC_Product_Variable {
[7] Fix | Delete
/**
[8] Fix | Delete
* Cached upsells id
[9] Fix | Delete
*
[10] Fix | Delete
* @since 4.0.10
[11] Fix | Delete
*
[12] Fix | Delete
* @var array
[13] Fix | Delete
*/
[14] Fix | Delete
protected static $tb_upsells_id;
[15] Fix | Delete
[16] Fix | Delete
/**
[17] Fix | Delete
* Cached product category ids
[18] Fix | Delete
*
[19] Fix | Delete
* @since 4.0.10
[20] Fix | Delete
*
[21] Fix | Delete
* @var array
[22] Fix | Delete
*/
[23] Fix | Delete
protected static $tb_category_ids;
[24] Fix | Delete
[25] Fix | Delete
/**
[26] Fix | Delete
* Cached product tag ids
[27] Fix | Delete
*
[28] Fix | Delete
* @since 4.0.10
[29] Fix | Delete
*
[30] Fix | Delete
* @var array
[31] Fix | Delete
*/
[32] Fix | Delete
protected static $tb_tag_ids;
[33] Fix | Delete
[34] Fix | Delete
/**
[35] Fix | Delete
* Cached attributes
[36] Fix | Delete
*
[37] Fix | Delete
* @since 4.0.10
[38] Fix | Delete
*
[39] Fix | Delete
* @var array
[40] Fix | Delete
*/
[41] Fix | Delete
protected static $tb_attributes;
[42] Fix | Delete
[43] Fix | Delete
/**
[44] Fix | Delete
* Create pre-filled WC Product (variable) object which acts as placeholder generator in TB
[45] Fix | Delete
*
[46] Fix | Delete
* @since 4.0.10 Instead of empty product object that is set later, pre-filled default data properties
[47] Fix | Delete
*
[48] Fix | Delete
* @param int|WC_Product|object $product Product to init.
[49] Fix | Delete
*/
[50] Fix | Delete
public function __construct( $product = 0 ) {
[51] Fix | Delete
// Pre-filled default data with placeholder value so everytime this product class is
[52] Fix | Delete
// initialized, it already has sufficient data to be displayed on Theme Builder
[53] Fix | Delete
$this->data = array(
[54] Fix | Delete
'name' => esc_html( 'Product name', 'et_builder' ),
[55] Fix | Delete
'slug' => 'product-name',
[56] Fix | Delete
'date_created' => current_time( 'timestamp' ),
[57] Fix | Delete
'date_modified' => null,
[58] Fix | Delete
'status' => 'publish',
[59] Fix | Delete
'featured' => false,
[60] Fix | Delete
'catalog_visibility' => 'visible',
[61] Fix | Delete
'description' => esc_html( 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Mauris bibendum eget dui sed vehicula. Suspendisse potenti. Nam dignissim at elit non lobortis. Cras sagittis dui diam, a finibus nibh euismod vestibulum. Integer sed blandit felis. Maecenas commodo ante in mi ultricies euismod. Morbi condimentum interdum luctus. Mauris iaculis interdum risus in volutpat. Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Praesent cursus odio eget cursus pharetra. Aliquam lacinia lectus a nibh ullamcorper maximus. Quisque at sapien pulvinar, dictum elit a, bibendum massa. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae; Mauris non pellentesque urna.', 'et_builder' ),
[62] Fix | Delete
'short_description' => esc_html( 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Mauris bibendum eget dui sed vehicula. Suspendisse potenti. Nam dignissim at elit non lobortis.', 'et_builder' ),
[63] Fix | Delete
'sku' => 'product-name',
[64] Fix | Delete
'price' => '75',
[65] Fix | Delete
'regular_price' => '80',
[66] Fix | Delete
'sale_price' => '65',
[67] Fix | Delete
'date_on_sale_from' => null,
[68] Fix | Delete
'date_on_sale_to' => null,
[69] Fix | Delete
'total_sales' => '0',
[70] Fix | Delete
'tax_status' => 'taxable',
[71] Fix | Delete
'tax_class' => '',
[72] Fix | Delete
'manage_stock' => true,
[73] Fix | Delete
'stock_quantity' => 50,
[74] Fix | Delete
'stock_status' => 'instock',
[75] Fix | Delete
'backorders' => 'no',
[76] Fix | Delete
'low_stock_amount' => 2,
[77] Fix | Delete
'sold_individually' => false,
[78] Fix | Delete
'weight' => 2,
[79] Fix | Delete
'length' => '',
[80] Fix | Delete
'width' => 2,
[81] Fix | Delete
'height' => 2,
[82] Fix | Delete
'upsell_ids' => array(),
[83] Fix | Delete
'cross_sell_ids' => array(),
[84] Fix | Delete
'parent_id' => 0,
[85] Fix | Delete
'reviews_allowed' => true,
[86] Fix | Delete
'purchase_note' => '',
[87] Fix | Delete
'attributes' => array(),
[88] Fix | Delete
'default_attributes' => array(),
[89] Fix | Delete
'menu_order' => 0,
[90] Fix | Delete
'post_password' => '',
[91] Fix | Delete
'virtual' => false,
[92] Fix | Delete
'downloadable' => false,
[93] Fix | Delete
'category_ids' => array(),
[94] Fix | Delete
'tag_ids' => array(),
[95] Fix | Delete
'shipping_class_id' => 0,
[96] Fix | Delete
'downloads' => array(),
[97] Fix | Delete
'image_id' => '',
[98] Fix | Delete
'gallery_image_ids' => array(),
[99] Fix | Delete
'download_limit' => -1,
[100] Fix | Delete
'download_expiry' => -1,
[101] Fix | Delete
'rating_counts' => array(
[102] Fix | Delete
4 => 2,
[103] Fix | Delete
),
[104] Fix | Delete
'average_rating' => '4.00',
[105] Fix | Delete
'review_count' => 2,
[106] Fix | Delete
'recent_product_ids' => null,
[107] Fix | Delete
);
[108] Fix | Delete
[109] Fix | Delete
parent::__construct( $product );
[110] Fix | Delete
}
[111] Fix | Delete
[112] Fix | Delete
/**
[113] Fix | Delete
* Get internal type.
[114] Fix | Delete
* Define custom internal type so custom data store can be used to bypass database value retrieval
[115] Fix | Delete
*
[116] Fix | Delete
* @since 4.0.10
[117] Fix | Delete
*
[118] Fix | Delete
* @return string
[119] Fix | Delete
*/
[120] Fix | Delete
public function get_type() {
[121] Fix | Delete
return 'tb-placeholder';
[122] Fix | Delete
}
[123] Fix | Delete
[124] Fix | Delete
/**
[125] Fix | Delete
* Get placeholder product as available variation. The method is basically identical to
[126] Fix | Delete
* `WC_Product_Variable->get_available_variation()` except for the checks which are removed
[127] Fix | Delete
* so placeholder value can be passed
[128] Fix | Delete
*
[129] Fix | Delete
* @since 4.3.3
[130] Fix | Delete
*
[131] Fix | Delete
* @param int|object $variation not needed since it will be overwritten by placeholder variation
[132] Fix | Delete
* but it needs to be kept for compatibility with base class' method
[133] Fix | Delete
*
[134] Fix | Delete
* @return array
[135] Fix | Delete
*/
[136] Fix | Delete
function get_available_variation( $variation = 0 ) {
[137] Fix | Delete
$variation = new ET_Theme_Builder_Woocommerce_Product_Variation_Placeholder();
[138] Fix | Delete
$show_variation_price = apply_filters( 'woocommerce_show_variation_price', $variation->get_price() === '' || $this->get_variation_sale_price( 'min' ) !== $this->get_variation_sale_price( 'max' ) || $this->get_variation_regular_price( 'min' ) !== $this->get_variation_regular_price( 'max' ), $this, $variation );
[139] Fix | Delete
[140] Fix | Delete
// Set variation id; Prevent $product->get_id() returns falsey which usually triggers wc_product_get()
[141] Fix | Delete
// in WC add ons; Valid $product->get_id() makes global $product being used most of the time
[142] Fix | Delete
$variation->set_id( $this->get_id() );
[143] Fix | Delete
[144] Fix | Delete
// Set current product id as variation parent id so $product->get_parent_id() returns
[145] Fix | Delete
// valid value (mostly when being called by WC add-ons). The absence of this value (in TB)
[146] Fix | Delete
// triggers new `wc_get_product()` which most likely returned unwanted output
[147] Fix | Delete
$variation->set_prop( 'parent_id', $this->get_id() );
[148] Fix | Delete
[149] Fix | Delete
// Returned array properties are identical to `WC_Product_Variable->get_available_variation()`
[150] Fix | Delete
return apply_filters(
[151] Fix | Delete
'woocommerce_available_variation',
[152] Fix | Delete
array(
[153] Fix | Delete
'attributes' => $variation->get_variation_attributes(),
[154] Fix | Delete
'availability_html' => wc_get_stock_html( $variation ),
[155] Fix | Delete
'backorders_allowed' => $variation->backorders_allowed(),
[156] Fix | Delete
'dimensions' => $variation->get_dimensions( false ),
[157] Fix | Delete
'dimensions_html' => wc_format_dimensions( $variation->get_dimensions( false ) ),
[158] Fix | Delete
'display_price' => wc_get_price_to_display( $variation ),
[159] Fix | Delete
'display_regular_price' => wc_get_price_to_display( $variation, array( 'price' => $variation->get_regular_price() ) ),
[160] Fix | Delete
'image' => wc_get_product_attachment_props( $variation->get_image_id() ),
[161] Fix | Delete
'image_id' => $variation->get_image_id(),
[162] Fix | Delete
'is_downloadable' => $variation->is_downloadable(),
[163] Fix | Delete
'is_in_stock' => $variation->is_in_stock(),
[164] Fix | Delete
'is_purchasable' => $variation->is_purchasable(),
[165] Fix | Delete
'is_sold_individually' => $variation->is_sold_individually() ? 'yes' : 'no',
[166] Fix | Delete
'is_virtual' => $variation->is_virtual(),
[167] Fix | Delete
'max_qty' => 0 < $variation->get_max_purchase_quantity() ? $variation->get_max_purchase_quantity() : '',
[168] Fix | Delete
'min_qty' => $variation->get_min_purchase_quantity(),
[169] Fix | Delete
'price_html' => $show_variation_price ? '<span class="price">' . $variation->get_price_html() . '</span>' : '',
[170] Fix | Delete
'sku' => $variation->get_sku(),
[171] Fix | Delete
'variation_description' => wc_format_content( $variation->get_description() ),
[172] Fix | Delete
'variation_id' => $variation->get_id(),
[173] Fix | Delete
'variation_is_active' => $variation->variation_is_active(),
[174] Fix | Delete
'variation_is_visible' => $variation->variation_is_visible(),
[175] Fix | Delete
'weight' => $variation->get_weight(),
[176] Fix | Delete
'weight_html' => wc_format_weight( $variation->get_weight() ),
[177] Fix | Delete
),
[178] Fix | Delete
$this,
[179] Fix | Delete
$variation
[180] Fix | Delete
);
[181] Fix | Delete
}
[182] Fix | Delete
[183] Fix | Delete
/**
[184] Fix | Delete
* Add to cart's <select> requires variable product type and get_available_variations() method
[185] Fix | Delete
* outputting product->children value. Filtering get_available_variations() can't be done so
[186] Fix | Delete
* extending WC_Product_Variable and set fixed value for get_available_variations() method
[187] Fix | Delete
*
[188] Fix | Delete
* @since 4.0.1
[189] Fix | Delete
* @since 4.3.3 `Replaced ET_Theme_Builder_Woocommerce_Product_Variable_Placeholder` with
[190] Fix | Delete
* `ET_Theme_Builder_Woocommerce_Product_Variation_Placeholder` (which is now called
[191] Fix | Delete
* at `get_available_variations()` method and similar to `WC_Product_Variation`'s
[192] Fix | Delete
* method with no check). It has all variation-required methods and properties
[193] Fix | Delete
* which makes it more reliable when WC add-ons are used
[194] Fix | Delete
*
[195] Fix | Delete
* @return array
[196] Fix | Delete
*/
[197] Fix | Delete
function get_available_variations() {
[198] Fix | Delete
return array(
[199] Fix | Delete
$this->get_available_variation(),
[200] Fix | Delete
);
[201] Fix | Delete
}
[202] Fix | Delete
[203] Fix | Delete
/**
[204] Fix | Delete
* Display Divi's placeholder image in WC image in TB
[205] Fix | Delete
*
[206] Fix | Delete
* @since 4.0.10
[207] Fix | Delete
*
[208] Fix | Delete
* @param string not used but need to be declared to prevent incompatible declaration error
[209] Fix | Delete
* @param array not used but need to be declared to prevent incompatible declaration error
[210] Fix | Delete
* @param bool not used but need to be declared to prevent incompatible declaration error
[211] Fix | Delete
*
[212] Fix | Delete
* @return string
[213] Fix | Delete
*/
[214] Fix | Delete
public function get_image( $size = 'woocommerce_thumbnail', $attr = array(), $placeholder = true ) {
[215] Fix | Delete
return et_builder_wc_placeholder_img();
[216] Fix | Delete
}
[217] Fix | Delete
[218] Fix | Delete
/**
[219] Fix | Delete
* Set product upsells id for TB's woocommerceComponent. This can't be called during class
[220] Fix | Delete
* initialization and need to be called BEFORE `woocommerce_product_class` filter callback
[221] Fix | Delete
* to avoid infinite loop
[222] Fix | Delete
*
[223] Fix | Delete
* @since 4.0.10
[224] Fix | Delete
*
[225] Fix | Delete
* @param array $args
[226] Fix | Delete
*/
[227] Fix | Delete
public static function set_tb_upsells_ids( $args = array() ) {
[228] Fix | Delete
$defaults = array(
[229] Fix | Delete
'limit' => 4,
[230] Fix | Delete
);
[231] Fix | Delete
$args = wp_parse_args( $args, $defaults );
[232] Fix | Delete
[233] Fix | Delete
// Get recent products for upsells product; Any product will do since its purpose is
[234] Fix | Delete
// for visual preview only
[235] Fix | Delete
$recent_products_query = new WC_Product_Query( $args );
[236] Fix | Delete
$recent_product_ids = array();
[237] Fix | Delete
[238] Fix | Delete
foreach( $recent_products_query->get_products() as $recent_product ) {
[239] Fix | Delete
$recent_product_ids[] = $recent_product->get_id();
[240] Fix | Delete
}
[241] Fix | Delete
[242] Fix | Delete
// Set up upsells id product
[243] Fix | Delete
self::$tb_upsells_id = $recent_product_ids;
[244] Fix | Delete
}
[245] Fix | Delete
[246] Fix | Delete
/**
[247] Fix | Delete
* Get upsells id
[248] Fix | Delete
*
[249] Fix | Delete
* @since 4.0.10
[250] Fix | Delete
*
[251] Fix | Delete
* @param string not used but need to be declared to prevent incompatible declaration error
[252] Fix | Delete
*
[253] Fix | Delete
* @return array
[254] Fix | Delete
*/
[255] Fix | Delete
public function get_upsell_ids( $context = 'view' ) {
[256] Fix | Delete
// Bypass database value retrieval and simply pulled cached value from property
[257] Fix | Delete
return is_array( self::$tb_upsells_id ) ? self::$tb_upsells_id : array();
[258] Fix | Delete
}
[259] Fix | Delete
[260] Fix | Delete
/**
[261] Fix | Delete
* Get attributes
[262] Fix | Delete
*
[263] Fix | Delete
* @since 4.0.10
[264] Fix | Delete
*
[265] Fix | Delete
* @param string not used but need to be declared to prevent incompatible declaration error
[266] Fix | Delete
*
[267] Fix | Delete
* @return array
[268] Fix | Delete
*/
[269] Fix | Delete
public function get_attributes( $context = 'view' ) {
[270] Fix | Delete
if ( ! is_null( self::$tb_attributes ) ) {
[271] Fix | Delete
return self::$tb_attributes;
[272] Fix | Delete
}
[273] Fix | Delete
[274] Fix | Delete
// Initialize color attribute
[275] Fix | Delete
$colors = new WC_Product_Attribute();
[276] Fix | Delete
$colors->set_id( 1 );
[277] Fix | Delete
$colors->set_name( 'color' );
[278] Fix | Delete
$colors->set_options( array( 'Black', 'White', 'Gray' ) );
[279] Fix | Delete
$colors->set_position( 1 );
[280] Fix | Delete
$colors->set_visible( 1 );
[281] Fix | Delete
$colors->set_variation( 1 );
[282] Fix | Delete
[283] Fix | Delete
// Initialize size attribute
[284] Fix | Delete
$sizes = new WC_Product_Attribute();
[285] Fix | Delete
$sizes->set_id( 2 );
[286] Fix | Delete
$sizes->set_name( 'size' );
[287] Fix | Delete
$sizes->set_options( array( 'S', 'M', 'L', 'XL' ) );
[288] Fix | Delete
$sizes->set_position( 1 );
[289] Fix | Delete
$sizes->set_visible( 1 );
[290] Fix | Delete
$sizes->set_variation( 1 );
[291] Fix | Delete
[292] Fix | Delete
self::$tb_attributes = array(
[293] Fix | Delete
'pa_color' => $colors,
[294] Fix | Delete
'pa_size' => $sizes,
[295] Fix | Delete
);
[296] Fix | Delete
[297] Fix | Delete
return self::$tb_attributes;
[298] Fix | Delete
}
[299] Fix | Delete
[300] Fix | Delete
/**
[301] Fix | Delete
* Get variation price
[302] Fix | Delete
*
[303] Fix | Delete
* @since 4.0.10
[304] Fix | Delete
*
[305] Fix | Delete
* @param bool not used but need to be declared to prevent incompatible declaration error
[306] Fix | Delete
*
[307] Fix | Delete
* @return array
[308] Fix | Delete
*/
[309] Fix | Delete
public function get_variation_prices( $for_display = false ) {
[310] Fix | Delete
return array(
[311] Fix | Delete
'price' => array( $this->data['price'] ),
[312] Fix | Delete
'regular_price' => array( $this->data['regular_price'] ),
[313] Fix | Delete
'sale_price' => array( $this->data['sale_price'] ),
[314] Fix | Delete
);
[315] Fix | Delete
}
[316] Fix | Delete
}
[317] Fix | Delete
[318] Fix | Delete
/**
[319] Fix | Delete
* Render default product variable add to cart UI for tb-placeholder product type
[320] Fix | Delete
*
[321] Fix | Delete
* @since 4.0.10
[322] Fix | Delete
*/
[323] Fix | Delete
add_action( 'woocommerce_tb-placeholder_add_to_cart', 'woocommerce_variable_add_to_cart', 30 );
[324] Fix | Delete
[325] Fix | Delete
[326] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function