) ); $product_ids = ! empty( $product_ids ) && is_array( $product_ids ) ? $product_ids : array(); $ignored_ids = ! empty( $ignored_ids ) && is_array( $ignored_ids ) ? $ignored_ids : array(); return array_merge( $ignored_ids, $product_ids ); } public function remove_generator_tag( $generator ) { $should_remove = (bool) smartcrawl_get_array_value( $this->get_options(), 'remove_generator_tag' ); if ( $should_remove ) { remove_filter( 'get_the_generator_html', 'wc_generator_tag' ); remove_filter( 'get_the_generator_xhtml', 'wc_generator_tag' ); } return $generator; } public function change_woo_status() { $data = $this->get_request_data(); if ( ! isset( $data['enable'] ) ) { wp_send_json_error(); return; } $options = get_option( Smartcrawl_Woocommerce_Data::OPTION_ID ); $options['woocommerce_enabled'] = ! empty( $data['enable'] ); update_option( Smartcrawl_Woocommerce_Data::OPTION_ID, $options ); wp_send_json_success(); } private function get_request_data() { return isset( $_POST['_wds_nonce'] ) && wp_verify_nonce( wp_unslash( $_POST['_wds_nonce'] ), 'wds-woo-nonce' ) ? stripslashes_deep( $_POST ) : array(); // phpcs:ignore } /** * @param array $markup Schema. * @param WC_Product $product Product. * * @return array */ public function remove_woocommerce_product_schema( $markup, $product ) { if ( $this->is_schema_disabled() ) { return $markup; } $schema_utils = Smartcrawl_Schema_Utils::get(); $product_post = get_post( $product->get_id() ); $schema_types = $schema_utils->get_custom_schema_types( $product_post ); foreach ( $schema_types as $type => $schema ) { if ( 'Product' === $type ) { return array(); } } return $markup; } /** * @param array $schema Schema. * @param WC_Product $product Product. * * @return array */ public function add_brand_to_woocommerce_schema( $schema, $product ) { $brand = $this->get_brand( $product ); if ( empty( $schema ) || empty( $brand ) ) { // We may have already removed the schema or there's no brand available. return $schema; } $schema['brand'] = array( '@type' => 'Brand', 'name' => $brand->name, 'url' => get_term_link( $brand ), ); return $schema; } private function is_schema_disabled() { $social = Smartcrawl_Settings::get_component_options( Smartcrawl_Settings::COMP_SOCIAL ); return ! empty( $social['disable-schema'] ) || ! Smartcrawl_Settings_Admin::is_tab_allowed( Smartcrawl_Settings::TAB_SCHEMA ); } /** * The following function belongs inside a Smartcrawl_Product class. * * @param WC_Product $product Product. * * @return WP_Term|bool */ public function get_brand( $product ) { $brand = smartcrawl_get_array_value( $this->get_options(), 'brand' ); if ( empty( $brand ) ) { return false; } $brands = get_the_terms( $product->get_id(), $brand ); return is_wp_error( $brands ) || empty( $brands[0] ) ? false : $brands[0]; } /** * @return bool */ private function woo_module_enabled() { return (bool) smartcrawl_get_array_value( $this->get_options(), 'woocommerce_enabled' ); } public function add_rules_to_robots_txt( $contents ) { $enabled = smartcrawl_get_array_value( $this->get_options(), 'add_robots' ); if ( ! $enabled ) { return $contents; } $parts = array( 'Disallow: /*add-to-cart=*', ); foreach ( array( 'cart', 'checkout', 'myaccount' ) as $page ) { $page_id = wc_get_page_id( $page ); if ( $page_id > 0 ) { $page_permalink = wc_get_page_permalink( $page ); $page_permalink_part = str_replace( home_url( '/' ), '/', $page_permalink ); $parts[] = "Disallow: $page_permalink_part"; } } if ( $parts ) { $contents .= "\n\n" . join( "\n", $parts ); } return $contents; } public function maybe_invalidate_sitemap_cache( $old_option, $new_option ) { $old_woo_status = smartcrawl_get_array_value( $old_option, 'woocommerce_enabled' ); $old_noindex_value = smartcrawl_get_array_value( $old_option, 'noindex_hidden_products' ); $old_noindex_status = $old_woo_status && $old_noindex_value; $new_woo_status = smartcrawl_get_array_value( $new_option, 'woocommerce_enabled' ); $new_noindex_value = smartcrawl_get_array_value( $new_option, 'noindex_hidden_products' ); $new_noindex_status = $new_woo_status && $new_noindex_value; if ( $old_noindex_status != $new_noindex_status ) { // phpcs:ignore Smartcrawl_Sitemap_Cache::get()->invalidate(); } } }