YITH plugin and WooCommerce filter and hook support

YITH plugin and WooCommerce filter and hook support
YITH plugin and WooCommerce filter and hook support

Woocommerce là plugin gì?

Woocommerce là một plugin miễn phí được sử dụng để tạo một trang thương mại điện tử cỡ nhỏ tốt nhất hiện nay trong WordPress. Nó cũng như bao plugin khác là bổ sung chức năng vào website nhưng nó sẽ bổ sung gần như toàn diện các chức năng mà một trang bán hàng đơn giản cần có.

Woocommerce sẽ có các chức năng chính như:

  • Tạo sản phẩm với định dạng thông thường, sản phẩm có thuộc tính, sản phẩm affiliate và sản phẩm kỹ thuật số (có thể tải về).
  • Hỗ trợ một số hình thức thanh toán online như PayPal, Credit Card, CoD, Cash và sẽ càng nhiều hơn khi cài thêm plugin hỗ trợ cho riêng nó.
  • Có hỗ trợ tự tính thuế sản phẩm hoặc thuế theo đơn hàng.
  • Tự tính giá chuyển phát, có rất nhiều loại tính giá chuyển phát và sẽ đa dạng hơn khi cài thêm plugin như có thể tính giá chuyển phát dựa theo cân nặng, kích thước, tỉnh thành,…
  • Trang quản lý đơn hàng chuyên nghiệp, lọc đơn hàng thông qua từng trạng thái.
  • Hỗ trợ template hiển thị riêng để có thể tự cấu hình lại template hiển thị phần shop và sản phẩm, cái này rất có lợi cho lập trình viên.
  • Có sẵn nhiều theme và extension (plugin mở rộng) để biến thành trang shop chuyên nghiệp.
  • Và hàng tá các chức năng hay ho khác nữa.

Như vậy với các tính năng kể trên, Woocommerce có thể lựa chọn cho những ai cần làm một trang shop đơn giản ngay trên website WordPress của mình để giới thiệu sản phẩm và cho phép khách đặt hàng trực tuyến để bán hàng tiện lợi hơn.

Ngoài ra Woo còn có rất nhiều plugin hỗ trợ khá là phổ biến như so sánh giữa các sản phẩm(YITH WooCommerce Compare), xem nhanh các sản phẩm(YITH WooCommerce Quick View), thêm sản phẩm vào danh sách yêu thích(YITH WooCommerce Wishlist, WooCommerce Wishlist Plugin),… và còn rất nhiều các plugin hỗ trợ khác nữa.

Change the “Return To Shop” link on the Cart page.

Các template của trang Giỏ hàng trong WooCommerce được tìm thấy trong thư mục giỏ hàng (cart). Thông thường, đường dẫn đến thư mục này (từ thư mục gốc của bản cài đặt WordPress của bạn) là: wp-content > plugins > woocommerce > templates > cart.

Tệp cụ thể kiểm soát liên kết “Return To Shop” là file cart-empty.php. Thật may là Woo cho phép người dùng ghi đè các tệp này trong chủ đề(theme).

Dưới đây là file gốc cart-empty.php ở @version 3.5.0

<?php
/**
 * Empty cart page
 *
 * This template can be overridden by copying it to yourtheme/woocommerce/cart/cart-empty.php.
 *
 * HOWEVER, on occasion WooCommerce will need to update template files and you
 * (the theme developer) will need to copy the new files to your theme to
 * maintain compatibility. We try to do this as little as possible, but it does
 * happen. When this occurs the version of the template file will be bumped and
 * the readme will list any important changes.
 *
 * @see     https://docs.woocommerce.com/document/template-structure/
 * @package WooCommerce/Templates
 * @version 3.5.0
 */

defined( 'ABSPATH' ) || exit;

/*
 * @hooked wc_empty_cart_message - 10
 */
do_action( 'woocommerce_cart_is_empty' );

if ( wc_get_page_id( 'shop' ) > 0 ) : ?>
    <p class="return-to-shop">
        <a class="button wc-backward" href="<?php echo esc_url( apply_filters( 'woocommerce_return_to_shop_redirect', wc_get_page_permalink( 'shop' ) ) ); ?>">
            <?php esc_html_e( 'Return to shop', 'woocommerce' ); ?>
        </a>
    </p>
<?php endif; ?>

Bây giờ bạn muốn đổi Return to shop thành Continue Shopping bằng cách thay đổi một chút ở dòng này là xong:

<?php esc_html_e( 'Continue Shopping', 'woocommerce' ); ?>

