Free WordPress, WooCommerce & Shopify Code Snippets

Production-ready code snippets for WordPress, WooCommerce, and Shopify development. Copy-paste solutions with detailed examples and usage instructions. Updated for 2025.

11
Total Snippets
3
Categories
3
Languages

Showing 11 of 11 snippets

Add Custom Admin Column

Add custom columns to the WordPress admin posts list with sortable functionality

PHPwordpressintermediate
phpPreview
// Add the custom column header
function add_featured_image_column($columns) {
    // Insert after title column
    $new_columns = array();
...
#admin#custom-column#wordpress+2
1/9/2025
View

Add Custom WooCommerce Checkout Field

Add a custom field to WooCommerce checkout page and save it to order meta

PHPwoocommerceintermediate
phpPreview
// Add custom field to checkout
function add_custom_checkout_field($checkout) {
    echo '<div id="custom_checkout_field"><h3>' . __('Additional Information') . '</h3>';

...
#woocommerce#checkout#custom-field+1
1/9/2025
View

Apply Discount Based on User Role

Automatically apply percentage discounts to WooCommerce products based on user roles

PHPwoocommerceadvanced
phpPreview
// Apply role-based discount to product prices
function apply_role_based_discount($price, $product) {
    // Only for logged-in users
    if (!is_user_logged_in()) {
...
#woocommerce#discount#user-roles+2
1/9/2025
View

Customize WordPress Login Page

Replace WordPress logo on login page with your custom logo

PHPwordpressbeginner
phpPreview
// Replace login logo
function custom_login_logo() {
    ?>
    <style type="text/css">
...
#branding#login#wp-login+2
1/9/2025
View

Customize WooCommerce Add to Cart Button

Change the "Add to Cart" button text and behavior for different product types

PHPwoocommercebeginner
phpPreview
// Change "Add to Cart" text on single product page
function custom_single_add_to_cart_text() {
    return __('Buy Now', 'woocommerce');
}
...
#woocommerce#add-to-cart#customization+1
1/9/2025
View

Disable Gutenberg Block Editor

Disable the Gutenberg editor and use the Classic Editor instead

PHPwordpressbeginner
phpPreview
// Method 1: Disable Gutenberg completely
add_filter('use_block_editor_for_post', '__return_false', 10);

// Method 2: Disable for specific post types only
...
#gutenberg#classic-editor#wordpress+1
1/9/2025
View

Register Custom Post Type

Complete example of registering a custom post type with all common options

PHPwordpressintermediate
phpPreview
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'),
...
#custom-post-type#wordpress#development+1
1/9/2025
View

Remove WordPress Version Number

Remove WordPress version number from header and RSS feeds for better security

PHPwordpressbeginner
phpPreview
// Remove version from head
remove_action('wp_head', 'wp_generator');

// Remove version from RSS feeds
...
#security#wordpress#wp-head+1
1/9/2025
View

Shopify AJAX Add to Cart

Add products to cart without page reload using Shopify AJAX API

JAVASCRIPTshopifyintermediate
javascriptPreview
// Add to cart with AJAX
function addToCart(variantId, quantity = 1) {
  const formData = {
    items: [{
...
#shopify#ajax#cart+2
1/9/2025
View

Shopify Product Recommendations

Display related products using Shopify's built-in recommendation engine

LIQUIDshopifybeginner
liquidPreview
{% comment %}
  Product Recommendations Section
  Add this to your product template or create as a section
{% endcomment %}
...
#shopify#liquid#recommendations+2
1/9/2025
View

Shopify Variant Selector with Images

Dynamic variant selector that updates product images and price in real-time

LIQUIDshopifyintermediate
liquidPreview
{% comment %}
  Product Variant Selector
  Add this to your product template
{% endcomment %}
...
#shopify#liquid#variants+2
1/9/2025
View

Need Custom Development?

Can't find the snippet you need? I offer custom WordPress, WooCommerce, and React development services.

Get in Touch