Skip to content

Instantly share code, notes, and snippets.

<?php
/**
* A products field template
* Ensure that the 'Products Quantities' field is set to 'One Only'
* @since 2.2.0
* @package WooCommerce Product Add Ons Ultimate
*/
// Exit if accessed directly
if( ! defined( 'ABSPATH' ) ) {
.woocommerce div.product.elementor form.cart.variations_form .woocommerce-variation-add-to-cart,
.woocommerce div.product.elementor form.cart:not(.grouped_form):not(.variations_form) {
display: block;
}
.elementor-element ul.pewc-product-extra-groups {
padding: 0;
}
<?php
/**
* A checkbox field template
* @see https://pluginrepublic.com/documentation/overriding-templates/
* @since 2.0.0
* @package WooCommerce Product Add-Ons Ultimate
*/
// Exit if accessed directly
if( ! defined( 'ABSPATH' ) ) {
@plugin-republic
plugin-republic / pewc_attach_images_to_email.php
Created June 6, 2019 08:47
Example function getting field data from the order
<?php
/**
* Optionally attach uploaded images to the order email
*/
function pewc_attach_images_to_email( $attachments, $id, $order ) {
if( ( $id == 'new_order' || $id == 'customer_on_hold_order' ) && get_option( 'pewc_email_images', 'no' ) == 'yes' ) {
// Find any attachments
$order_items = $order->get_items( 'line_item' );
<?php
// Add this if you want to prevent non-required number fields from validating min or max values
add_filter( 'pewc_only_validate_number_field_value_if_field_required', '__return_true' );
?>
<?php
/**
* Display a custom text field
* @since 1.0.0
*/
function cfwc_create_custom_field() {
woocommerce_wp_text_input(
array(
'id' => 'custom_text_field_title',
'label' => __( 'Custom Text Field Title', 'cfwc' ),
<?php
/**
* Add a custom text input field to the product page
*/
function plugin_republic_add_text_field() { ?>
<div class="pr-field-wrap">
<label for="pr-field"><?php _e( 'Your name', 'plugin-republic' ); ?></label>
<input type="text" name='pr-field' id='pr-field' value=''>
</div>
<?php }
@plugin-republic
plugin-republic / simple.php
Created June 17, 2019 15:03
The WooCommerce simple product page
<?php
/**
* Simple product add to cart
*
* This template can be overridden by copying it to yourtheme/woocommerce/single-product/add-to-cart/simple.php.
*
* HOWEVER, on occasion WooCommerce will need to update template files and you
* (the theme developer) will need to copy the new files to your theme to
* maintain compatibility. We try to do this as little as possible, but it does
* happen. When this occurs the version of the template file will be bumped and
<?php
/**
* Validate our custom text input field value
*/
function plugin_republic_add_to_cart_validation( $passed, $product_id, $quantity, $variation_id=null ) {
if( empty( $_POST['pr-field'] ) ) {
$passed = false;
wc_add_notice( __( 'Your name is a required field.', 'plugin-republic' ), 'error' );
}
return $passed;
<?php
/**
* Add custom cart item data
*/
function plugin_republic_add_cart_item_data( $cart_item_data, $product_id, $variation_id ) {
if( isset( $_POST['pr-field'] ) ) {
$cart_item_data['pr_field'] = sanitize_text_field( $_POST['pr-field'] );
}
return $cart_item_data;
}