woocommerce_api_request_url filter
-
Hi.
I am trying to solve a problem with PayPal Checkout when using Polylang and found the following:
I changed /plugins/woocommerce/includes/class-woocommerce.php function on line 616 from:public function api_request_url( $request, $ssl = null ) { if ( is_null( $ssl ) ) { $scheme = wp_parse_url( home_url(), PHP_URL_SCHEME ); } elseif ( $ssl ) { $scheme = 'https'; } else { $scheme = 'http'; } if ( strstr( get_option( 'permalink_structure' ), '/index.php/' ) ) { $api_request_url = trailingslashit( home_url( '/index.php/wc-api/' . $request, $scheme ) ); } elseif ( get_option( 'permalink_structure' ) ) { $api_request_url = trailingslashit( home_url( '/wc-api/' . $request, $scheme ) ); } else { $api_request_url = add_query_arg( 'wc-api', $request, trailingslashit( home_url( '', $scheme ) ) ); } return esc_url_raw( apply_filters( 'woocommerce_api_request_url', $api_request_url, $request, $ssl ) ); }
to
public function api_request_url( $request, $ssl = null ) { $currentlang = get_bloginfo('language'); switch ($currentlang) { case "cs-CZ": $lang = "/cs"; break; case "en-GB": $lang = '/en'; break; default: $lang = '/en'; }; if ( is_null( $ssl ) ) { $scheme = wp_parse_url( home_url(), PHP_URL_SCHEME ); } elseif ( $ssl ) { $scheme = 'https'; } else { $scheme = 'http'; } if ( strstr( get_option( 'permalink_structure' ), '/index.php/' ) ) { $api_request_url = trailingslashit( home_url( $lang . '/index.php/wc-api/' . $request, $scheme ) ); } elseif ( get_option( 'permalink_structure' ) ) { $api_request_url = trailingslashit( home_url( $lang . '/wc-api/' . $request, $scheme ) ); } else { $api_request_url = add_query_arg( 'wc-api', $request, trailingslashit( home_url( '', $scheme ) ) ); } return esc_url_raw( apply_filters( 'woocommerce_api_request_url', $api_request_url, $request, $ssl ) ); }
It works, but anyone would know how to use a filter, so that I woudn’t have to modify Woocommerce original files?
The filter is like:add_filter( 'woocommerce_api_request_url', 'filter_function_name_3164', 10, 3 ); function filter_function_name_3164( $api_request_url, $request, $ssl ){ // filter... return $api_request_url; }
Thanks ??
Viewing 3 replies - 1 through 3 (of 3 total)
Viewing 3 replies - 1 through 3 (of 3 total)
- The topic ‘woocommerce_api_request_url filter’ is closed to new replies.