2017-08-10 43 views
0

我檢查了一些其他話題,並沒有適合我的設置複選框的頁面加載時檢查框。PHP設置複選框檢查默認WordPresspress

該複選框與數據庫沒有關聯,只是讓代碼查看它是否被選中。我知道如何在HTML和PHP中做到這一點,但我有一個Wordpress插件,它有一個複選框,我需要在頁面加載時進行檢查。

下面顯示的複選框的代碼,但我不知道該怎麼添加,使其設置複選框選中在頁面加載時:

$is_offers_enabled = get_post_meta($object_id, 'offers_for_woocommerce_enabled', true); 
$is_offers_enabled = ($is_offers_enabled == 'yes') ? 'yes' : 'no'; 
    WCVendors_Pro_Form_Helper::input(apply_filters('ofwcv_offers_for_woocommerce_enabled', array( 
        'id'  => 'offers_for_woocommerce_enabled', 
        'label'  => __('Enable Offers?', 'offers-for-woocommerce-wc-vendors'), 
        'type'  => 'checkbox', 
        'value'  => $is_offers_enabled, 
        'class'  => 'ofwcv_offers_for_woocommerce_enabled', 
        'wrapper_start' => '<div class="wcv-cols-group wcv-horizontal-gutters"><div class="all-50 small-100">', 
        'wrapper_end' => '</div>' 
        )) 
       ); 
+0

難道你不能將'checked'=>'checked'添加到該數組嗎? – IsThisJavascript

回答

0

你應該能夠添加'checked => 'checked'到屬性列表你發佈在你的問題。

WCVendors_Pro_Form_Helper::input(apply_filters('ofwcv_offers_for_woocommerce_enabled', array( 
    'id'  => 'offers_for_woocommerce_enabled', 
    'label'  => __('Enable Offers?', 'offers-for-woocommerce-wc-vendors'), 
    'type'  => 'checkbox', 
    'value'  => $is_offers_enabled, 
    'class'  => 'ofwcv_offers_for_woocommerce_enabled', 
    'wrapper_start' => '<div class="wcv-cols-group wcv-horizontal-gutters"><div class="all-50 small-100">', 
    'wrapper_end' => '</div>', 
    custom_attributes(
        array('checked' => 'checked') 
    ) 
)) 
+0

沒有工作。我知道這是顯示覆選框原因的正確區域,如果我更改它顯示的標籤文本。 – Stretcher25

+0

@ Stretcher25對於屬性的排序可能是挑剔的,需要在包裝之前列出它們? – Canis

+0

@ Stretcher25你也許能夠做''檢查'=>真' – Canis