How to create your own WordPress plugin
Use Case Scenario:
Create a WordPress plugin to change the Add to Cart button label to Buy Me.
In one of our WooCommerce Tutorial, we change the “Add to Cart” button label to “Buy Me”. We did that by adding a code inside functions.php. Now, instead of adding the code, we will create a WordPress plugin from scratch and install in WordPress just like any other plugin.
1. Create a php file for the plugin. Make sure the php filename or the plugin name is unique. We will name the php file to “Buyme.php”
WordPress plugin standard should have the proper information about your WordPress plugin
<?php
/**
*Plugin Name: BuyMe Button Label Plugin
*Plugin URI: https://wehelpcode.com
*Description: A plugin changing the "Add to Cart" button label to "Buy Me"
*Version: 1.0
*Author: codegray
*Author URI: https://wehelpcode.com
*License: GPLv2
*/
2. Add the code for your plugin in Buyme.php plugin file. This is the code to change the Add to Cart button label in the other tutorial
<?php
/**
*Plugin Name: BuyMe Button Label Plugin
*Plugin URI: https://wehelpcode.com
*Description: A plugin changing the Add to Cart button label to Buy Me
*Version: 1.0
*Author: codegray
*Author URI: https://wehelpcode.com
*License: GPLv2
*/
add_filter( 'woocommerce_product_single_add_to_cart_text', 'whc_add_button', 9999 );
add_filter( 'woocommerce_product_add_to_cart_text', 'whc_add_button', 9999 );
function whc_add_button() {
return 'Buy Me!';
}
3. Create a ZIP file from Buyme.php file
You have just created your own WordPress plugin
4. Install the Buyme Plugin in your WordPress. The plugin will automatically change the “Add to Cart” button label to “Buy Me” in WooCommerce Shop