我想使用Woocommerce过滤器返回的Array作为Redux Framework字段中的值。我确实了解Woocommerce插件加载后过滤器返回的情况。我试图将Redux :: setSection方法移到filter函数内,但在这种情况下似乎未调用section方法。有什么建议吗?
$statuses;
add_filter( 'wc_order_statuses', 'custom_wc_order_statuses' );
function custom_wc_order_statuses( $order_statuses ) {
$statuses = $order_statuses;
return $order_statuses;
}
/*Need to pass $statuses to the Redux::setSection*/
Redux::setSection( $opt_name, array(
'title' => __( 'Text Options', 'redux-framework-demo' ),
'desc' => __( 'For full documentation on this field, visit: ', 'redux-framework-demo' ) . '<a href="http://docs.reduxframework.com/core/fields/text/" target="_blank">http://docs.reduxframework.com/core/fields/text/</a>',
'id' => 'opt-text-subsection',
'icon' => 'el el-home',
'subsection' => false,
'fields' => array(
array(
'id'=>'multi-text',
'type' => 'multi_text',
'title' => __('Multi Text Option - Color Validated', 'redux-framework-demo'),
'validate' => 'color',
'subtitle' => __('If you enter an invalid color it will be removed. Try using the text "blue" as a color. ;)', 'redux-framework-demo'),
'desc' => __('This is the description field, again good for additional info.', 'redux-framework-demo')
),
array(
'id' => 'opt-select',
'type' => 'select',
'title' => __('Select Option', 'redux-framework-demo'),
'subtitle' => __('No validation can be done on this field type', 'redux-framework-demo'),
'desc' => __('This is the description field, again good for additional info.', 'redux-framework-demo'),
// Must provide key => value pairs for select options
'options' => $statuses,
'default' => '2',
)
)
) );
答案 0 :(得分:0)
使用Redux数据字段。您可以进行自定义回调,数据将始终是最新的。
https://docs.redux.io/configuration/argument-data.html#using-a-custom-callback
此外,如果您需要从Redux外部更新选项(例如WooCommerce对该值的更新),则可以通过以下方式进行设置: https://docs.redux.io/guides/advanced-updating-an-option-manually.html