Hỗ trợ trực tuyến

Tin mới nhất

[Tổng hợp] 20 đoạn code hay nhất cho Flatsome

Đánh giá post

Đây là các đoạn code hay nhất cho Flatsome được Miootech tổng hợp từ nhiều nguồn khác nhau chắc chắn sẽ giúp ích cho bạn trong việc tối ưu và phát triển theme Flatsome cho riêng mình.

Cách sử dụng:

Các bạn hãy chèn đoạn code mà mình muốn vào file funtions.php theo đường dẫn: Giao diện -> Chỉnh sửa -> Child theme -> Funtions.php

Code xóa bỏ số lượng sản phẩm hiển thị trong bộ lọc cửa hàng

add_action( 'init', 'woovn_remove_woocommerce_result_count' );
function woovn_remove_woocommerce_result_count() {
remove_action( 'flatsome_category_title_alt', 'woocommerce_result_count', 20 );
}

 

Xoa-Bo-So-Luong-San-Pham
Xoa-bo-so-luong-san-pham

Code di chuyển mô tả ngắn lên trên giá bán

add_action( 'init', 'woovn_flatsome_woocommerce_shop_loop_excerpt' );
function woovn_flatsome_woocommerce_shop_loop_excerpt() {
remove_action( 'flatsome_product_box_after', 'flatsome_woocommerce_shop_loop_excerpt', 20 );
add_action( 'woocommerce_shop_loop_item_title','flatsome_woocommerce_shop_loop_excerpt', 15 );
}

 

Di-Chuyen-Mo-Ta-Len-Tren-Gia-Ban
Di-chuyen-mo-ta-len-tren-gia-ban

Code di chuyển nút đóng vào trong lightbox

add_filter( 'flatsome_lightbox_close_btn_inside', '__return_true' );

Code thay đổi icon nút đóng của lightbox

add_filter( 'flatsome_lightbox_close_button', function ( $html ) {
$html = '<button title="%title%" type="button" class="mfp-close">';
/* f.ex. We're replacing the SVG icon into another one. */$html .= '<svg xmlns="//www.w3.org/2000/svg" viewBox="0 0 475.2 475.2" width="28" height="28"><path d="M405.6 69.6C360.7 24.7 301.1 0 237.6 0s-123.1 24.7-168 69.6S0 174.1 0 237.6s24.7 123.1 69.6 168 104.5 69.6 168 69.6 123.1-24.7 168-69.6 69.6-104.5 69.6-168-24.7-123.1-69.6-168zm-19.1 316.9c-39.8 39.8-92.7 61.7-148.9 61.7s-109.1-21.9-148.9-61.7c-82.1-82.1-82.1-215.7 0-297.8C128.5 48.9 181.4 27 237.6 27s109.1 21.9 148.9 61.7c82.1 82.1 82.1 215.7 0 297.8z" data-original="#000000" class="active-path" data-old_color="#000000" fill="#FFF"/><path d="M342.3 132.9c-5.3-5.3-13.8-5.3-19.1 0l-85.6 85.6-85.6-85.6c-5.3-5.3-13.8-5.3-19.1 0-5.3 5.3-5.3 13.8 0 19.1l85.6 85.6-85.6 85.6c-5.3 5.3-5.3 13.8 0 19.1 2.6 2.6 6.1 4 9.5 4s6.9-1.3 9.5-4l85.6-85.6 85.6 85.6c2.6 2.6 6.1 4 9.5 4 3.5 0 6.9-1.3 9.5-4 5.3-5.3 5.3-13.8 0-19.1l-85.4-85.6 85.6-85.6c5.3-5.3 5.3-13.8 0-19.1z" data-original="#000000" class="active-path" data-old_color="#000000" fill="#FFF"/></svg>';
$html .= '</button>';
return $html;
} );

Code thay đổi độ dài của mô tả sản phẩm

function custom_excerpt_length( $length ) {
return 70; //thay bằng độ dài mong muốn
}
add_filter( 'excerpt_length', 'custom_excerpt_length', 999 );

Code thêm text tùy chọn vào sau giá

add_filter( 'woocommerce_get_price_html', 'price_prefix_suffix', 99, 2 );
function price_prefix_suffix( $price, $product ){
if(is_singular('product')) {
$price = $price . '(Chưa bao gồm VAT)';
}
return apply_filters( 'woocommerce_get_price', $price );
}

Code xóa chữ “Product” trên thanh điều hướng

/*
* Hide "Products" in WooCommerce breadcrumb
*/function woo_custom_filter_breadcrumbs_trail ( $trail ) {
foreach ( $trail as $k => $v ) {
if ( strtolower( strip_tags( $v ) ) == 'products' ) {
unset( $trail[$k] );
break;
}
}

return $trail;
}
add_filter( 'woo_breadcrumbs_trail', 'woo_custom_filter_breadcrumbs_trail', 10 );

Code tự thêm sản phẩm vào giỏ mỗi khi khách truy cập trang web

/*
* Add item to cart on visit
*/function add_product_to_cart() {
if ( ! is_admin() ) {
global $woocommerce;
$product_id = 64;
$found = false;
//check if product already in cart
if ( sizeof( $woocommerce->cart->get_cart() ) > 0 ) {
foreach ( $woocommerce->cart->get_cart() as $cart_item_key => $values ) {
$_product = $values['data'];
if ( $_product->id == $product_id )
$found = true;
}
// if product not found, add it
if ( ! $found )
$woocommerce->cart->add_to_cart( $product_id );
} else {
// if no products in cart, add it
$woocommerce->cart->add_to_cart( $product_id );
}
}
}
add_action( 'init', 'add_product_to_cart' );

Code thêm ký hiệu tiền tệ theo ý mình

