Filters
Packaging Fit provides several filter hooks that allow developers to extend and customize its functionality.
twpf_global_options
Modify global options for the plugin. This filter allows you to customize the default settings used throughout the plugin.
add_filter( 'twpf_global_options', 'twpf_custom_global_options' );
function twpf_custom_global_options( $options ) {
// Modify global options
$options['min_weight'] = 0.5;
return $options;
}
twpf_menu_capability
Customize the capability required to access the menu. This filter allows you to control which user roles can access the Packaging Fit
settings.
add_filter( 'twpf_menu_capability', 'twpf_custom_menu_capability' );
function twpf_custom_menu_capability( $capability ) {
return 'manage_woocommerce';
}
twpf_menu_title
Customize the menu title. Use this filter to change the text displayed in the WordPress admin menu.
add_filter( 'twpf_menu_title', 'twpf_custom_menu_title' );
function twpf_custom_menu_title( $title ) {
return __( 'Custom Packaging Fit Title', 'theme_name' );
}
twpf_prepare_api_request_data
@since 1.0.2
Filters the data sent to the Packaging Fit API before making the request.
add_filter( 'twpf_prepare_api_request_data', 'twpf_custom_prepare_api_request_data', 10, 2 );
function twpf_custom_prepare_api_request_data( $response_data, $order ) {
// To capture debug information, use the code below.
// If debugging is not needed, this code should be removed.
ob_start();
echo '<pre>';
var_dump( $response_data );
var_dump( $order->get_ID() );
var_dump( $order->get_billing_postcode() );
echo '</pre>';
return array( 'debug' => ob_get_clean() );
// End of debug information capture.
// Change data here.
return $response_data;
}
Last updated
Was this helpful?