This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
add_filter( 'acf/load_field', 'my_plugin_get_proper_form_templates', 10, 1 ); | |
function my_plugin_get_proper_form_templates($field) { | |
if ( 'select_form_tmpl' === $field['name'] ) { | |
$forms_cfg = my_plugin_get_form_fields_cfg(); // external function, we get data from here | |
$choices = []; | |
if (array_keys($forms_cfg)) { | |
foreach (array_keys($forms_cfg) as $tmpl_name) { | |
$choices[$tmpl_name] = $forms_cfg[$tmpl_name]['label']; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
Working snippet of code we are using in Uni CPO 4 plugin (https://wordpress.org/plugins/uni-woo-custom-product-options/). | |
This code display prices like "From $20.00" on product archives. | |
*/ | |
add_filter('woocommerce_get_price_html', 'your_prefix_display_custom_price_on_archives', 10, 2); | |
function your_prefix_display_custom_price_on_archives($price, $product) | |
{ | |
if (is_admin()) { | |
// do not display in admin area | |
return $price; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
# taxonomy terms loop | |
taxonomy: terms ( | |
query: { | |
taxonomy: "product_cat" | |
hide_empty: true | |
} | |
) @private { | |
terms: nodes { | |
id: term_id |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(function(blocks, data, compose, element, blockEditor, components, serverSideRender) { | |
const el = element.createElement; | |
const registerBlockType = blocks.registerBlockType; | |
const { InspectorControls } = blockEditor; | |
const { Fragment } = element; | |
const { PanelBody, PanelRow, SelectControl } = components; | |
const useBlockProps = blockEditor.useBlockProps; | |
const { withSelect } = data; | |
registerBlockType('prefix/block_name', { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
add_filter( 'the_content', 'conditional_block_displaying', 1, 10 ); | |
function conditional_block_displaying($content) { | |
$blocks = parse_blocks( $content ); | |
$filtered_content = []; | |
foreach ( $blocks as $block ) { | |
if ( !wp_is_mobile() && 'core/paragraph' !== $block['blockName'] ) { // put your condition here | |
$filtered_content[] = $block; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function nav_sort_menu_items( $items ) { | |
return _nav_get_children( $items, 0, 0 ); | |
} | |
// This is the inner recursive function - do not use directly | |
function _nav_get_children( $items, $parentId, $depth ) { | |
$children = array(); | |
foreach ( $items as $id => $child ) { | |
if ( (int) $child->menu_item_parent === (int) $parentId ) { | |
$child->depth = $depth; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
add_action( 'woocommerce_product_options_pricing', 'uni_display_fields' ); | |
add_action( 'woocommerce_process_product_meta', 'uni_save_fields' ); | |
function uni_display_fields() { | |
woocommerce_wp_text_input( | |
array( | |
'id' => 'uni_paired_meta', | |
'label' => 'Meta field paired with NOV', | |
'description' => 'This value will be used instead of {uni_nov_cpo_paired_meta}', | |
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const flickty = jQuery('.woocommerce-product-gallery__wrapper').data('flickity'); | |
if (typeof flickty !== 'undefined' && flickty.slides.length > 1) { | |
flickty.destroy(); | |
jQuery('.woocommerce-product-gallery__wrapper').flickity({ | |
draggable: false | |
}); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
add_action( 'wp', 'uni_checkout_under_certain_circumstances' ); | |
function uni_checkout_under_certain_circumstances() { | |
if ( function_exists( 'is_checkout' ) && ( is_checkout() || is_ajax() ) ) { | |
remove_action( 'woocommerce_before_checkout_form', 'woocommerce_checkout_coupon_form', 10 ); | |
// the following line disables "notes" field | |
add_filter( 'woocommerce_enable_order_notes_field', '__return_false' ); | |
// an example of unsetting checkout fields | |
add_filter( 'woocommerce_checkout_fields', 'uni_unset_billing_checkout_fields', 10, 1 ); | |
// an example of modifying atributtes of checkout fields |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Reads attributes from the item | |
* | |
* @param $productData | |
* @param $product | |
* @return array | |
*/ | |
protected function populateAttributes($productData, $product) | |
{ | |
$attributes = []; |
NewerOlder