dongwei6457 2014-07-20 17:15
浏览 105
已采纳

如何在WooCommerce Checkout中创建自定义选择框看起来像其他选择框?

I've done some research on this before asking and am unable to find the answer I'm looking for. I created a custom select box for the checkout page under billing. It's complete in that it works on the page, submits the data and even adds the data to the emails. However, it doesn't look great. I want it to look like the Country and State drop down boxes, style-wise. Here is the code:

add_filter( 'woocommerce_checkout_fields' , 'custom_store_pickup_field');

function custom_store_pickup_field( $fields ) {
  $fields['billing']['my_field_name'] = array(
    'type'          => 'select',
    'options'       => array(
    'Option 1'      => 'Select if choosing local pickup',
    'Option 2'      => 'Address 1, etc.',
    ),
    'class'         => array('own-css-name'),
    'label'         => __('<br /><p style="font-size:20px;">Please Choose A Pickup Location (if applicable, otherwise skip)'),
    );

return $fields;

}

I read online you could make it own-css-name, so i tried that (as seen above), but I'm not sure what that means? What css name would I use to match the country and state style, as those styles came with WooCommerce, they weren't custom?

Edit: I've come up with a solution to inspect element, find class, and use Simple Custom CSS to override and assign the same properties as Country and State have. However, this doesn't seem like the most eloquent solution. I was wondering if there was a better way.

  • 写回答

1条回答 默认 最新

  • duanla3319 2014-07-20 19:05
    关注

    You will need to add some custom JavaScript to apply the Chosen style to your new drop down. By default WooCommerce applies this to select boxes with the class select.chosen_select however from looking at the code it is not possible to apply the .chosen_select class to the actual select box, the class attribute is applied to the parent container for the field, thus the new JavaScript to apply the style.

    jQuery('.own-css-name select').chosen();
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 能把水桶搬到饮水机的机械设计
  • ¥15 Android Studio中如何把H5逻辑放在Assets 文件夹中以实现将h5代码打包为apk
  • ¥15 使用小程序wx.createWebAudioContext()开发节拍器
  • ¥15 关于#爬虫#的问题:请问HMDB代谢物爬虫的那个工具可以提供一下吗
  • ¥15 vue3+electron打包获取本地视频属性,文件夹里面有ffprobe.exe 文件还会报错这是什么原因呢?
  • ¥20 用51单片机控制急停。
  • ¥15 孟德尔随机化结果不一致
  • ¥15 在使用pyecharts时出现问题
  • ¥50 怎么判断同步时序逻辑电路和异步时序逻辑电路
  • ¥15 差动电流二次谐波的含量Matlab计算