// Add a custom field to the product edit page add_action('woocommerce_product_options_general_product_data', 'add_custom_back_button_field'); function add_custom_back_button_field() { woocommerce_wp_checkbox( array( 'id' => '_enable_back_button', 'wrapper_class' => 'show_if_simple', 'label' => __('Enable Back Button', 'woocommerce'), 'description' => __('Enable or disable the back button on this product page', 'woocommerce'), ) ); } // Save the custom field data add_action('woocommerce_process_product_meta', 'save_custom_back_button_field'); function save_custom_back_button_field($post_id) { $enable_back_button = isset($_POST['_enable_back_button']) ? 'yes' : 'no'; update_post_meta($post_id, '_enable_back_button', $enable_back_button); } // Display the back button if the custom field is enabled function add_back_button() { if (is_product() && should_display_back_button()) { echo ''; } } function should_display_back_button() { $enable_back_button = get_post_meta(get_the_ID(), '_enable_back_button', true); return $enable_back_button === 'yes'; }