Product Category Dynamic Datapoint for Oxygen

This CodeBitt adds a new Dynamic Datapoint for Product Category/Archive templates in Oxygen.

snippet Code

<?php
add_filter( 'oxygen_custom_dynamic_data', 'oxys_dynamic_data_product_category', 10, 1 );


function oxys_dynamic_data_product_category( $dynamic_data ) {
	global $post;
	
	$properties = '';

	$field_data = array(
		'name' => __( 'Product Category Image', 'oxygen-woocommerce' ),
		// Name of the field as it displays in Oxygen
		'mode' => 'image',
		// Available modes: 'content', 'custom-field', 'link' and 'image'
		'position' => 'Archive',
		// Available positions: 'Post', 'Author', 'User', 'Featured Image', 'Current User', 'Archive' 'Blog Info'
		'data' => 'product_cat_img',
		// Slug of the field in Oxygen, will render as 'custom_field_name
		'handler' => 'oxys_product_thumbnail_callback',
		// Must be a function callback
		'properties' => $properties
	);
	$dynamic_data[] = $field_data;
	// Add the field to Dynamic Data

	return $dynamic_data;
}

function oxys_product_thumbnail_callback($atts) {
	global $wp_query; // get the query object
	
	if($wp_query) {
		$cat_obj = $wp_query->get_queried_object();
		$term_id = $cat_obj->term_id;
		$thumbnail_id = get_woocommerce_term_meta( $term_id, 'thumbnail_id', true );
		$image = wp_get_attachment_url( $thumbnail_id );
		return $image;
	}
}
?>
Leave a Reply

Your email address will not be published. Required fields are marked *

    Table Of Contents

    Related Content

    © 2020-2024 Luxibay
    Name(Required)
    Please let us know what's on your mind. Have a question for us? Ask away.
    This field is for validation purposes and should be left unchanged.