WPML
add_filter( 'wcml_custom_prices_fields', 'the_callback_function', 10, 2 );
Loại
filter
Phiên bản WooCommerce Multilingual
3.8

Miêu tả

  • Thêm các trường giá tùy chỉnh bổ sung vào sản phẩm.
  • Các trường này được hiển thị trong phần Đặt giá bằng các loại tiền tệ khác theo cách thủ công khi chỉnh sửa/tạo sản phẩm gốc.
  • Để thêm nhãn trường giá tùy chỉnh, hãy xem hook wcml_custom_prices_fields_labels.

Đối số

Có hai tham số được truyền cho bộ lọc này:
$fields
(mảng) Mảng trường giá tùy chỉnh.
$product_id
(số nguyên) ID của một sản phẩm gốc.

Ví dụ sử dụng

Sử dụng mã ví dụ được cung cấp bên dưới để nhận được kết quả hiển thị trong ảnh chụp màn hình sau.

trường giá tùy chỉnh

Ví dụ
/*
 * Add this code to the functions.php file of your theme.
 */
add_filter( 'wcml_custom_prices_fields',  'add_custom_price_fields', 10, 2 );
function add_custom_price_fields( $fields, $product_id ) {
    
    // Add a new custom price field 
    $fields[] = '_sign_up_fee'; 

    return $fields;

}


add_filter( 'wcml_custom_prices_fields_labels', 'set_labels_for_price_fields', 10, 2 );
function set_labels_for_price_fields( $labels, $product_id ){

    // Edit the label of a custom price field
    $labels[ '_sign_up_fee' ] = __( 'Sign-up Fee', 'woocommerce-multilingual' ); 

    return $labels;

}

wcml_custom_prices_fields_labels, wcml_is_cache_enabled_for_switching_currency, wcml_geolocation_get_user_country, wcml_user_store_strategy, wcml_rounded_price, wcml_currencies_without_cents, wcml_product_custom_prices, wcml_custom_prices_strings, wcml_switch_currency, wcml_multi_currency_ajax_actions

Tất cả 24 hook Tính năng đa tiền tệ →