PMC Plugins
Pmc Buy Now

PMC Buy Now

Customize and Extend

A few filters exist to create a custom Buy Now button. By default, the PMC Buy Now plugin interface will only load on post edit pages: post.php and post-new.php. If you are using TinyMCE on another page and would like to load the interface, you should use the filter pmc_buy_now_pages.

Example

add_filter( 'pmc_buy_now_pages', 'pmc_add_buy_now_to_page` );

function pmc_add_buy_now_to_page( $pages ) {
	$pages[] = 'admin.php';

	return $pages;
}

You can adjust or add more options with the pmc_buy_now_options filter. By default this includes Text, Link, Current Price, Original Price, and Target. Below is an example of how you may extend this.

Example

add_filter( 'pmc_buy_now_options', 'pmc_buy_now_custom_option` );

function pmc_buy_now_custom_option( $options ) {
	$option[] = [
		'title'       => __( 'Title', 'domain' ),
		'name'        => 'text',
		'type'        => 'text',
		'default'     => __( 'BUY! BUY! BUY!', 'domain' ),
		'placeholder' => __( 'Add your title', 'domain' ),
	];

	return $options;
}

Another filter for extending is pmc_buy_now_data, which allows you to override a template. Some times you'll want to do this for the default template, other times you may just want to override a template for a particular button type (covered next). Here is an example for overriding a template.

Example

add_filter( 'pmc_buy_now_data', 'pmc_buy_now_data_override', 10, 2 );

function pmc_buy_now_data_override( $buy_now_data ) {
	$buy_now_data['template']      = __DIR__ . '/template/buy-now.php';
	$buy_now_data['amp_template']  = __DIR__ . '/template/buy-now-amp.php';
	$buy_now_data['data']['title'] = $buy_now_data['data']['text'] 
	return $buy_now_data;
}

To change the default amp buy now button color scheme, see PMC\Buy_Now\Config::action_amp_post_template_css

If you'd like to create a custom button type, you can use the pmc_buy_now_button_types filter to accomplish that. This allows you to add to the dropdown for a completely customized button with its own attributes. Below is an example for creating a custom button type.

Example

add_filter( 'pmc_buy_now_button_types', 'pmc_buy_now_custom_button_type' );

function pmc_buy_now_custom_button_type( $button_types ) {
	$button_types['amazon'] = [
		'label'  => __( 'Amazon', 'domain' ),
		'fields' => [
			'asin',
			'title',
			'url',
			'price',
			'rating',
			'summary',
			'award',
		],
	];

	return $button_types;
}

Important note: the fields array is all the options that a particular button type allows. These types need to be defined in the pmc_buy_now_options filter. Also, you can define a custom template for a button type with the pmc_buy_now_template filter by doing something like this.

Example

add_filter( 'pmc_buy_now_data', 'pmc_buy_now_data_amazon', 10, 2 );

function pmc_buy_now_data_amazon( $buy_now_data ) {
	$data        = $buy_now_data['data'] ?? [];
	$button_type = $data['button_type'] ?? 'default';
	if ( 'amazon' === $button_type ) {
		// Override the default template 
		$buy_now_data['template']     = __DIR__ . '/templates/buy-now-amazon.php';
		
		// Override the default AMP template as needed
		$buy_now_data['amp_template'] = __DIR__ . '/templates/buy-now-amazon-amp.php';
		
		$buy_now_data['data'] = array_merge(
			$data,
			[
				'additional-field' => 'some data',
				...
			]
		);
	}

	return $buy_now_data;
}

Apple News

For output related to Apple News, please see the pmc-apple-news plugin.