admin管理员组文章数量:1313006
I am trying to have a variable out of the filter
At the end of there is return apply_filters( 'woocommerce_account_menu_items', $items, $endpoints );
function wc_get_account_menu_items() {
$endpoints = array(
'orders' => get_option( 'woocommerce_myaccount_orders_endpoint', 'orders' ),
'downloads' => get_option( 'woocommerce_myaccount_downloads_endpoint', 'downloads' ),
'edit-address' => get_option( 'woocommerce_myaccount_edit_address_endpoint', 'edit-address' ),
'payment-methods' => get_option( 'woocommerce_myaccount_payment_methods_endpoint', 'payment-methods' ),
'edit-account' => get_option( 'woocommerce_myaccount_edit_account_endpoint', 'edit-account' ),
'customer-logout' => get_option( 'woocommerce_logout_endpoint', 'customer-logout' ),
);
$items = array(
'dashboard' => __( 'Dashboard', 'woocommerce' ),
'orders' => __( 'Orders', 'woocommerce' ),
'downloads' => __( 'Downloads', 'woocommerce' ),
'edit-address' => _n( 'Addresses', 'Address', (int) wc_shipping_enabled(), 'woocommerce' ),
'payment-methods' => __( 'Payment methods', 'woocommerce' ),
'edit-account' => __( 'Account details', 'woocommerce' ),
'customer-logout' => __( 'Logout', 'woocommerce' ),
);
// Remove missing endpoints.
foreach ( $endpoints as $endpoint_id => $endpoint ) {
if ( empty( $endpoint ) ) {
unset( $items[ $endpoint_id ] );
}
}
// Check if payment gateways support add new payment methods.
if ( isset( $items['payment-methods'] ) ) {
$support_payment_methods = false;
foreach ( WC()->payment_gateways->get_available_payment_gateways() as $gateway ) {
if ( $gateway->supports( 'add_payment_method' ) || $gateway->supports( 'tokenization' ) ) {
$support_payment_methods = true;
break;
}
}
if ( ! $support_payment_methods ) {
unset( $items['payment-methods'] );
}
}
return apply_filters( 'woocommerce_account_menu_items', $items, $endpoints );
}
if I have a class like this
Class MyClass{
public function __construct(){
add_filter ( 'woocommerce_account_menu_items', array($this, 'wooquickmy_grab_endpoints'), 10 , 1 );
add_action( 'admin_menu', array( $this,'wooquickmy_options_page' ));
}
public function wooquickmy_options_page(){
//get the return value from there wooquickmy_grab_endpoints
}
public function wooquickmy_grab_endpoints($endpoints){
return $endpoints ;
}
}
Is it possible to get that return value inside the action that I have created? What is the best possible option for such cases?
Please Help
Thanks
I am trying to have a variable out of the filter
At the end of there is return apply_filters( 'woocommerce_account_menu_items', $items, $endpoints );
function wc_get_account_menu_items() {
$endpoints = array(
'orders' => get_option( 'woocommerce_myaccount_orders_endpoint', 'orders' ),
'downloads' => get_option( 'woocommerce_myaccount_downloads_endpoint', 'downloads' ),
'edit-address' => get_option( 'woocommerce_myaccount_edit_address_endpoint', 'edit-address' ),
'payment-methods' => get_option( 'woocommerce_myaccount_payment_methods_endpoint', 'payment-methods' ),
'edit-account' => get_option( 'woocommerce_myaccount_edit_account_endpoint', 'edit-account' ),
'customer-logout' => get_option( 'woocommerce_logout_endpoint', 'customer-logout' ),
);
$items = array(
'dashboard' => __( 'Dashboard', 'woocommerce' ),
'orders' => __( 'Orders', 'woocommerce' ),
'downloads' => __( 'Downloads', 'woocommerce' ),
'edit-address' => _n( 'Addresses', 'Address', (int) wc_shipping_enabled(), 'woocommerce' ),
'payment-methods' => __( 'Payment methods', 'woocommerce' ),
'edit-account' => __( 'Account details', 'woocommerce' ),
'customer-logout' => __( 'Logout', 'woocommerce' ),
);
// Remove missing endpoints.
foreach ( $endpoints as $endpoint_id => $endpoint ) {
if ( empty( $endpoint ) ) {
unset( $items[ $endpoint_id ] );
}
}
// Check if payment gateways support add new payment methods.
if ( isset( $items['payment-methods'] ) ) {
$support_payment_methods = false;
foreach ( WC()->payment_gateways->get_available_payment_gateways() as $gateway ) {
if ( $gateway->supports( 'add_payment_method' ) || $gateway->supports( 'tokenization' ) ) {
$support_payment_methods = true;
break;
}
}
if ( ! $support_payment_methods ) {
unset( $items['payment-methods'] );
}
}
return apply_filters( 'woocommerce_account_menu_items', $items, $endpoints );
}
if I have a class like this
Class MyClass{
public function __construct(){
add_filter ( 'woocommerce_account_menu_items', array($this, 'wooquickmy_grab_endpoints'), 10 , 1 );
add_action( 'admin_menu', array( $this,'wooquickmy_options_page' ));
}
public function wooquickmy_options_page(){
//get the return value from there wooquickmy_grab_endpoints
}
public function wooquickmy_grab_endpoints($endpoints){
return $endpoints ;
}
}
Is it possible to get that return value inside the action that I have created? What is the best possible option for such cases?
Please Help
Thanks
Share Improve this question asked Dec 28, 2020 at 16:20 GeekyOwlGeekyOwl 16 1 |1 Answer
Reset to default -1The filter has 2 args, not one.
Try:
add_filter ( 'woocommerce_account_menu_items', array($this, 'wooquickmy_grab_endpoints'), 10 , 2 );
public function wooquickmy_grab_endpoints($items, $endpoints){
// do something with $endpoints
return $items;
}
本文标签: actionsIs it possible to make get variable out of filter in Class
版权声明:本文标题:actions - Is it possible to make get variable out of filter in Class? 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741885266a2402984.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
admin_menu
runs in the back end, andwoocommerce_account_menu_items
runs on the front end, so no, you won't be able to get the list of endpoints in the back-end. – Jacob Peattie Commented Dec 29, 2020 at 2:09