Đối với link của button này, ví dụ bạn không muốn nó trở về trang Shop nữa, mà bạn muốn hướng người dùng ra Home Page bạn có thể thay đổi trực tiếp ở trong file này như sau:

href="<?php echo esc_url( home_url() ); ?>"

Hoặc bạn giữ nguyên file trên và dùng add_filter()vào hook woocommerce_return_to_shop_redirect:

function ntc_add_filter_woocommerce_return_to_shop_redirect() {
    return esc_url( home_url() );
}

add_filter( 'woocommerce_return_to_shop_redirect', 'ntc_add_filter_woocommerce_return_to_shop_redirect' );

 

Change button text YITH WooCommerce Wishlist in font-end products

 

// Change button text wishlist in font-end products
if ( ! function_exists( '_ntc_wishlist_custom_button_text' ) ) :
    function _ntc_wishlist_custom_button_text() {
         return 'Your text';
    }
endif;
add_filter( 'yith_wcwl_button_label', '_ntc_wishlist_custom_button_text', 20 ); // 2.1 +

Shortcode  [yith_wcwl_add_to_wishlist] YITH WooCommerce Wishlist

Document here

if ( is_plugin_active( 'yith-woocommerce-wishlist/init.php' ) ) {
    echo do_shortcode( '[yith_wcwl_add_to_wishlist]' );
}

// Function shortcode in plugin 
// Path : ..wp-contentpluginsyith-woocommerce-wishlistincludesclass.yith-wcwl-shortcode.php
// Line 318 - 394 Version 2.1.2 (The current version at the time of writing this article.)

/**
 * Return "Add to Wishlist" button.
 *
 * @since 1.0.0
 */
public static function add_to_wishlist( $atts, $content = null ) {
    # Code...
    
}

Change button text YITH WooCommerce Compare in font-end products

 

// Change button text compare in font-end products
if ( ! function_exists( '_ntc_compare_custom_added_label' ) ) :
    function _ntc_compare_custom_added_label() {
        return 'Your text';
    }
endif;
add_filter( 'yith_woocompare_compare_added_label', '_ntc_compare_custom_added_label', 20 ); 

 

Shortcode [yith_compare_button] YITH WooCommerce Compare

 

if ( is_plugin_active( 'yith-woocommerce-compare/init.php' ) ) {
    echo do_shortcode( '[yith_compare_button container="no"]' );
}

// Function shortcode in plugin 
// Path : ..wp-contentpluginsyith-woocommerce-compareincludesclass.yith-woocompare-frontend.php
// Line 730 - 770 Version 2.2.2 (The current version at the time of writing this article.)

/**
 * Show the html for the shortcode
 */
public function compare_button_sc( $atts, $content = null ) {
    $atts = shortcode_atts(array(
        'product' => false,
        'type' => 'default',
        'container' => 'yes'
    ), $atts);

    $product_id = 0;

    /**
     * Retrieve the product ID in these steps:
     * - If "product" attribute is not set, get the product ID of current product loop
     * - If "product" contains ID, post slug or post title
     */
    if ( ! $atts['product'] ) {
        global $product;
        $product_id = ! is_null( $product ) ? yit_get_prop( $product, 'id', true ) : 0;
    } else {
        global $wpdb;
        $product = $wpdb->get_row( $wpdb->prepare( "SELECT ID FROM $wpdb->posts WHERE ID = %d OR post_name = %s OR post_title = %s LIMIT 1", $atts['product'], $atts['product'], $atts['product'] ) );
        if ( ! empty( $product ) ) {
            $product_id = $product->ID;
        }
    }

    // if product ID is 0, maybe the product doesn't exists or is wrong.. in this case, doesn't show the button
    if ( empty( $product_id ) )
        return '';

    ob_start();
    if ( $atts['container'] == 'yes' ) echo '<div class="woocommerce product compare-button">';
    $this->add_compare_link( $product_id, array(
        'button_or_link' => ( $atts['type'] == 'default' ? false : $atts['type'] ),
        'button_text' => empty( $content ) ? 'default' : $content
    ) );
    if ( $atts['container'] == 'yes' ) echo '</div>';
    return ob_get_clean();
}

 

There’s more… Will update later… thanks 🙂

Thêm Form tuỳ chỉnh tính giá sản phẩm trong Woocommerce WordPress Kích hoạt Gutenberg cho Custom Post Types trong WordPress 5+ 9 plugin WordPress và công cụ hay nhất mà website của bạn nên sử dụng

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.