Skip to content

Instantly share code, notes, and snippets.

View racmanuel's full-sized avatar
💡
Making new things!

Manuel Ramirez Coronel racmanuel

💡
Making new things!
View GitHub Profile
<?php
add_filter( 'woocommerce_loop_add_to_cart_link', function ( $html, $product ) {
if ( is_user_logged_in() && is_shop() && $product && $product->is_type( 'simple' ) && $product->is_purchasable() && $product->is_in_stock() && ! $product->is_sold_individually() ) {
$html = '<form action="' . esc_url( $product->add_to_cart_url() ) . '" class="cart" method="post" enctype="multipart/form-data"><div class="ct-cart-actions">';
$html .= woocommerce_quantity_input( array(), $product, false );
$html .= '<button type="submit" class="single_add_to_cart_button button alt" name="add-to-cart" value="' . $product->get_id() . '">' . esc_html( $product->add_to_cart_text() ) . '</button>';
$html .= '</div></form>';
}
return $html;
}, 10, 2 );
@racmanuel
racmanuel / blc-2-add-quantity+atc-to-product-cards.php
Created July 10, 2024 22:14 — forked from tdmrhn/blc-2-add-quantity+atc-to-product-cards.php
Blocksy 2 Add Quantity + Add to Card button to Product Cards via Content Blocks Element
<?php
// Add this to Content Blocks > Hook > No Condition or Location
// Call it through Customizer > Product Archives > Card Options > Enable Content Block Element > Select the Hook name in drop down
if ( is_product() || is_shop() || is_tax( 'product_cat' ) || is_tax( 'product_tag' ) ) {
global $product;
if ( ! $product->is_sold_individually() && 'variable' != $product->product_type && $product->is_purchasable() && $product->is_in_stock() ) {
echo '<div class="dhn-atc-wrap">';
woocommerce_quantity_input( array( 'min_value' => 1, 'max_value' => $product->backorders_allowed() ? '' : $product->get_stock_quantity() ) );
echo '<a href="' . esc_url( $product->add_to_cart_url() ) . '" data-quantity="1" class="button product_type_simple add_to_cart_button ajax_add_to_cart" data-product_id="' . esc_attr( $product->get_id() ) . '" aria-label="' . esc_attr( sprintf( __( 'Add to cart: %s', 'woocommerce' ), $product->get_name() ) ) . '" aria-describedby="" rel="nofollow">' . esc_html( $p
<?php
add_filter( 'woocommerce_loop_add_to_cart_link', function ( $html, $product ) {
if ( $product && $product->is_type( 'simple' ) && $product->is_purchasable() && $product->is_in_stock() && ! $product->is_sold_individually() ) {
$class = implode( ' ', array_filter( array(
'button',
'product_type_' . $product->get_type(),
$product->is_purchasable() && $product->is_in_stock() ? 'add_to_cart_button' : '',
$product->supports( 'ajax_add_to_cart' ) ? 'ajax_add_to_cart' : '',
) ) );
@racmanuel
racmanuel / functions.php
Created November 29, 2023 22:58 — forked from nayemDevs/functions.php
Add new field on vendor product upload form in Dokan
/*
* Adding extra field on New product popup/without popup form
*/
add_action( 'dokan_new_product_after_product_tags','new_product_field',10 );
function new_product_field(){ ?>
<div class="dokan-form-group">
<?php
/**
* Put this into your functions.php of your child-theme or custom plugin
* you can create the role with wp-cli by running `wp shell` and running the command:
* add_role('merchant','Merchant',array('read' => true, 'delete_posts' => false) );
*/
/**
* Step #1: create the field used to store the new sale_price for product_variation and for products
*/
@racmanuel
racmanuel / sync_acf_post_title.php
Created December 7, 2022 21:40 — forked from rveitch/sync_acf_post_title.php
Update WordPress post title from an ACF field value on save. (Advanced Custom Fields)
<?php
/**
* Update Post Title from an ACF field value on post save.
*
* Triggers on save, edit or update of published posts.
* Works in "Quick Edit", but not bulk edit.
*/
function sync_acf_post_title($post_id, $post, $update) {
$acf_title = get_field('my_acf_field_name', $post_id); // NOTE: enter the name of the ACF field here
@racmanuel
racmanuel / woo-update-product-stock-qty.php
Created November 25, 2022 19:20 — forked from stuart-lambon/woo-update-product-stock-qty.php
Updates WooCommerce product stock quantity programmatically. $sku and $qty variables need to be filled.
<?php
$sku = 'ITEM001';
$qty = 1;
// Get product_id from SKU — returns null if not found
$product_id = wc_get_product_id_by_sku( $sku );
// Process if product found
if ( $product_id != null ) {
@racmanuel
racmanuel / one-million-posts.md
Created October 31, 2022 23:26 — forked from xhrix/one-million-posts.md
One Million Posts - Wordpress

One million posts

Let's create one million posts to see the performance of a Wordpress site.

Creation of a post

The purpose of this document is to find out what is the underlying data that gets modified in a wordpress database when a post with an image are created.

What I did

<?php
/*
Plugin Name: Add Gift Card as Custom Product Type
Description: A simple demo plugin on how to add Gift Card as your custom product type
Author: Bhavik Kiri
Version: 1.0
*/
add_action( 'plugins_loaded', 'wcpt_register_gift_card_type' );
<?php
/**
*
* You can find the complete tutorial for this here:
* https://pluginrepublic.com/woocommerce-custom-fields
*
* Alternatively, check out the plugin
* https://pluginrepublic.com/wordpress-plugins/woocommerce-product-add-ons-ultimate/
*