Production-ready code snippets for WordPress, WooCommerce, and Shopify development. Copy-paste solutions with detailed examples and usage instructions. Updated for 2025.
Showing 11 of 11 snippets
Add custom columns to the WordPress admin posts list with sortable functionality
// Add the custom column header
function add_featured_image_column($columns) {
// Insert after title column
$new_columns = array();
...Add a custom field to WooCommerce checkout page and save it to order meta
// Add custom field to checkout
function add_custom_checkout_field($checkout) {
echo '<div id="custom_checkout_field"><h3>' . __('Additional Information') . '</h3>';
...Automatically apply percentage discounts to WooCommerce products based on user roles
// Apply role-based discount to product prices
function apply_role_based_discount($price, $product) {
// Only for logged-in users
if (!is_user_logged_in()) {
...Replace WordPress logo on login page with your custom logo
// Replace login logo
function custom_login_logo() {
?>
<style type="text/css">
...Change the "Add to Cart" button text and behavior for different product types
// Change "Add to Cart" text on single product page
function custom_single_add_to_cart_text() {
return __('Buy Now', 'woocommerce');
}
...Disable the Gutenberg editor and use the Classic Editor instead
// Method 1: Disable Gutenberg completely
add_filter('use_block_editor_for_post', '__return_false', 10);
// Method 2: Disable for specific post types only
...Complete example of registering a custom post type with all common options
function register_portfolio_post_type() {
$labels = array(
'name' => _x('Portfolio Items', 'Post type general name', 'textdomain'),
'singular_name' => _x('Portfolio Item', 'Post type singular name', 'textdomain'),
...Remove WordPress version number from header and RSS feeds for better security
// Remove version from head
remove_action('wp_head', 'wp_generator');
// Remove version from RSS feeds
...Add products to cart without page reload using Shopify AJAX API
// Add to cart with AJAX
function addToCart(variantId, quantity = 1) {
const formData = {
items: [{
...Display related products using Shopify's built-in recommendation engine
{% comment %}
Product Recommendations Section
Add this to your product template or create as a section
{% endcomment %}
...Dynamic variant selector that updates product images and price in real-time
{% comment %}
Product Variant Selector
Add this to your product template
{% endcomment %}
...Can't find the snippet you need? I offer custom WordPress, WooCommerce, and React development services.
Get in Touch