add_filter( 'woocommerce_currencies', 'add_my_currency' );

function add_my_currency( $currencies ) {
$currencies['VNĐ'] = __( 'Vietnam Dong', 'woocommerce' );
return $currencies;
}

add_filter('woocommerce_currency_symbol', 'add_my_currency_symbol', 10, 2);

function add_my_currency_symbol( $currency_symbol, $currency ) {
switch( $currency ) {
case 'VNĐ': $currency_symbol = '$'; break;
}
return $currency_symbol;
}

Code thay đổi chữ “Add to Cart”

/**
* Change the add to cart text on single product pages
*/function woo_custom_cart_button_text() {
return __('My Button Text', 'woocommerce');
}
add_filter('single_add_to_cart_text', 'woo_custom_cart_button_text');

/**
* Change the add to cart text on product archives
*/function woo_archive_custom_cart_button_text() {
return __( 'My Button Text', 'woocommerce' );
}
add_filter( 'add_to_cart_text', 'woo_archive_custom_cart_button_text' );

Thay chữ ‘My Button Text‘ thành chữ mà bạn muốn

Code gửi email sau khi thanh toán bằng coupon

/**
* WooCommerce Extra Feature
* --------------------------
*
* Send an email each time an order with coupon(s) is completed
* The email contains coupon(s) used during checkout process
*
*/function woo_email_order_coupons( $order_id ) {
$order = new WC_Order( $order_id );

if( $order->get_used_coupons() ) {

$to = 'youremail@yourcompany.com';
$subject = 'New Order Completed';
$headers = 'From: My Name ' . "\r\n";

$message = 'A new order has been completed.\n';
$message .= 'Order ID: '.$order_id.'\n';
$message .= 'Coupons used:\n';

foreach( $order->get_used_coupons() as $coupon) {
$message .= $coupon.'\n';
}
@wp_mail( $to, $subject, $message, $headers );
}
}
add_action( 'woocommerce_thankyou', 'woo_email_order_coupons' );

Code thay đổi số lượng sản phẩm liên quan

/**
* WooCommerce Extra Feature
* --------------------------
*
* Change number of related products on product page
* Set your own value for 'posts_per_page'
*
*/function woo_related_products_limit() {
global $product;

$args = array(
'post_type' => 'product',
'no_found_rows' => 1,
'posts_per_page' => 6,
'ignore_sticky_posts' => 1,
'orderby' => $orderby,
'post__in' => $related,
'post__not_in' => array($product->id)
);
return $args;
}
add_filter( 'woocommerce_related_products_args', 'woo_related_products_limit' );

Thay số 6 bằng giá trị mà bạn muốn

Code tắt các tab như Review, Description trong sản phẩm

/**
* Remove product tabs
*
*/function woo_remove_product_tab($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;

}
add_filter( 'woocommerce_product_tabs', 'woo_remove_product_tab', 98);

Code thay số lượng ảnh thumbnail trong sản phẩm

add_filter ( 'woocommerce_product_thumbnails_columns', 'xx_thumb_cols' );
function xx_thumb_cols() {
return 4; // .last class applied to every 4th thumbnail
}

Thay số 4 bằng giá trị mà bạn muốn

Code sửa đường link nút “Add to Cart”

add_filter('add_to_cart_redirect', 'custom_add_to_cart_redirect');

function custom_add_to_cart_redirect() {
/**
* Replace with the url of your choosing
* e.g. return '//www.yourshop.com/'
*/return get_permalink( get_option('woocommerce_checkout_page_id') );
}

Thay link //www.yourshop.com/ bằng link mà bạn muốn

Code sửa số lượng sản phẩm hiển thị ở mỗi trang

// Display 24 products per page. Goes in functions.php
add_filter( 'loop_shop_per_page', create_function( '$cols', 'return 24;' ), 20 );

Thay 24 bằng giá trị mà bạn muốn

Code ẩn sản phẩm liên quan

/*
* wc_remove_related_products
*
* Clear the query arguments for related products so none show.
* Add this code to your theme functions.php file.
*/function wc_remove_related_products( $args ) {
return array();
}
add_filter('woocommerce_related_products_args','wc_remove_related_products', 10);

Code đưa mô tả sản phẩm vào bên dưới ảnh sản phẩm

add_action('woocommerce_after_shop_loop_item_title','woocommerce_template_single_excerpt', 5);

Code tắt chức năng mã SKU

add_filter( 'wc_product_sku_enabled', '__return_false' );

Code chuyển sản phẩm không có giá sẽ hiển thị Liên hệ

add_filter(‘woocommerce_empty_price_html’, ‘custom_call_for_price’);

function custom_call_for_price() {

return ‘<span class=”lien-he-price”>Liên hệ</span>’;

}

Code thêm 1 Tab mới trong Woocormerce

add_filter( ‘woocommerce_product_tabs’, ‘woo_new_product_tab’ );

function woo_new_product_tab( $tabs ) {

// Adds the new tab

$tabs[‘test_tab’] = array(

‘title’ => __( ‘Lịch trình chi tiết’, ‘woocommerce’ ),

‘priority’ => 50,

‘callback’ => ‘woo_new_product_tab_content’

);

return $tabs;

}

function woo_new_product_tab_content() {

// The new tab content

echo “Nội dung”;

}

Code thêm text tùy chọn vào sau giá

add_filter( 'woocommerce_get_price_html', 'devvn_price_prefix_suffix', 99, 2 );
function devvn_price_prefix_suffix( $price, $product ){
if(is_singular('product')) {
$price = $price . '(Chưa bao gồm VAT)';
}
return apply_filters( 'woocommerce_get_price', $price );
}

 

Trả lời

Email của bạn sẽ không được hiển thị công khai. Các trường bắt buộc được đánh dấu *