is_inner_frame() ) { $templates = tve_dash_get_backbone_templates( TVE_TCB_ROOT_PATH . 'inc/woocommerce/views/backbone' ); tve_dash_output_backbone_templates( $templates, 'tve-woocommerce-' ); } } /** * Include WooCommerce editor components */ public static function tcb_output_components() { $path = TVE_TCB_ROOT_PATH . 'inc/woocommerce/views/components/'; $files = array_diff( scandir( $path ), [ '.', '..' ] ); foreach ( $files as $file ) { include $path . $file; } } /** * Initialize the rest api class */ public static function rest_api_init() { require_once TVE_TCB_ROOT_PATH . 'inc/woocommerce/classes/class-rest-api.php'; Rest_Api::register_routes(); } /** * Remove parenthesis from category count * * @param String $output * @param array $args * * @return string|string[] */ public static function wp_list_categories( $output, $args ) { if ( ! empty( $args['walker'] ) && $args['walker'] instanceof \WC_Product_Cat_List_Walker ) { $output = preg_replace( '/(class=\"count\"[^>]*>)\D*(\d*)[^<]*/', '$1$2', $output ); } return $output; } /** * Add some data to the frontend localized object * * @param $data * * @return mixed */ public static function tve_frontend_data( $data ) { $data['woo_rest_routes'] = array( 'shop' => get_rest_url( get_current_blog_id(), 'tcb/v1/woo/render_shop' ), 'product_categories' => get_rest_url( get_current_blog_id(), 'tcb/v1/woo/render_product_categories' ), 'product_variations' => get_rest_url( get_current_blog_id(), 'tcb/v1/woo/variations' ), ); return $data; } /** * Modifies the template content for headers/footers * * @param array $template_data * @param array $meta * @param boolean $do_shortcode * * @return array */ public static function tcb_alter_cloud_template_meta( $template_data, $meta, $do_shortcode ) { if ( ! is_array( $template_data ) ) { $template_data = []; } if ( $do_shortcode && in_array( $template_data['type'], [ 'header', 'footer' ] ) && ! empty( $template_data['content'] ) ) { /* the main reason for calling this is to render woo widgets such as Product Search which rely on __CONFIG__s */ $template_data['content'] = tve_thrive_shortcodes( $template_data['content'], is_editor_page_raw( true ) || \TCB_Utils::is_rest() ); } return $template_data; } /** * Don't load woocommerce if there are no elements used * * @param $styles * * @return mixed */ public static function woocommerce_enqueue_styles( $styles ) { /* Dequeue all woo scripts */ if ( \TCB\Lightspeed\Woocommerce::is_woocommerce_disabled() || \TCB\Lightspeed\Woocommerce::is_woocommerce_disabled( true ) ) { foreach ( $styles as $style_key => $style_data ) { if ( ! Main::needs_woo_enqueued() ) { unset( $styles[ $style_key ] ); } } } /* Deregister the woo blocks scripts */ if ( ! Main::needs_woo_enqueued() ) { wp_deregister_style( 'wc-blocks-style' ); wp_dequeue_style( 'wc-blocks-style' ); wp_deregister_style( 'wc-blocks-vendors-style' ); wp_dequeue_style( 'wc-blocks-vendors-style' ); } return $styles; } /** * Filter out undesired products based on the $extra argument * * @param $products * @param $request * * @return array|mixed */ public static function tcb_filter_products( $products, $request ) { $extra = $request->get_param( 'extra' ); if ( $extra === 'dynamic_add_to_cart' ) { $products = array_filter( $products, function ( $product ) { $full_product = wc_get_product( $product->ID ); return ! $full_product->is_type( 'external' ); } ); } return $products; } /** * Localize the woo modules if Woocommerce is active * * @param $data * * @return mixed */ public static function localize_woo_modules( $data ) { $data['lightspeed']['woo_modules'] = \TCB\Lightspeed\Woocommerce::get_woocommerce_assets( null, 'identifier' ); return $data; } /** * Check if posts has woo modules to include * * @param $post_id * @param $modules * * @return void */ public static function check_woo_modules_to_enqueue( $post_id, $modules ) { $woo_modules = get_post_meta( $post_id, Woocommerce::WOO_MODULE_META_NAME, true ); if ( ! empty( $woo_modules ) ) { add_filter( 'tcb_lightspeed_optimize_woo', '__return_true' ); static::enqueue_scripts(); Main::enqueue_scripts(); foreach ( Woocommerce::get_woo_styles() as $handle => $src ) { $media = strpos( $handle, 'smallscreen' ) === false ? 'all' : 'only screen and (max-width: 768px)'; wp_enqueue_style( $handle, $src, [], false, $media ); } } } /** * Do not display the hidden products when searching * * @param \WP_Query $query */ public static function pre_get_posts( $query ) { if ( $query->is_main_query() && $query->is_search() && isset( $_GET['tcb_sf_post_type'] ) && is_array( $_GET['tcb_sf_post_type'] ) && in_array( 'product', $_GET['tcb_sf_post_type'] ) ) { $tax_query = $query->get( 'tax_query', [] ); $tax_query[] = [ 'relation' => 'OR', [ 'taxonomy' => 'product_visibility', 'field' => 'name', 'terms' => 'exclude-from-catalog', 'operator' => 'NOT IN', ], [ 'taxonomy' => 'product_visibility', 'field' => 'name', 'terms' => 'exclude-from-catalog', 'operator' => '!=', ], ]; $query->set( 'tax_query', $tax_query ); } } }