Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- // ativando suporte do tema ao woocommerce
- add_theme_support( 'woocommerce' );
- // Ativando galeria padrão do Woo
- //add_theme_support( 'wc-product-gallery-zoom' );
- add_theme_support( 'wc-product-gallery-lightbox' );
- add_theme_support( 'wc-product-gallery-slider' );
- // remove as tabs de informações necessárias do produto
- add_filter( 'woocommerce_product_tabs', 'woo_remove_product_tabs', 98 );
- function woo_remove_product_tabs( $tabs ) {
- unset( $tabs['description'] ); // Remove the description tab
- //unset( $tabs['reviews'] ); // Remove the reviews tab
- unset( $tabs['additional_information'] ); // Remove the additional information tab
- return $tabs;
- }
- /**
- * Set WooCommerce image dimensions upon theme activation
- */
- // Remove each style one by one
- add_filter( 'woocommerce_enqueue_styles', 'jk_dequeue_styles' );
- function jk_dequeue_styles( $enqueue_styles ) {
- unset( $enqueue_styles['woocommerce-general'] ); // Remove the gloss
- unset( $enqueue_styles['woocommerce-layout'] ); // Remove the layout
- unset( $enqueue_styles['woocommerce-smallscreen'] ); // Remove the smallscreen optimisation
- return $enqueue_styles;
- }
- // Or just remove them all in one line
- add_filter( 'woocommerce_enqueue_styles', '__return_false' );
- /** Mostrar imagem da categoria **/
- function woocommerce_category_image() {
- global $wp_query;
- $taxonomy = $wp_query->get_queried_object();
- $taxonomy_image_desktop = wp_get_attachment_image_src(get_field('desktop', $taxonomy), 'full');
- $taxonomy_image_mobile = wp_get_attachment_image_src(get_field('mobile', $taxonomy), 'full');
- $taxonomy_image_link = esc_url(get_field('link', $taxonomy));
- if ($taxonomy_image_link) {
- echo '<a class="main-slider__link" href="' . $taxonomy_image_link . '">';
- }
- if ($taxonomy_image_desktop && $taxonomy_image_mobile) {
- echo '<picture class="taxonomy_image">';
- echo '<source media="(max-width: 500px)" srcset="' . $taxonomy_image_mobile[0] . '" alt="' . $taxonomy->name . '">';
- echo '<img src="' . $taxonomy_image_desktop[0] . '" alt="' . $taxonomy->name . '">';
- echo '</picture>';
- } elseif ($taxonomy_image_desktop) {
- echo '<img class="taxonomy_image" src="' . $taxonomy_image_desktop . '" alt="' . $taxonomy->name . '" />';
- }
- if ($taxonomy_image_link) {
- echo '</a>';
- }
- }
- // Não lista categorias "vazias" no Widget de produtos WooComerce
- function woo_hide_product_categories_widget( $list_args )
- {
- $list_args[ 'hide_empty' ] = 1;
- return $list_args;
- }
- add_filter( 'woocommerce_product_categories_widget_args', 'woo_hide_product_categories_widget' );
- // troca a mensagem EM ESTOQUE
- add_filter( 'woocommerce_get_availability', 'custom_get_availability', 1, 2);
- function custom_get_availability( $availability, $_product ) {
- //change text "In Stock' to 'SPECIAL ORDER'
- if ( $_product->is_in_stock() ) $availability['availability'] = __('Disponível', 'woocommerce');
- //change text "Out of Stock' to 'SOLD OUT'
- if ( !$_product->is_in_stock() ) $availability['availability'] = __('Fora de Estoque', 'woocommerce');
- return $availability;
- }
- // Change number of products that are displayed per page (shop page)
- add_filter( 'loop_shop_per_page', 'new_loop_shop_per_page', 20 );
- function new_loop_shop_per_page( $cols ) {
- // $cols contém o número atual de produtos por página com base no valor armazenado em opções-> leitura
- // Retorne o número de produtos que você deseja mostrar por página.
- $cols = 30;
- return $cols;
- }
- // campo bairro obrigatório no woocommerce
- function custom_wcbcf_billing_fields( $fields ) {
- $fields['billing_neighborhood']['required'] = true;
- return $fields;
- }
- add_filter( 'wcbcf_billing_fields', 'custom_wcbcf_billing_fields' );
- function custom_wcbcf_shipping_fields( $fields ) {
- $fields['shipping_neighborhood']['required'] = true;
- return $fields;
- }
- add_filter( 'wcbcf_shipping_fields', 'custom_wcbcf_shipping_fields' );
- /**
- * Campo de telefone obrigatório
- */
- function checkout_fields_phone_required( $fields ) {
- $fields['billing_phone']['required'] = true;
- return $fields;
- }
- add_filter( 'woocommerce_billing_fields', 'checkout_fields_phone_required' );
- /**
- * Remove a imagem de categoria padrão do woocommerce
- */
- //add_action('admin_head', 'my_custom_fonts');
- function my_custom_fonts() {
- echo '
- <style>
- .term-thumbnail-wrap {
- display: none;
- }
- </style>';
- }
- // atualizar o carrinho automaticamente
- add_action( 'wp_footer', 'bbloomer_cart_refresh_update_qty' );
- function bbloomer_cart_refresh_update_qty() {
- if (is_cart()) {
- ?>
- <script type="text/javascript">
- jQuery('div.woocommerce').on('click', 'input.qty', function(){
- jQuery("[name='update_cart']").trigger("click");
- });
- </script>
- <?php
- }
- }
- // Calcula o parcelamento
- add_action('woocommerce_after_shop_loop_item_title', 'product_parceled_price', 20);
- add_action('woocommerce_single_product_summary', 'product_parceled_price', 11);
- function product_parceled_price() {
- $product = wc_get_product();
- $html = '<div class="installments">';
- if ( wc_get_price_including_tax($product) > $valor_min_compra ) {
- $value = wc_price( wc_get_price_including_tax($product) / 6 );
- $html .= '<span class="installments_prefix">ou até 6x de </span>' . $value;
- }
- $html .= '</div>';
- echo $html;
- }
- /**
- * Remove produtos que a variação não tem em estoque
- * @see https://github.com/woocommerce/woocommerce/issues/20689
- */
- add_action( 'woocommerce_before_shop_loop_item_title', 'remove_out_of_stock_products_from_active_filter' );
- function remove_out_of_stock_products_from_active_filter(){
- if (isset($_GET['filter_tamanho'])) {
- global $product;
- if ($product->is_type('variable')) {
- $variations = $product->get_available_variations();
- $is_available = false;
- foreach ($variations as $variation) {
- if (isset($variation['attributes']['attribute_pa_tamanho'])) {
- if ($variation['attributes']['attribute_pa_tamanho'] == $_GET['filter_tamanho'] && $variation['is_in_stock']){
- $is_available = true;
- }
- }
- }
- if (!$is_available) {
- global $product;
- $id = $product->get_id();
- echo "
- <style>
- .woocommerce-result-count { visibility: hidden }
- .post-$id { display: none !important }
- .woocommerce-pagination { display: none !important }
- </style>
- ";
- }
- }
- }
- }
- // adiciona tag de desconto
- add_action( 'woocommerce_before_shop_loop_item_title', 'product_sale_percentage', 0 );
- add_action( 'woocommerce_single_product_summary', 'product_sale_percentage', 6 );
- function product_sale_percentage() {
- $product = wc_get_product();
- $is_sale = $product->is_on_sale();
- if ( $product->is_on_sale() ) {
- if ( $product->is_type( 'variable' ) ) {
- $percentage = round( ( ( $product->get_variation_regular_price('max') - $product->get_variation_sale_price('max') ) / $product->get_variation_regular_price('max') ) * 100 );
- echo '<span class="product-on-sale-percentage-tag">' . $percentage . '% OFF</span>';
- }
- if ( $product->is_type( 'simple' ) ) {
- $percentage = round( ( ( $product->get_regular_price() - $product->get_sale_price() ) / $product->get_regular_price() ) * 100 );
- echo '<span class="product-on-sale-percentage-tag">' . $percentage . '% OFF</span>';
- }
- }
- }
- // adiciona a tag de fora de estoque
- add_action( 'woocommerce_before_shop_loop_item_title', function() {
- global $product;
- if ($product->managing_stock() && !$product->is_in_stock() ) {
- echo '<span class="product_out_of_stock_label">Fora de estoque</span>';
- }
- });
- // remove a necessidade de senha forte para clientes woocommerce
- function fa_remove_password_strength() {
- wp_dequeue_script( 'wc-password-strength-meter' );
- wp_deregister_script( 'wc-password-strength-meter' );
- }
- add_action( 'wp_enqueue_scripts', 'fa_remove_password_strength', 99999 );
- /**
- * Adiciona desconto baseado nos produtos do carrinho
- */
- function add_cart_fee_based_on_products($cart_object) {
- global $woocommerce;
- $fee_products = array(74445, 70749, 74496, 72872);
- $fee_percent = 25;
- $cart_products = array();
- foreach ($cart_object->cart_contents as $key => $value) {
- $cart_products[] = $value['product_id'];
- }
- $cart_has_fee_preducts = count(array_intersect($fee_products, $cart_products)) == count($fee_products);
- if ($cart_has_fee_preducts) {
- $fee_value = ($woocommerce->cart->cart_contents_total + $woocommerce->cart->shipping_total ) * ($fee_percent / 100) * -1;
- $woocommerce->cart->add_fee('Desconto de 25% dia dos Namorados.)', $fee_value, true, 'standard');
- }
- }
- add_action('woocommerce_cart_calculate_fees', 'add_cart_fee_based_on_products');
- // corrige o breadcrumb na single do produto
- add_filter( 'wpseo_breadcrumb_single_link' ,'wpseo_remove_breadcrumb_link', 10 ,2);
- function wpseo_remove_breadcrumb_link( $link_output , $link ){
- $text_to_remove = 'Produtos';
- if( $link['text'] == $text_to_remove ) {
- $link_output = '';
- }
- return $link_output;
- }
- // Remove o cross sell
- remove_action( 'woocommerce_cart_collaterals', 'woocommerce_cross_sell_display' );
- // Adiciona ele em outro lugar
- add_action( 'woocommerce_after_cart', 'woocommerce_cross_sell_display', 50 );
- /**
- * Remove produtos fora de estoque do cross sell
- * @See https://github.com/woocommerce/woocommerce/blob/444dffdda27750b98ce1517d5f6f4d8153c53967/includes/class-wc-cart.php#L817
- */
- add_filter('woocommerce_cart_crosssell_ids', 'remove_out_of_stock_from_crosssell', 10, 1 );
- function remove_out_of_stock_from_crosssell( $wp_parse_id_list ){
- if (!empty($wp_parse_id_list)) {
- foreach ($wp_parse_id_list as $product_id) {
- $product = wc_get_product($product_id);
- // Verifica de o produto esta fora de estoque
- if ( $product->managing_stock() && !$product->is_in_stock() ) {
- // Remove o produto da listagem
- if (($key = array_search($product_id, $wp_parse_id_list)) !== false) {
- unset($wp_parse_id_list[$key]);
- }
- }
- }
- }
- return $wp_parse_id_list;
- }
- /**
- * Ordena produtos fora de estoque no final do catálogo
- * source: https://stackoverflow.com/a/44597448
- */
- add_filter('posts_clauses', 'order_by_stock_status');
- function order_by_stock_status($posts_clauses) {
- global $wpdb;
- // only change query on WooCommerce loops
- if (is_woocommerce() && (is_shop() || is_product_category() || is_product_tag() || is_product_taxonomy())) {
- $posts_clauses['join'] .= " INNER JOIN $wpdb->postmeta istockstatus ON ($wpdb->posts.ID = istockstatus.post_id) ";
- $posts_clauses['orderby'] = " istockstatus.meta_value ASC, " . $posts_clauses['orderby'];
- $posts_clauses['where'] = " AND istockstatus.meta_key = '_stock_status' AND istockstatus.meta_value <> '' " . $posts_clauses['where'];
- }
- return $posts_clauses;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement