set($_POST['compare_empty_text']) ? $_POST['compare_empty_text'] : '', 'remove_from_compare_text' => isset($_POST['remove_text']) ? sanitize_text_field($_POST['remove_text']) : '', 'element_addcart_simple_txt' => isset($_POST['element_addcart_simple_txt']) ? $_POST['element_addcart_simple_txt'] : '', 'element_addcart_grouped_txt' => isset($_POST['element_addcart_grouped_txt']) ? $_POST['element_addcart_grouped_txt'] : '', 'element_addcart_variable_txt' => isset($_POST['element_addcart_variable_txt']) ? $_POST['element_addcart_grouped_txt'] : '' ]; if ($user_id > 0) { $compare = get_user_meta( get_current_user_id(), 'wpr_compare', true ); if ( ! $compare ) { $compare = array(); } } else { $compare = $this->get_compare_from_cookie(); } if ( ! $compare ) { $table_hidden = 'wpr-hidden-element'; } else { $notification_hidden = 'wpr-hidden-element'; } ob_start(); echo '

'. $settings['compare_empty_text'] .'

'; // Start the table echo '
'; echo ''; // Create the first row of table headers echo ''; echo ''; // Blank space for top-left corner foreach ( $compare as $product_id ) { $product = wc_get_product( $product_id ); if ( ! $product ) { continue; } echo ''; } echo ''; // Create the remaining rows of the table $table_data = array( ['label' => esc_html__('Image', 'wpr-addons'), 'type' => 'image'], ['label' => esc_html__('Name', 'wpr-addons'), 'type' => 'text'], ['label' => esc_html__('Rating', 'wpr-addons'), 'type' => 'text'], ['label' => esc_html__('Description', 'wpr-addons'), 'type' => 'text'], ['label' => esc_html__('Price', 'wpr-addons'), 'type' => 'text'], ['label' => esc_html__('SKU', 'wpr-addons'), 'type' => 'text'], ['label' => esc_html__('Stock Status', 'wpr-addons'), 'type' => 'text'], ['label' => esc_html__('Dimensions', 'wpr-addons'), 'type' => 'text'], ['label' => esc_html__('Weight', 'wpr-addons'), 'type' => 'text'] ); $all_attributes = array(); foreach ( $compare as $product_id ) { $product = wc_get_product( $product_id ); if ( ! $product ) { continue; } $attributes = $product->get_attributes(); foreach ( $attributes as $attribute ) { $attribute_name = wc_attribute_label($attribute->get_name()); if ( !in_array($attribute_name, $all_attributes) ) { $all_attributes[] = $attribute_name; } } } foreach ( $all_attributes as $attribute_name ) { $table_data[] = array('label' => $attribute_name, 'type' => 'text'); } foreach ( $table_data as $row ) { echo ''; echo ''; foreach ( $compare as $key => $product_id ) { $product = wc_get_product( $product_id ); if ( ! $product ) { continue; } echo ''; } echo ''; } // Close the table echo '
' . $row['label'] . ''; switch ( $row['type'] ) { case 'image': echo '' . $product->get_image() . ''; echo '
' . $this->render_product_add_to_cart( $settings, $product ) . '
'; break; case 'text': if( in_array(strtolower($row['label']), ['description', 'sku']) ) { echo $product->get_data()[strtolower($row['label'])]; } else if ( strtolower($row['label']) == 'name' ) { echo ''. $product->get_data()[strtolower($row['label'])] .''; } else if ( strtolower($row['label']) == 'price' ) { echo $product->get_price_html(); } else if ( strtolower($row['label']) == 'rating' ) { $this->render_product_rating($product); } else if ( strtolower($row['label']) == 'stock status' ) { $stock_status = $product->get_stock_status(); echo $stock_status == 'instock' ? esc_html__('In Stock', 'wpr-addons') : esc_html__('Out of Stock', 'wpr-addons'); } else if ( strtolower($row['label']) == 'dimensions' ) { if ( $product->has_dimensions() ) { $dimensions = sprintf( '%s', wc_format_dimensions( $product->get_dimensions( false ) ) ); echo $dimensions; } } else if ( strtolower($row['label']) == 'weight' ) { if ( $product->get_weight() ) { $weight = sprintf( '%s %s', $product->get_weight(), get_option( 'woocommerce_weight_unit' ) ); echo $weight; } } else { $attributes = $product->get_attributes(); $attribute_name = wc_attribute_label(strtolower($row['label'])); foreach ($product->get_attributes($product_id) as $attr) { if ( strtolower($attr['name']) === strtolower($row['label']) ) { echo $attr['value']; } } // Product Attributes if (isset($attributes['pa_'.$attribute_name])) { // Get the value(s) of the 'dimensions' attribute for the product $attributes_value = $attributes['pa_'.$attribute_name]->get_options(); $attributes_value_array = []; // Loop through the values and output them foreach ($attributes_value as $value) { $term = get_term($value); $attributes_value_array[] = $term->name; } echo implode(' | ', $attributes_value_array); } } break; } echo '
'; echo '
'; return ob_get_clean(); } public function render_product_rating($product) { // $rating_count = $product->get_rating_count(); // $rating_amount = floatval( $product->get_average_rating() ); // $round_rating = (int)$rating_amount; // $rating_icon = '☆'; // echo '
'; // for ( $i = 1; $i <= 5; $i++ ) { // if ( $i <= $rating_amount ) { // echo ''. $rating_icon .''; // } elseif ( $i === $round_rating + 1 && $rating_amount !== $round_rating ) { // echo ''. $rating_icon .''; // } else { // echo ''. $rating_icon .''; // } // } // echo '
'; // Another option $rating = $product->get_average_rating(); $count = $product->get_rating_count(); return wc_get_rating_html( $rating, $count ); } // Render Add To Cart public function render_product_add_to_cart( $settings, $product ) { // If NOT a Product if ( is_null( $product ) ) { return; } ob_start(); // Get Button Class $button_class = implode( ' ', array_filter( [ 'product_type_'. $product->get_type(), $product->is_purchasable() && $product->is_in_stock() ? 'add_to_cart_button' : '', $product->supports( 'ajax_add_to_cart' ) ? 'ajax_add_to_cart' : '', ] ) ); $attributes = [ 'rel="nofollow"', 'class="'. esc_attr($button_class) .' wpr-button-effect '. (!$product->is_in_stock() && 'simple' === $product->get_type() ? 'wpr-atc-not-clickable' : '').'"', 'aria-label="'. esc_attr($product->add_to_cart_description()) .'"', 'data-product_id="'. esc_attr($product->get_id()) .'"', 'data-product_sku="'. esc_attr($product->get_sku()) .'"', ]; $button_HTML = ''; $page_id = get_queried_object_id(); // Button Text if ( 'simple' === $product->get_type() ) { $button_HTML .= $settings['element_addcart_simple_txt']; if ( 'yes' === get_option('woocommerce_enable_ajax_add_to_cart') ) { array_push( $attributes, 'href="'. esc_url( get_permalink( $page_id ) .'/?add-to-cart='. get_the_ID() ) .'"' ); } else { array_push( $attributes, 'href="'. esc_url( get_permalink() ) .'"' ); } } elseif ( 'grouped' === $product->get_type() ) { $button_HTML .= $settings['element_addcart_grouped_txt']; array_push( $attributes, 'href="'. esc_url( $product->get_permalink() ) .'"' ); } elseif ( 'variable' === $product->get_type() ) { $button_HTML .= $settings['element_addcart_variable_txt']; array_push( $attributes, 'href="'. esc_url( $product->get_permalink() ) .'"' ); } else { array_push( $attributes, 'href="'. esc_url( $product->get_product_url() ) .'"' ); $button_HTML .= get_post_meta( get_the_ID(), '_button_text', true ) ? get_post_meta( get_the_ID(), '_button_text', true ) : 'Buy Product'; } // Button HTML echo ''. $button_HTML .''; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped return \ob_get_clean(); } } new WPR_Count_Wishlist_Compare_Items();
Fatal error: Uncaught Error: Class "Automattic\WooCommerce\Blocks\BlockTypes\CartCrossSellsProductsBlock" not found in /htdocs/wp-content/plugins/woocommerce/src/Blocks/BlockTypesController.php:106 Stack trace: #0 /htdocs/wp-includes/class-wp-hook.php(324): Automattic\WooCommerce\Blocks\BlockTypesController->register_blocks('') #1 /htdocs/wp-includes/class-wp-hook.php(348): WP_Hook->apply_filters(NULL, Array) #2 /htdocs/wp-includes/plugin.php(517): WP_Hook->do_action(Array) #3 /htdocs/wp-settings.php(727): do_action('init') #4 /htdocs/wp-config.php(98): require_once('/htdocs/wp-sett...') #5 /htdocs/wp-load.php(50): require_once('/htdocs/wp-conf...') #6 /htdocs/wp-blog-header.php(13): require_once('/htdocs/wp-load...') #7 /htdocs/index.php(17): require('/htdocs/wp-blog...') #8 {main} thrown in /htdocs/wp-content/plugins/woocommerce/src/Blocks/BlockTypesController.php on line 106