Код: Выделить всё
// Display custom field on single product page
function d_extra_product_field(){
$value = isset( $_POST ['extra_product_field'] ) ? sanitize_text_field( $_POST['extra_product_field'] ) : '';
printf( '%s
', __( 'Notes: Select colours & quantities for 12 pack only' ), esc_attr( $value ) );
}
add_action( 'woocommerce_after_add_to_cart_button', 'd_extra_product_field', 9 );
Я бы хотел, чтобы настраиваемое поле добавлялось только для определенной категории продукта (идентификатор категории). 29).
Вот моя попытка кода:
Код: Выделить всё
// Display custom field on single product page
function d_extra_product_field(){
$value = isset( $_POST ['extra_product_field'], $product_cat_id = 29 ) ? sanitize_text_field( $_POST['extra_product_field'] ) : '';
printf( '%s
', __( 'Notes: Select colours & quantities for 12 pack only' ), esc_attr( $value ) );
}
add_action( 'woocommerce_after_add_to_cart_button', 'd_extra_product_field', 9 );
Пример дополнительного поля WooCommerce
Подробнее здесь: https://stackoverflow.com/questions/783 ... t-category