Ответы пользователя по тегу WooСommerce
  • Как проверить, оставил ли юзер отзывы на товары?

    gogowq
    @gogowq
    Ozh domosh acha ozh
    add_shortcode( 'customer_products', 'truemisha_products_current_user' );
    
    function truemisha_products_current_user() {
      // ничего не делаем, если не авторизован
      if ( ! is_user_logged_in() ) {
        return;
      }
    
      // получаем все оплаченные заказы пользователя
      $customer_orders = get_posts( array(
        'posts_per_page' => -1,
        'meta_key'    => '_customer_user',
        'meta_value'  => get_current_user_id(),
        'post_type'   => wc_get_order_types(),
        'post_status' => array_keys( wc_get_is_paid_statuses() ),
      ) );
    
      // если заказов не найдено
      if ( ! $customer_orders ) {
        return;
      }
    
      // создаём отдельную переменную для ID товаров и записываем в неё
      $ids = array();
      foreach ( $customer_orders as $customer_order ) {
        $order = wc_get_order( $customer_order->ID );
        $items = $order->get_items();
        foreach ( $items as $item ) {
          $product_id = $item->get_product_id();
          if ( ! has_reviewed_product( $product_id, get_current_user_id() ) ) {
            $ids[] = $product_id;
          }
        }
      }
    
      // если нет товаров без отзывов
      if ( empty( $ids ) ) {
        return;
      }
    
      // возвращаем шорткод
      return do_shortcode( '[products ids="' . join( ",", array_unique( $ids ) ) . '"]' );
    
    }
    Ответ написан
    1 комментарий
  • Как изменить текст кнопки в коде?

    gogowq
    @gogowq
    Ozh domosh acha ozh
    Если речь всё же о селекте,а не о кнопке. То
    add_filter( 'woocommerce_product_add_to_cart_text' , 'custom_woocommerce_product_add_to_cart_text' );
    function custom_woocommerce_product_add_to_cart_text() {
        global $product;    
        $product_type = $product->product_type;  
        switch ( $product_type ) {
    case 'variable':
                return __( 'Options', 'woocommerce' );
            break;
    }
    }


    Если о кнопке

    function my_custom_cart_button_text( $text, $product ) {
        if( $product->is_type( 'variable' ) ){
            $text = __('Buy Now', 'woocommerce');
        }
        return $text;
    }
    add_filter( 'woocommerce_product_single_add_to_cart_text', 'my_custom_cart_button_text', 10, 2 );
    Ответ написан
    Комментировать
  • Как перевести произвольные поля Buy one click WooCommerce на другой язык?

    gogowq
    @gogowq
    Ozh domosh acha ozh
    Разве у buy one click нет (po/mo)файлов внутри папки плагина в условном (language) ? Loco translate/ poedit в помощь .
    Ответ написан
  • Как сделать поиск по меткам товаров Woocommerce?

    gogowq
    @gogowq
    Ozh domosh acha ozh
    function include_tags_in_search( WP_Query $query ): void{
        $search_terms = $query->get( 's' );
    
        if ( $query->is_search() ) {
            global $the_original_paged;
            $the_original_paged = $query->get( 'paged' ) ? $query->get( 'paged' ) : 1;
            if ( ! $search_terms ) {
                 add_action( 'wp', function () use ( $query ) {
                 $query->set_404();
                 status_header( 404 );
                 nocache_headers();
                } );
            }
            $query->set( 'paged', null );
            $query->set( 'post_type', array( 'post', 'product' )  );
            $query->set( 'posts_per_page', SEARCH_GRID_COUNT_ITEMS );
        }
    }
    add_action( 'pre_get_posts', 'include_tags_in_search' );
    
    function add_posts_by_tags( $posts, WP_Query $query ): array {
        if ( $query->is_search() ) {
            global $the_original_paged;
            remove_filter( 'the_posts', 'add_posts_by_tags' );
            $posts_product_cat = new WP_Query( array(
             'posts_per_page' => -1,
             'tax_query' => array(
                  array(
                    'taxonomy' => 'product_tag',
                    'field'    => 'name',
                    'terms'    => explode( ' ', esc_attr( $query->get( 's' ) ) )
                  )
              )
            ) );
            $merged = array_unique( array_merge( $posts, $posts_product_cat->get_posts() ), SORT_REGULAR );
            $posts = array_slice( $merged, ( SEARCH_GRID_COUNT_ITEMS * ( $the_original_paged - 1 ) ), SEARCH_GRID_COUNT_ITEMS );
            $query->found_posts = $posts;
            $query->set( 'paged', $the_original_paged );
            $query->post_count = count( $posts );
            $query->max_num_pages = ceil( count( $merged ) / SEARCH_GRID_COUNT_ITEMS );
            unset( $the_original_paged );
            return $posts;
        }
    
        return $posts;
    }
    add_filter( 'the_posts', 'add_posts_by_tags', 10, 2 );


    Источник
    Ответ написан
    Комментировать
  • Как обновить пиратскую тему Wordpress на лицензионную без потери настроек?

    gogowq
    @gogowq
    Ozh domosh acha ozh
    Ну если ты все изменения вносил в Child тему своей нулленой темы,то можно обновляться.
    Условно просто обновить родительский шаблон с репозитория темы или автообновлениями(обычно нулленая тема ниже версией и автоматом будет предложено обновиться)
    Если же вносились изменения в род.тему,то в ручную перебирать все файлы после обновы.
    Желательно вынести все свои изменения в Child,чтоб можно было обновляться и в будущем.
    Ответ написан
    1 комментарий
  • Как правильно отобразить ссылку товара в woocommerce?

    gogowq
    @gogowq
    Ozh domosh acha ozh
    Если это CPT ,то можно поменять ЧПУ этим
    Ответ написан
    Комментировать
  • Как добавить вторую акционную цену для роли Woocommerce?

    gogowq
    @gogowq
    Ozh domosh acha ozh
    Если нужно по быстрому,то ставишь этот плагин и задаешь цену своим касмомным ролям.Вроде бы там ставиться оптовая цена под роль
    https://wordpress.org/plugins/premmerce-woocommerc...

    This plugin effectively works with the Premmerce User Roles plugin that allows you to easily create additional users’ roles directly from the dashboard.

    MAJOR FEATURES IN “PREMMERCE WHOLESALE PRICING FOR WOOCOMMERCE”
    adding wholesale prices
    adding custom prices
    Ответ написан
  • Как добавить новый статус публикации к продуктам на Woocommerce?

    gogowq
    @gogowq
    Ozh domosh acha ozh
    /**
     * Add 'Unread' post status.
     */
    function wpdocs_custom_post_status(){
        register_post_status( 'unread', array(
            'label'                     => _x( 'Unread', 'post' ),
            'public'                    => true,
            'exclude_from_search'       => false,
            'show_in_admin_all_list'    => true,
            'show_in_admin_status_list' => true,
            'label_count'               => _n_noop( 'Unread <span class="count">(%s)</span>', 'Unread <span class="count">(%s)</span>' ),
        ) );
    }
    add_action( 'init', 'wpdocs_custom_post_status' );


    https://developer.wordpress.org/reference/function...
    Ответ написан
    1 комментарий