Product Sample Actions and Filters

All of the custom filters that are available in the Product Sample For WooCommerce plugin are listed in this document.

Custom Filter #1 :-

Filter For - Hide local pickup option when a customer orders sample products.

Filter Description - We have integrated the Local Pickup Plus plugin with our plugin, and when a customer adds sample products to the cart, we can hide the pickup location options by using the filter code below.

Filter Code -

// Hide local pickup fields for sample products

if ( ! function_exists( 'dsfps_hide_local_pickup_fields_for_sample' ) ) {

function dsfps_hide_local_pickup_fields_for_sample() {

return true;

}

add_filter( 'dsfps_hide_local_pickup_for_sample', 'dsfps_hide_local_pickup_fields_for_sample' );

}

How To - Simply add the above filter code to your theme's function.php file, and the local pickup options for sample products will be automatically hidden.

Screenshot - 1 :- (Front - Cart page before filter code)

Screenshot - 2 :- (Front - Cart page after filter code)

Custom Filter #2 :-

Filter For - Sample product maximum quantity limitation.

Filter Description - If the maximum quantity restriction for the sample products isn't working properly on your website. The ineffectiveness of the built-in WooCommerce validation hook might be the cause. You can try the filter code below to make it work to solve this problem.

Filter Code -

// Maximum quantity limit validation for sample products

if ( ! function_exists( 'dsfps_wc_check_cart_items_filter' ) ) {

function dsfps_wc_check_cart_items_filter() {

return 'template_redirect';

}

add_filter( 'dsfps_wc_check_cart_items', 'dsfps_wc_check_cart_items_filter' );

}

How To - Simply add the above filter code to your theme's function.php file, and check if the maximum quantity limitation is working or not.

Custom Filter #3 :-

Filter For - Sample add to cart button location or position

Filter Description - To change the location/position of your sample add to cart button, you can utilize this filter code. You can review different hooks of the single product page from here to change the button location.

Filter Code -

// Change sample add to cart button location

if ( ! function_exists( 'dsfps_single_product_button_location_filter' ) ) {

function dsfps_single_product_button_location_filter() {

return 'woocommerce_after_add_to_cart_button';

}

add_filter( 'dsfps_single_product_button_location', 'dsfps_single_product_button_location_filter' );

}

How To - Simply add the above filter code to your theme's function.php file, and it will change the sample button position based on the provided hook.

Custom Filter #4 :-

Filter For - Out of stock sample button label.

Filter Description - To change the label of the sample add to cart button for sample products when they are out of stock, you can utilize this filter code.

Filter Code -

// Change sample out of stock button label

if ( ! function_exists( 'dsfps_sample_out_of_stock_btn_label_filter' ) ) {

function dsfps_sample_out_of_stock_btn_label_filter() {

return 'Sample - Out of Stock';

}

add_filter( 'dsfps_sample_out_of_stock_btn_label', 'dsfps_sample_out_of_stock_btn_label_filter' );

}

How To - Simply add the above filter code to your theme's function.php file, and check if the out-of-stock samples button label changed or not.

Custom Filter #5 :-

Filter For - Sample and actual product restriction message for single product page

Filter Description - Our feature 'Prevent Sample & Real Products to Ordered' restricts customers from adding samples and actual products to the same cart. Enabling this feature will display an error message when customers attempt to add samples and normal products together. You can customize the default error message by using this filter code.

Filter Code -

// Change sample and actual product restriction message for product page

if ( ! function_exists( 'dsfps_order_restriction_msg_for_product_filter' ) ) {

function dsfps_order_restriction_msg_for_product_filter() {

return 'You can't add samples and actual products to the same cart.';

}

add_filter( 'dsfps_order_restriction_msg_for_product_page', 'dsfps_order_restriction_msg_for_product_filter' );

}

How To - Simply add the above filter code to your theme's function.php file, and check how it works.

Custom Filter #6 :-

Filter For - Sample and actual product restriction message for the cart page

Filter Description - You can customize the cart page default error message by using this filter code.

Filter Code -

// Change sample and actual product restriction message for the cart page

if ( ! function_exists( 'dsfps_order_restriction_msg_for_cart_filter' ) ) {

function dsfps_order_restriction_msg_for_cart_filter() {

return 'You've added both samples and actual products to your cart. To proceed with checkout, please remove either the samples or the actual products.';

}

add_filter( 'dsfps_order_restriction_msg_for_cart_page', 'dsfps_order_restriction_msg_for_cart_filter' );

}

How To - Simply add the above filter code to your theme's function.php file, and check how it works.

Custom Filter #7 :-

Filter For - Sample menu location

Filter Description - Our 'Include on Store Menu' feature adds a new menu item called 'Sample Products' to the primary menu by default when enabled. It displays a list of all sample products. If you wish to customize the menu location for this feature, you can utilize this filter.

Filter Code -

// Change sample menu location

if ( ! function_exists( 'dsfps_sample_shop_menu_location_filter' ) ) {

function dsfps_sample_shop_menu_location_filter() {

return 'secondary';

}

add_filter( 'default_sample_shop_menu_location', 'dsfps_sample_shop_menu_location_filter' );

}

How To - Simply add the above filter code to your theme's function.php file, and check the sample menu item in the newly defined menu location.

Did this answer your question? Thanks for the feedback There was a problem submitting your feedback. Please try again later.